OLD | NEW |
| (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 | |
11 <script> | |
12 'use strict'; | |
13 | |
14 tr.exportTo('tr.v.d', function() { | |
15 class TelemetryInfo extends tr.v.d.Diagnostic { | |
16 constructor(opt_info) { | |
17 super(); | |
18 | |
19 this.benchmarkName_ = ''; | |
20 this.benchmarkStart_ = undefined; | |
21 this.label_ = ''; | |
22 this.legacyTIRLabel_ = ''; | |
23 this.storyDisplayName_ = ''; | |
24 this.storyGroupingKeys_ = new Map(); | |
25 this.storysetRepeatCounter_ = undefined; | |
26 this.canonicalUrl_ = ''; | |
27 | |
28 if (opt_info) { | |
29 this.addInfo(opt_info); | |
30 } | |
31 } | |
32 | |
33 clone() { | |
34 const clone = new tr.v.d.MergedTelemetryInfo(); | |
35 clone.addDiagnostic(this); | |
36 return clone; | |
37 } | |
38 | |
39 /** | |
40 * @param {!Object} info | |
41 * @param {string} info.benchmarkName | |
42 * @param {undefined|string} info.label | |
43 * @param {undefined|!Object} info.storyGroupingKeys | |
44 * @param {undefined|string} info.storyDisplayName | |
45 * @param {number} info.storysetRepeatCounter | |
46 * @param {number} info.benchmarkStartMs Milliseconds since Unix epoch. | |
47 */ | |
48 addInfo(info) { | |
49 if (info.benchmarkName) { | |
50 this.benchmarkName_ = info.benchmarkName; | |
51 } | |
52 if (info.benchmarkStartMs !== undefined) { | |
53 this.benchmarkStart_ = new Date(info.benchmarkStartMs); | |
54 } | |
55 if (info.label) { | |
56 this.label_ = info.label; | |
57 } | |
58 if (info.storyDisplayName) { | |
59 this.storyDisplayName_ = info.storyDisplayName; | |
60 } | |
61 for (const [name, value] of Object.entries( | |
62 info.storyGroupingKeys || {})) { | |
63 this.storyGroupingKeys_.set(name, value); | |
64 } | |
65 if (info.storysetRepeatCounter !== undefined) { | |
66 this.storysetRepeatCounter_ = info.storysetRepeatCounter; | |
67 } | |
68 if (info.legacyTIRLabel) { | |
69 this.legacyTIRLabel_ = info.legacyTIRLabel; | |
70 } | |
71 if (info.canonicalUrl) { | |
72 this.canonicalUrl_ = info.canonicalUrl; | |
73 } | |
74 } | |
75 | |
76 addToHistogram(hist) { | |
77 hist.diagnostics.set(tr.v.d.RESERVED_NAMES.TELEMETRY, this); | |
78 } | |
79 | |
80 /** | |
81 * @param {!tr.v.Histogram} hist | |
82 * @return {(undefined|!tr.v.d.TelemetryInfo)} | |
83 */ | |
84 static getFromHistogram(hist) { | |
85 return hist.diagnostics.get(tr.v.d.RESERVED_NAMES.TELEMETRY) || | |
86 hist.diagnostics.get(tr.v.d.RESERVED_NAMES.ITERATION); | |
87 } | |
88 | |
89 asDictInto_(d) { | |
90 d.benchmarkName = this.benchmarkName; | |
91 if (this.benchmarkStart) { | |
92 d.benchmarkStartMs = this.benchmarkStart.getTime(); | |
93 } | |
94 d.label = this.label; | |
95 d.storyDisplayName = this.storyDisplayName; | |
96 if (this.storyGroupingKeys.size > 0) { | |
97 d.storyGroupingKeys = {}; | |
98 for (const [name, value] of this.storyGroupingKeys) { | |
99 d.storyGroupingKeys[name] = value; | |
100 } | |
101 } | |
102 d.storysetRepeatCounter = this.storysetRepeatCounter; | |
103 d.legacyTIRLabel = this.legacyTIRLabel; | |
104 d.canonicalUrl = this.canonicalUrl; | |
105 } | |
106 | |
107 static fromDict(d) { | |
108 const info = new TelemetryInfo(); | |
109 info.addInfo(d); | |
110 return info; | |
111 } | |
112 | |
113 get displayLabel() { | |
114 if (this.label) return this.label; | |
115 return this.benchmarkName + '\n' + this.benchmarkStartString; | |
116 } | |
117 | |
118 get benchmarkName() { | |
119 return this.benchmarkName_; | |
120 } | |
121 | |
122 get label() { | |
123 return this.label_; | |
124 } | |
125 | |
126 get legacyTIRLabel() { | |
127 return this.legacyTIRLabel_; | |
128 } | |
129 | |
130 set legacyTIRLabel(tir) { | |
131 this.legacyTIRLabel_ = tir; | |
132 } | |
133 | |
134 get storyGroupingKeys() { | |
135 return this.storyGroupingKeys_; | |
136 } | |
137 | |
138 get storyDisplayName() { | |
139 return this.storyDisplayName_; | |
140 } | |
141 | |
142 get storysetRepeatCounter() { | |
143 return this.storysetRepeatCounter_; | |
144 } | |
145 | |
146 get storysetRepeatCounterLabel() { | |
147 return 'storyset repeat ' + this.storysetRepeatCounter; | |
148 } | |
149 | |
150 get canonicalUrl() { | |
151 return this.canonicalUrl_; | |
152 } | |
153 | |
154 get benchmarkStart() { | |
155 return this.benchmarkStart_; | |
156 } | |
157 | |
158 get benchmarkStartString() { | |
159 if (this.benchmarkStart_ === undefined) return ''; | |
160 return tr.b.formatDate(this.benchmarkStart); | |
161 } | |
162 | |
163 /** | |
164 * @param {!tr.v.Histogram} hist | |
165 * @param {string} fieldName | |
166 * @param {*} defaultValue | |
167 * @return {*} | |
168 */ | |
169 static getField(hist, fieldName, defaultValue) { | |
170 const telemetry = tr.v.d.TelemetryInfo.getFromHistogram(hist); | |
171 if (!(telemetry instanceof tr.v.d.TelemetryInfo) || | |
172 !telemetry[fieldName]) { | |
173 return defaultValue; | |
174 } | |
175 return telemetry[fieldName]; | |
176 } | |
177 | |
178 /** | |
179 * @param {!tr.v.Histogram} hist | |
180 * @param {string} storyGroupingKey | |
181 * @return {string} | |
182 */ | |
183 static getStoryGroupingKeyLabel(hist, storyGroupingKey) { | |
184 const telemetry = tr.v.d.TelemetryInfo.getFromHistogram(hist); | |
185 if (!(telemetry instanceof tr.v.d.TelemetryInfo)) { | |
186 return storyGroupingKey + ': undefined'; | |
187 } | |
188 return storyGroupingKey + ': ' + | |
189 telemetry.storyGroupingKeys.get(storyGroupingKey); | |
190 } | |
191 | |
192 /** | |
193 * Returns a closure that gets a story grouping key label from a Histogram. | |
194 * | |
195 * @param {string} storyGroupingKey | |
196 * @return {!function(tr.v.Histogram):string} | |
197 */ | |
198 static makeStoryGroupingKeyLabelGetter(storyGroupingKey) { | |
199 return v => TelemetryInfo.getStoryGroupingKeyLabel( | |
200 v, storyGroupingKey); | |
201 } | |
202 } | |
203 | |
204 tr.v.d.Diagnostic.register(TelemetryInfo, { | |
205 elementName: 'tr-v-ui-telemetry-info-span' | |
206 }); | |
207 | |
208 return { | |
209 TelemetryInfo, | |
210 }; | |
211 }); | |
212 </script> | |
OLD | NEW |