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

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

Issue 3009553002: Refactor Histogram relationship diagnostics. (Closed)
Patch Set: Created 3 years, 3 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
Index: tracing/tracing/value/diagnostics/related_name_map.html
diff --git a/tracing/tracing/value/diagnostics/related_name_map.html b/tracing/tracing/value/diagnostics/related_name_map.html
new file mode 100644
index 0000000000000000000000000000000000000000..3004d6bf3e56a0316331a10bca7275e63366c322
--- /dev/null
+++ b/tracing/tracing/value/diagnostics/related_name_map.html
@@ -0,0 +1,99 @@
+<!DOCTYPE html>
+<!--
+Copyright 2017 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/utils.html">
+<link rel="import" href="/tracing/value/diagnostics/diagnostic.html">
+
+<script>
+'use strict';
+
+tr.exportTo('tr.v.d', function() {
+ class RelatedNameMap extends tr.v.d.Diagnostic {
+ constructor(opt_info) {
+ super();
+ this.map_ = new Map();
+ }
+
+ clone() {
+ const clone = new RelatedNameMap();
+ clone.addDiagnostic(this);
+ return clone;
+ }
+
+ equals(other) {
+ if (!(other instanceof RelatedNameMap)) return false;
+
+ const keys1 = new Set(this.map_.keys());
+ const keys2 = new Set(other.map_.keys());
+ if (!tr.b.setsEqual(keys1, keys2)) return false;
+
+ for (const [key, name] of this) {
+ if (name !== other.get(key)) return false;
+ }
+
+ return true;
+ }
+
+ canAddDiagnostic(otherDiagnostic) {
+ return otherDiagnostic instanceof RelatedNameMap;
+ }
+
+ addDiagnostic(otherDiagnostic) {
+ for (const [key, name] of otherDiagnostic) {
+ const existing = this.get(key);
+ if (existing === undefined) {
+ this.set(key, name);
+ } else if (existing !== name) {
+ throw new Error('Histogram names differ: ' +
+ `"${existing}" != "${name}"`);
+ }
+ }
+ }
+
+ asDictInto_(d) {
+ d.names = {};
+ for (const [key, name] of this) d.names[key] = name;
+ }
+
+ set(key, name) {
+ this.map_.set(key, name);
+ }
+
+ get(key) {
+ return this.map_.get(key);
+ }
+
+ * [Symbol.iterator]() {
+ for (const pair of this.map_) yield pair;
+ }
+
+ * values() {
+ for (const value of this.map_.values()) yield value;
+ }
+
+ static fromEntries(entries) {
+ const names = new RelatedNameMap();
+ for (const [key, name] of entries) {
+ names.set(key, name);
+ }
+ return names;
+ }
+
+ static fromDict(d) {
+ return RelatedNameMap.fromEntries(Object.entries(d.names || {}));
+ }
+ }
+
+ tr.v.d.Diagnostic.register(RelatedNameMap, {
+ elementName: 'tr-v-ui-related-name-map-span',
+ });
+
+ return {
+ RelatedNameMap,
+ };
+});
+</script>
« no previous file with comments | « tracing/tracing/value/diagnostics/related_histogram_map.html ('k') | tracing/tracing/value/diagnostics/reserved_infos.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698