OLD | NEW |
| (Empty) |
1 <!DOCTYPE html> | |
2 <!-- | |
3 Copyright 2017 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 | |
11 <script> | |
12 'use strict'; | |
13 | |
14 tr.exportTo('tr.v.d', function() { | |
15 class MergedTelemetryInfo extends tr.v.d.Diagnostic { | |
16 constructor() { | |
17 super(); | |
18 this.benchmarkNames_ = new Set(); | |
19 this.benchmarkStartsMs_ = new Set(); | |
20 this.labels_ = new Set(); | |
21 this.legacyTIRLabels_ = new Set(); | |
22 this.storyDisplayNames_ = new Set(); | |
23 this.storyGroupingKeys_ = new Map(); | |
24 this.storysetRepeatCounters_ = new Set(); | |
25 } | |
26 | |
27 clone() { | |
28 const clone = new tr.v.d.MergedTelemetryInfo(); | |
29 clone.addDiagnostic(this); | |
30 return clone; | |
31 } | |
32 | |
33 addToHistogram(hist) { | |
34 hist.diagnostics.set(tr.v.d.RESERVED_NAMES.TELEMETRY, this); | |
35 } | |
36 | |
37 equals(other) { | |
38 if (!(other instanceof MergedTelemetryInfo)) return false; | |
39 if (!tr.b.setsEqual(this.benchmarkNames, other.benchmarkNames)) { | |
40 return false; | |
41 } | |
42 if (!tr.b.setsEqual(this.labels, other.labels)) return false; | |
43 if (!tr.b.setsEqual(this.storyDisplayNames, other.storyDisplayNames)) { | |
44 return false; | |
45 } | |
46 if (!tr.b.setsEqual(this.legacyTIRLabels, other.legacyTIRLabels)) { | |
47 return false; | |
48 } | |
49 if (!tr.b.setsEqual(this.storysetRepeatCounters, | |
50 other.storysetRepeatCounters)) { | |
51 return false; | |
52 } | |
53 if (!tr.b.setsEqual(this.benchmarkStartsMs, other.benchmarkStartsMs)) { | |
54 return false; | |
55 } | |
56 | |
57 if (!tr.b.setsEqual(new Set(this.storyGroupingKeys.keys()), | |
58 new Set(other.storyGroupingKeys.keys()))) { | |
59 return false; | |
60 } | |
61 for (const [k, vs] of this.storyGroupingKeys) { | |
62 if (!tr.b.setsEqual(vs, other.storyGroupingKeys.get(k))) { | |
63 return false; | |
64 } | |
65 } | |
66 | |
67 return true; | |
68 } | |
69 | |
70 canAddDiagnostic(otherDiagnostic) { | |
71 return otherDiagnostic instanceof MergedTelemetryInfo || | |
72 otherDiagnostic instanceof tr.v.d.TelemetryInfo; | |
73 } | |
74 | |
75 addDiagnostic(otherDiagnostic) { | |
76 if (otherDiagnostic instanceof MergedTelemetryInfo) { | |
77 for (const name of otherDiagnostic.benchmarkNames) { | |
78 this.benchmarkNames.add(name); | |
79 } | |
80 for (const t of otherDiagnostic.benchmarkStartsMs) { | |
81 this.benchmarkStartsMs.add(t); | |
82 } | |
83 for (const name of otherDiagnostic.labels) { | |
84 this.labels.add(name); | |
85 } | |
86 for (const name of otherDiagnostic.legacyTIRLabels) { | |
87 this.legacyTIRLabels.add(name); | |
88 } | |
89 for (const name of otherDiagnostic.storyDisplayNames) { | |
90 this.storyDisplayNames.add(name); | |
91 } | |
92 for (const name of otherDiagnostic.storysetRepeatCounters) { | |
93 this.storysetRepeatCounters.add(name); | |
94 } | |
95 for (const [name, value] of otherDiagnostic.storyGroupingKeys) { | |
96 if (this.storyGroupingKeys.has(name)) { | |
97 for (const subValue of value) { | |
98 this.storyGroupingKeys.get(name).add(subValue); | |
99 } | |
100 } else { | |
101 this.storyGroupingKeys.set(name, new Set(value)); | |
102 } | |
103 } | |
104 return; | |
105 } | |
106 | |
107 if (otherDiagnostic.benchmarkName) { | |
108 this.benchmarkNames.add(otherDiagnostic.benchmarkName); | |
109 } | |
110 if (otherDiagnostic.benchmarkStart !== undefined) { | |
111 // Store the number timestamps in the Set, not the Date objects. | |
112 // Sets uniquify based on object identity, not equivalency. | |
113 // Multiple different Date objects can have the same value, and we don't | |
114 // want to store multiple Dates with the same value. | |
115 // Dates are not interned like strings are. | |
116 // The |benchmarkStarts| getter converts the timestamps to Date objects. | |
117 this.benchmarkStartsMs.add(otherDiagnostic.benchmarkStart.getTime()); | |
118 } | |
119 if (otherDiagnostic.label) { | |
120 this.labels.add(otherDiagnostic.label); | |
121 } | |
122 if (otherDiagnostic.legacyTIRLabel) { | |
123 this.legacyTIRLabels.add(otherDiagnostic.legacyTIRLabel); | |
124 } | |
125 if (otherDiagnostic.storyDisplayName) { | |
126 this.storyDisplayNames.add(otherDiagnostic.storyDisplayName); | |
127 } | |
128 for (const [name, value] of otherDiagnostic.storyGroupingKeys) { | |
129 if (this.storyGroupingKeys.has(name)) { | |
130 this.storyGroupingKeys.get(name).add(value); | |
131 } else { | |
132 this.storyGroupingKeys.set(name, new Set([value])); | |
133 } | |
134 } | |
135 if (otherDiagnostic.storysetRepeatCounter !== undefined) { | |
136 this.storysetRepeatCounters.add(otherDiagnostic.storysetRepeatCounter); | |
137 } | |
138 } | |
139 | |
140 asDictInto_(d) { | |
141 if (this.benchmarkNames.size) { | |
142 d.benchmarkNames = Array.from(this.benchmarkNames); | |
143 } | |
144 if (this.benchmarkStartsMs.size) { | |
145 d.benchmarkStartsMs = Array.from(this.benchmarkStartsMs); | |
146 } | |
147 if (this.labels.size) { | |
148 d.labels = Array.from(this.labels); | |
149 } | |
150 if (this.legacyTIRLabels.size) { | |
151 d.legacyTIRLabels = this.legacyTIRLabels; | |
152 } | |
153 if (this.storyDisplayNames.size) { | |
154 d.storyDisplayNames = Array.from(this.storyDisplayNames); | |
155 } | |
156 if (this.storyGroupingKeys.size) { | |
157 d.storyGroupingKeys = {}; | |
158 for (const [name, values] of this.storyGroupingKeys) { | |
159 d.storyGroupingKeys[name] = Array.from(values); | |
160 } | |
161 } | |
162 if (this.storysetRepeatCounters.size) { | |
163 d.storysetRepeatCounters = Array.from(this.storysetRepeatCounters); | |
164 } | |
165 } | |
166 | |
167 static fromDict(d) { | |
168 const info = new MergedTelemetryInfo(); | |
169 for (const n of d.benchmarkNames || []) { | |
170 info.benchmarkNames_.add(n); | |
171 } | |
172 for (const n of d.benchmarkStartsMs || []) { | |
173 info.benchmarkStartsMs_.add(n); | |
174 } | |
175 for (const n of d.labels || []) { | |
176 info.labels_.add(n); | |
177 } | |
178 for (const n of d.legacyTIRLabels || []) { | |
179 info.legacyTIRLabels_.add(n); | |
180 } | |
181 for (const n of d.storyDisplayNames || []) { | |
182 info.storyDisplayNames_.add(n); | |
183 } | |
184 for (const [name, values] of Object.entries(d.storyGroupingKeys || {})) { | |
185 info.storyGroupingKeys_.set(name, new Set(values)); | |
186 } | |
187 for (const n of d.storysetRepeatCounters || []) { | |
188 info.storysetRepeatCounters_.add(n); | |
189 } | |
190 return info; | |
191 } | |
192 | |
193 get displayLabel() { | |
194 if (this.labels.size) { | |
195 return Array.from(this.labels).join('\n'); | |
196 } | |
197 return Array.from(this.benchmarkNames).concat( | |
198 this.benchmarkStartStrings).join('\n'); | |
199 } | |
200 | |
201 get benchmarkNames() { | |
202 return this.benchmarkNames_; | |
203 } | |
204 | |
205 get labels() { | |
206 return this.labels_; | |
207 } | |
208 | |
209 get legacyTIRLabels() { | |
210 return this.legacyTIRLabels_; | |
211 } | |
212 | |
213 get storyGroupingKeys() { | |
214 return this.storyGroupingKeys_; | |
215 } | |
216 | |
217 get storyDisplayNames() { | |
218 return this.storyDisplayNames_; | |
219 } | |
220 | |
221 get storysetRepeatCounters() { | |
222 return this.storysetRepeatCounters_; | |
223 } | |
224 | |
225 get storysetRepeatCounterLabel() { | |
226 return 'storyset repeat ' + Array.from( | |
227 this.storysetRepeatCounters).join(','); | |
228 } | |
229 | |
230 /** | |
231 * @return {!Set.<number>} | |
232 */ | |
233 get benchmarkStartsMs() { | |
234 return this.benchmarkStartsMs_; | |
235 } | |
236 | |
237 /** | |
238 * @return {!Array.<!Date>} | |
239 */ | |
240 get benchmarkStarts() { | |
241 const startsMs = Array.from(this.benchmarkStartsMs); | |
242 startsMs.sort((x, y) => x - y); | |
243 return startsMs.map(t => new Date(t)); | |
244 } | |
245 | |
246 /** | |
247 * @return {!Array.<string>} | |
248 */ | |
249 get benchmarkStartStrings() { | |
250 return this.benchmarkStarts.map(tr.b.formatDate); | |
251 } | |
252 | |
253 /** | |
254 * @param {!tr.v.Histogram} hist | |
255 * @param {string} fieldName | |
256 * @param {*} defaultValue | |
257 * @return {*} | |
258 */ | |
259 static getField(hist, fieldName, defaultValue) { | |
260 const telemetry = tr.v.d.TelemetryInfo.getFromHistogram(hist); | |
261 if (!(telemetry instanceof tr.v.d.MergedTelemetryInfo) || | |
262 !telemetry[fieldName]) { | |
263 return defaultValue; | |
264 } | |
265 return telemetry[fieldName]; | |
266 } | |
267 | |
268 /** | |
269 * @param {!tr.v.Histogram} hist | |
270 * @param {string} storyGroupingKey | |
271 * @return {string} | |
272 */ | |
273 static getStoryGroupingKeyLabel(hist, storyGroupingKey) { | |
274 const telemetry = tr.v.d.TelemetryInfo.getFromHistogram(hist); | |
275 if (!(telemetry instanceof tr.v.d.MergedTelemetryInfo)) { | |
276 return storyGroupingKey + ': undefined'; | |
277 } | |
278 return storyGroupingKey + ': ' + | |
279 telemetry.storyGroupingKeys[storyGroupingKey]; | |
280 } | |
281 | |
282 /** | |
283 * Returns a closure that gets a story grouping key label from a Histogram. | |
284 * | |
285 * @param {string} storyGroupingKey | |
286 * @return {!function(tr.v.Histogram):string} | |
287 */ | |
288 static makeStoryGroupingKeyLabelGetter(storyGroupingKey) { | |
289 return v => MergedTelemetryInfo.getStoryGroupingKeyLabel( | |
290 v, storyGroupingKey); | |
291 } | |
292 } | |
293 | |
294 tr.v.d.Diagnostic.register(MergedTelemetryInfo, { | |
295 elementName: 'tr-v-ui-merged-telemetry-info-span' | |
296 }); | |
297 | |
298 return { | |
299 MergedTelemetryInfo, | |
300 }; | |
301 }); | |
302 </script> | |
OLD | NEW |