Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(296)

Unified Diff: tracing/tracing/value/diagnostics/diagnostic_map.html

Issue 2000063006: Define DiagnosticMap and a basic Diagnostic hierarchy (Closed) Base URL: https://github.com/catapult-project/catapult.git@master
Patch Set: rebase Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « tracing/tracing/value/diagnostics/diagnostic.html ('k') | tracing/tracing/value/diagnostics/generic.html » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tracing/tracing/value/diagnostics/diagnostic_map.html
diff --git a/tracing/tracing/value/diagnostics/diagnostic_map.html b/tracing/tracing/value/diagnostics/diagnostic_map.html
new file mode 100644
index 0000000000000000000000000000000000000000..df0c2ab2a207d4b2cdc6c4d02baa3c87954d2233
--- /dev/null
+++ b/tracing/tracing/value/diagnostics/diagnostic_map.html
@@ -0,0 +1,88 @@
+<!DOCTYPE html>
+<!--
+Copyright 2016 The Chromium Authors. All rights reserved.
+Use of this source code is governed by a BSD-style license that can be
+found in the LICENSE file.
+-->
+
+<link rel="import" href="/tracing/value/diagnostics/composition.html">
+<link rel="import" href="/tracing/value/diagnostics/generic.html">
+
+<script>
+'use strict';
+
+tr.exportTo('tr.v.d', function() {
+ /** @constructor */
+ function DiagnosticMap() {
+ this.diagnosticsByName_ = {};
+ }
+
+ DiagnosticMap.prototype = {
+ /**
+ * Add a new Diagnostic to this map.
+ *
+ * @param {string} name
+ * @param {!tr.v.d.Diagnostic} diagnostic
+ */
+ add: function(name, diagnostic) {
+ if (!(diagnostic instanceof tr.v.d.Diagnostic))
+ throw new Error('Must be instanceof Diagnostic: ' + diagnostic);
+
+ if (typeof(name) !== 'string')
+ throw new Error('name must be string, not ' + name);
+
+ if (this.diagnosticsByName_[name])
+ throw new Error('Attempt to add duplicate diagnostic ' + name);
+
+ this.diagnosticsByName_[name] = diagnostic;
+ },
+
+ /**
+ * Add Diagnostics from a dictionary of dictionaries.
+ *
+ * @param {Object} dict
+ */
+ addDicts: function(dict) {
+ tr.b.iterItems(dict, function(name, diagnosticDict) {
+ this.add(name, tr.v.d.Diagnostic.fromDict(diagnosticDict));
+ }, this);
+ },
+
+ /**
+ * @param {string} name
+ * @return {tr.v.d.Diagnostic}
+ */
+ get: function(name) {
+ return this.diagnosticsByName_[name];
+ },
+
+ /**
+ * Iterate over this map's key-value-pairs.
+ *
+ * @param {function(string, tr.v.d.Diagnostic)} cb
+ * @param {Object=} opt_this
+ */
+ forEach: function(cb, opt_this) {
+ tr.b.iterItems(this.diagnosticsByName_, cb, opt_this || this);
+ },
+
+ asDict: function() {
+ var dict = {};
+ this.forEach(function(name, diagnostic) {
+ dict[name] = diagnostic.asDict();
+ });
+ return dict;
+ }
+ };
+
+ DiagnosticMap.fromDict = function(d) {
+ var diagnostics = new DiagnosticMap();
+ diagnostics.addDicts(d);
+ return diagnostics;
+ };
+
+ return {
+ DiagnosticMap: DiagnosticMap
+ };
+});
+</script>
« no previous file with comments | « tracing/tracing/value/diagnostics/diagnostic.html ('k') | tracing/tracing/value/diagnostics/generic.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698