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

Side by Side Diff: tracing/tracing/value/diagnostics/related_histogram_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 unified diff | Download patch
OLDNEW
(Empty)
1 <!DOCTYPE html>
2 <!--
3 Copyright 2016 The Chromium Authors. All rights reserved.
4 Use of this source code is governed by a BSD-style license that can be
5 found in the LICENSE file.
6 -->
7
8 <link rel="import" href="/tracing/base/utils.html">
9 <link rel="import" href="/tracing/value/diagnostics/diagnostic.html">
10 <link rel="import" href="/tracing/value/diagnostics/histogram_ref.html">
11
12 <script>
13 'use strict';
14
15 tr.exportTo('tr.v.d', function() {
16 class RelatedHistogramMap extends tr.v.d.Diagnostic {
17 constructor() {
18 super();
19 this.histogramsByName_ = new Map();
20 }
21
22 canAddDiagnostic(otherDiagnostic) {
23 return otherDiagnostic instanceof RelatedHistogramMap;
24 }
25
26 addDiagnostic(otherDiagnostic) {
27 // Related Histograms might not exist yet.
28 }
29
30 mergeRelationships(otherDiagnostic, parentHist, otherParentHist) {
31 /*
32 Modify |this| to contain Histograms that should be related to
33 |parentHist|.
34
35 |otherParentHist| was merged to |parentHist|.
36 |otherDiagnostic| contains Histograms that are related to
37 |otherParentHist|.
38
39 Since mergeRelationships() is called after all Histograms are merged,
40 then the MERGED_TO diagnostics of the Histograms in |otherDiagnostic|
41 contain Histograms that should be related to |parentHist| via |this|
42 RelatedHistogramMap.
43
44 otherParentHist -----------------------------> parentHist
45 | merged to RelatedHistogramMap |
46 | |
47 | otherDiagnostic | this
48 | RelatedHistogramMap | RelatedHistogramMap
49 v v
50 otherRelatedHist -----------------------------> relatedHist
51 merged to RelatedHistogramMap
52
53 However, |otherRelatedHist| may have been merged to Histograms using
54 different grouping keys, so if |relatedHist|'s merge path is different
55 from |parentHist|'s merge path, then |relatedHist| should not be related
56 to |parentHist|.
57 */
58
59 const parentGroupingPath = tr.v.d.GroupingPath.getFromHistogram(
60 parentHist);
61
62 for (const [name, otherRelatedHist] of otherDiagnostic) {
63 const mergedTo = otherRelatedHist.diagnostics.get(
64 tr.v.d.RESERVED_NAMES.MERGED_TO);
65 if (mergedTo === undefined) continue;
66
67 for (const relatedHist of mergedTo.histogramsByName_.values()) {
68 const relatedGroupingPath = tr.v.d.GroupingPath.getFromHistogram(
69 relatedHist);
70 if (relatedGroupingPath === undefined) continue;
71 if (!parentGroupingPath.equals(relatedGroupingPath)) continue;
72
73 this.set(name, relatedHist);
74 }
75 }
76 }
77
78 /**
79 * Lookup a Histogram by name. Returns undefined if |name| is not found.
80 *
81 * @param {string} name
82 * @return {!tr.v.d.HistogramRef|!tr.v.Histogram|undefined}
83 */
84 get(name) {
85 return this.histogramsByName_.get(name);
86 }
87
88 /**
89 * Add a Histogram by an explicit name to this map.
90 *
91 * @param {string} name
92 * @param {!(tr.v.d.HistogramRef|tr.v.Histogram)} hist
93 */
94 set(name, hist) {
95 if (!(hist instanceof tr.v.Histogram) &&
96 !(hist instanceof tr.v.d.HistogramRef)) {
97 throw new Error('Must be instanceof Histogram or HistogramRef: ' +
98 hist);
99 }
100
101 this.histogramsByName_.set(name, hist);
102 }
103
104 /**
105 * Add a Histogram implicitly by its own name to this map.
106 *
107 * @param {!(tr.v.d.HistogramRef|tr.v.Histogram)} hist
108 */
109 add(hist) {
110 this.set(hist.name, hist);
111 }
112
113 get length() {
114 return this.histogramsByName_.size;
115 }
116
117 * [Symbol.iterator]() {
118 for (const pair of this.histogramsByName_) {
119 yield pair;
120 }
121 }
122
123 /**
124 * Resolve all HistogramRefs into Histograms by looking up their guids in
125 * |histograms|.
126 * If a Histogram cannot be found and |opt_required| is true, then throw an
127 * Error.
128 * If a Histogram cannot be found and |opt_required| is false, then the
129 * HistogramRef will remain a HistogramRef.
130 *
131 * @param {!tr.v.HistogramSet} histograms
132 * @param {boolean=} opt_required
133 */
134 resolve(histograms, opt_required) {
135 for (const [name, value] of this) {
136 if (!(value instanceof tr.v.d.HistogramRef)) continue;
137
138 const guid = value.guid;
139 const hist = histograms.lookupHistogram(guid);
140 if (hist instanceof tr.v.Histogram) {
141 this.histogramsByName_.set(name, hist);
142 } else if (opt_required) {
143 throw new Error('Unable to find Histogram ' + guid);
144 }
145 }
146 }
147
148 asDictInto_(d) {
149 d.values = {};
150 for (const [name, hist] of this) {
151 d.values[name] = hist.guid;
152 }
153 }
154
155 static fromDict(d) {
156 const map = new RelatedHistogramMap();
157 for (const [name, guid] of Object.entries(d.values)) {
158 map.set(name, new tr.v.d.HistogramRef(guid));
159 }
160 return map;
161 }
162 }
163
164 tr.v.d.Diagnostic.register(RelatedHistogramMap, {
165 elementName: 'tr-v-ui-related-histogram-map-span'
166 });
167
168 return {
169 RelatedHistogramMap,
170 };
171 });
172 </script>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698