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

Unified Diff: tracing/tracing/value/diagnostics/related_value_set.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/generic.html ('k') | tracing/tracing/value/value.html » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tracing/tracing/value/diagnostics/related_value_set.html
diff --git a/tracing/tracing/value/diagnostics/related_value_set.html b/tracing/tracing/value/diagnostics/related_value_set.html
new file mode 100644
index 0000000000000000000000000000000000000000..d9ea56f2120adbb1964748efbcf3ccc76f9ca03d
--- /dev/null
+++ b/tracing/tracing/value/diagnostics/related_value_set.html
@@ -0,0 +1,92 @@
+<!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/base/iteration_helpers.html">
+<link rel="import" href="/tracing/value/diagnostics/diagnostic.html">
+
+<script>
+'use strict';
+
+tr.exportTo('tr.v.d', function() {
+ /** @constructor */
+ function ValueRef(guid) {
+ this.guid = guid;
+ }
+
+ /** @constructor */
+ function RelatedValueSet(opt_values) {
+ this.values_ = {};
+
+ if (opt_values)
+ opt_values.forEach(this.add, this);
+ }
+
+ RelatedValueSet.prototype = {
+ __proto__: tr.v.d.Diagnostic.prototype,
+
+ /**
+ * Add a Value to this set.
+ *
+ * @param {!ValueRef|tr.v.Value} v
+ */
+ add: function(v) {
+ if (!(v instanceof tr.v.Value) &&
+ !(v instanceof ValueRef))
+ throw new Error('Must be instanceof Value or ValueRef: ' + v);
+
+ if (this.values_[v.guid])
+ throw new Error('Tried to add same value twice');
+
+ this.values_[v.guid] = v;
+ },
+
+ /**
+ * @return {Array.<ValueRef|tr.v.Value>}
+ */
+ get values() {
+ return tr.b.dictionaryValues(this.values_);
+ },
+
+ /**
+ * Resolve all ValueRefs into Values by looking up their guids in valueSet.
+ * If a value cannot be found and opt_required is true, then throw an Error.
+ * If a value cannot be found and opt_required is false, then the ValueRef
+ * will remain a ValueRef.
+ *
+ * @param {!tr.metrics.ValueSet} valueSet
+ * @param {boolean=} opt_required
+ */
+ resolve: function(valueSet, opt_required) {
+ tr.b.iterItems(this.values_, function(guid, value) {
+ if (!(value instanceof ValueRef))
+ return;
+
+ value = valueSet.lookup(guid);
+ if (value instanceof tr.v.Value)
+ this.values_[guid] = value;
+ else if (opt_required)
+ throw new Error('Unable to find Value ' + guid);
+ }, this);
+ },
+
+ _asDictInto: function(d) {
+ d.guids = tr.b.dictionaryKeys(this.values_);
+ }
+ };
+
+ RelatedValueSet.fromDict = function(d) {
+ return new RelatedValueSet(d.guids.map(guid => new ValueRef(guid)));
+ };
+
+ tr.v.d.Diagnostic.register(RelatedValueSet);
+
+ return {
+ RelatedValueSet: RelatedValueSet,
+ ValueRef: ValueRef
+ };
+});
+</script>
« no previous file with comments | « tracing/tracing/value/diagnostics/generic.html ('k') | tracing/tracing/value/value.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698