OLD | NEW |
1 /** | 1 /** |
2 * Copyright (C) 2014 Google Inc. All rights reserved. | 2 * Copyright (C) 2014 Google Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
6 * met: | 6 * met: |
7 * | 7 * |
8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
(...skipping 10 matching lines...) Expand all Loading... |
21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | 21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | 22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | 23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
29 */ | 29 */ |
30 | 30 |
31 | |
32 /** | 31 /** |
33 * @constructor | |
34 * @implements {WebInspector.FlameChartDataProvider} | 32 * @implements {WebInspector.FlameChartDataProvider} |
35 * @param {?WebInspector.Target} target | 33 * @unrestricted |
36 */ | 34 */ |
37 WebInspector.ProfileFlameChartDataProvider = function(target) | 35 WebInspector.ProfileFlameChartDataProvider = class { |
38 { | 36 /** |
| 37 * @param {?WebInspector.Target} target |
| 38 */ |
| 39 constructor(target) { |
39 WebInspector.FlameChartDataProvider.call(this); | 40 WebInspector.FlameChartDataProvider.call(this); |
40 this._target = target; | 41 this._target = target; |
41 this._colorGenerator = WebInspector.ProfileFlameChartDataProvider.colorGener
ator(); | 42 this._colorGenerator = WebInspector.ProfileFlameChartDataProvider.colorGener
ator(); |
42 }; | 43 } |
43 | 44 |
44 WebInspector.ProfileFlameChartDataProvider.prototype = { | 45 /** |
45 /** | 46 * @return {!WebInspector.FlameChart.ColorGenerator} |
46 * @override | 47 */ |
47 * @return {number} | 48 static colorGenerator() { |
48 */ | |
49 barHeight: function() | |
50 { | |
51 return 15; | |
52 }, | |
53 | |
54 /** | |
55 * @override | |
56 * @return {number} | |
57 */ | |
58 textBaseline: function() | |
59 { | |
60 return 4; | |
61 }, | |
62 | |
63 /** | |
64 * @override | |
65 * @return {number} | |
66 */ | |
67 textPadding: function() | |
68 { | |
69 return 2; | |
70 }, | |
71 | |
72 /** | |
73 * @override | |
74 * @return {number} | |
75 */ | |
76 minimumBoundary: function() | |
77 { | |
78 return this._cpuProfile.profileStartTime; | |
79 }, | |
80 | |
81 /** | |
82 * @override | |
83 * @return {number} | |
84 */ | |
85 totalTime: function() | |
86 { | |
87 return this._cpuProfile.profileHead.total; | |
88 }, | |
89 | |
90 /** | |
91 * @override | |
92 * @param {number} value | |
93 * @param {number=} precision | |
94 * @return {string} | |
95 */ | |
96 formatValue: function(value, precision) | |
97 { | |
98 return Number.preciseMillisToString(value, precision); | |
99 }, | |
100 | |
101 /** | |
102 * @override | |
103 * @return {number} | |
104 */ | |
105 maxStackDepth: function() | |
106 { | |
107 return this._maxStackDepth; | |
108 }, | |
109 | |
110 /** | |
111 * @override | |
112 * @return {?WebInspector.FlameChart.TimelineData} | |
113 */ | |
114 timelineData: function() | |
115 { | |
116 return this._timelineData || this._calculateTimelineData(); | |
117 }, | |
118 | |
119 /** | |
120 * @return {!WebInspector.FlameChart.TimelineData} | |
121 */ | |
122 _calculateTimelineData: function() | |
123 { | |
124 throw "Not implemented."; | |
125 }, | |
126 | |
127 /** | |
128 * @override | |
129 * @param {number} entryIndex | |
130 * @return {?Element} | |
131 */ | |
132 prepareHighlightedEntryInfo: function(entryIndex) | |
133 { | |
134 throw "Not implemented."; | |
135 }, | |
136 | |
137 /** | |
138 * @override | |
139 * @param {number} entryIndex | |
140 * @return {boolean} | |
141 */ | |
142 canJumpToEntry: function(entryIndex) | |
143 { | |
144 return this._entryNodes[entryIndex].scriptId !== "0"; | |
145 }, | |
146 | |
147 /** | |
148 * @override | |
149 * @param {number} entryIndex | |
150 * @return {string} | |
151 */ | |
152 entryTitle: function(entryIndex) | |
153 { | |
154 var node = this._entryNodes[entryIndex]; | |
155 return WebInspector.beautifyFunctionName(node.functionName); | |
156 }, | |
157 | |
158 /** | |
159 * @override | |
160 * @param {number} entryIndex | |
161 * @return {?string} | |
162 */ | |
163 entryFont: function(entryIndex) | |
164 { | |
165 if (!this._font) { | |
166 this._font = (this.barHeight() - 4) + "px " + WebInspector.fontFamil
y(); | |
167 this._boldFont = "bold " + this._font; | |
168 } | |
169 var node = this._entryNodes[entryIndex]; | |
170 return node.deoptReason ? this._boldFont : this._font; | |
171 }, | |
172 | |
173 /** | |
174 * @override | |
175 * @param {number} entryIndex | |
176 * @return {string} | |
177 */ | |
178 entryColor: function(entryIndex) | |
179 { | |
180 var node = this._entryNodes[entryIndex]; | |
181 // For idle and program, we want different 'shades of gray', so we fallb
ack to functionName as scriptId = 0 | |
182 // For rest of nodes e.g eval scripts, if url is empty then scriptId wil
l be guaranteed to be non-zero | |
183 return this._colorGenerator.colorForID(node.url || (node.scriptId !== "0
" ? node.scriptId : node.functionName)); | |
184 }, | |
185 | |
186 /** | |
187 * @override | |
188 * @param {number} entryIndex | |
189 * @param {!CanvasRenderingContext2D} context | |
190 * @param {?string} text | |
191 * @param {number} barX | |
192 * @param {number} barY | |
193 * @param {number} barWidth | |
194 * @param {number} barHeight | |
195 * @return {boolean} | |
196 */ | |
197 decorateEntry: function(entryIndex, context, text, barX, barY, barWidth, bar
Height) | |
198 { | |
199 return false; | |
200 }, | |
201 | |
202 /** | |
203 * @override | |
204 * @param {number} entryIndex | |
205 * @return {boolean} | |
206 */ | |
207 forceDecoration: function(entryIndex) | |
208 { | |
209 return false; | |
210 }, | |
211 | |
212 /** | |
213 * @override | |
214 * @return {number} | |
215 */ | |
216 paddingLeft: function() | |
217 { | |
218 return 0; | |
219 }, | |
220 | |
221 /** | |
222 * @override | |
223 * @param {number} entryIndex | |
224 * @return {string} | |
225 */ | |
226 textColor: function(entryIndex) | |
227 { | |
228 return "#333"; | |
229 } | |
230 }; | |
231 | |
232 | |
233 /** | |
234 * @return {!WebInspector.FlameChart.ColorGenerator} | |
235 */ | |
236 WebInspector.ProfileFlameChartDataProvider.colorGenerator = function() | |
237 { | |
238 if (!WebInspector.ProfileFlameChartDataProvider._colorGenerator) { | 49 if (!WebInspector.ProfileFlameChartDataProvider._colorGenerator) { |
239 var colorGenerator = new WebInspector.FlameChart.ColorGenerator( | 50 var colorGenerator = new WebInspector.FlameChart.ColorGenerator( |
240 { min: 30, max: 330 }, | 51 {min: 30, max: 330}, {min: 50, max: 80, count: 5}, {min: 80, max: 90,
count: 3}); |
241 { min: 50, max: 80, count: 5 }, | 52 |
242 { min: 80, max: 90, count: 3 }); | 53 colorGenerator.setColorForID('(idle)', 'hsl(0, 0%, 94%)'); |
243 | 54 colorGenerator.setColorForID('(program)', 'hsl(0, 0%, 80%)'); |
244 colorGenerator.setColorForID("(idle)", "hsl(0, 0%, 94%)"); | 55 colorGenerator.setColorForID('(garbage collector)', 'hsl(0, 0%, 80%)'); |
245 colorGenerator.setColorForID("(program)", "hsl(0, 0%, 80%)"); | 56 WebInspector.ProfileFlameChartDataProvider._colorGenerator = colorGenerato
r; |
246 colorGenerator.setColorForID("(garbage collector)", "hsl(0, 0%, 80%)"); | |
247 WebInspector.ProfileFlameChartDataProvider._colorGenerator = colorGenera
tor; | |
248 } | 57 } |
249 return WebInspector.ProfileFlameChartDataProvider._colorGenerator; | 58 return WebInspector.ProfileFlameChartDataProvider._colorGenerator; |
| 59 } |
| 60 |
| 61 /** |
| 62 * @override |
| 63 * @return {number} |
| 64 */ |
| 65 barHeight() { |
| 66 return 15; |
| 67 } |
| 68 |
| 69 /** |
| 70 * @override |
| 71 * @return {number} |
| 72 */ |
| 73 textBaseline() { |
| 74 return 4; |
| 75 } |
| 76 |
| 77 /** |
| 78 * @override |
| 79 * @return {number} |
| 80 */ |
| 81 textPadding() { |
| 82 return 2; |
| 83 } |
| 84 |
| 85 /** |
| 86 * @override |
| 87 * @return {number} |
| 88 */ |
| 89 minimumBoundary() { |
| 90 return this._cpuProfile.profileStartTime; |
| 91 } |
| 92 |
| 93 /** |
| 94 * @override |
| 95 * @return {number} |
| 96 */ |
| 97 totalTime() { |
| 98 return this._cpuProfile.profileHead.total; |
| 99 } |
| 100 |
| 101 /** |
| 102 * @override |
| 103 * @param {number} value |
| 104 * @param {number=} precision |
| 105 * @return {string} |
| 106 */ |
| 107 formatValue(value, precision) { |
| 108 return Number.preciseMillisToString(value, precision); |
| 109 } |
| 110 |
| 111 /** |
| 112 * @override |
| 113 * @return {number} |
| 114 */ |
| 115 maxStackDepth() { |
| 116 return this._maxStackDepth; |
| 117 } |
| 118 |
| 119 /** |
| 120 * @override |
| 121 * @return {?WebInspector.FlameChart.TimelineData} |
| 122 */ |
| 123 timelineData() { |
| 124 return this._timelineData || this._calculateTimelineData(); |
| 125 } |
| 126 |
| 127 /** |
| 128 * @return {!WebInspector.FlameChart.TimelineData} |
| 129 */ |
| 130 _calculateTimelineData() { |
| 131 throw 'Not implemented.'; |
| 132 } |
| 133 |
| 134 /** |
| 135 * @override |
| 136 * @param {number} entryIndex |
| 137 * @return {?Element} |
| 138 */ |
| 139 prepareHighlightedEntryInfo(entryIndex) { |
| 140 throw 'Not implemented.'; |
| 141 } |
| 142 |
| 143 /** |
| 144 * @override |
| 145 * @param {number} entryIndex |
| 146 * @return {boolean} |
| 147 */ |
| 148 canJumpToEntry(entryIndex) { |
| 149 return this._entryNodes[entryIndex].scriptId !== '0'; |
| 150 } |
| 151 |
| 152 /** |
| 153 * @override |
| 154 * @param {number} entryIndex |
| 155 * @return {string} |
| 156 */ |
| 157 entryTitle(entryIndex) { |
| 158 var node = this._entryNodes[entryIndex]; |
| 159 return WebInspector.beautifyFunctionName(node.functionName); |
| 160 } |
| 161 |
| 162 /** |
| 163 * @override |
| 164 * @param {number} entryIndex |
| 165 * @return {?string} |
| 166 */ |
| 167 entryFont(entryIndex) { |
| 168 if (!this._font) { |
| 169 this._font = (this.barHeight() - 4) + 'px ' + WebInspector.fontFamily(); |
| 170 this._boldFont = 'bold ' + this._font; |
| 171 } |
| 172 var node = this._entryNodes[entryIndex]; |
| 173 return node.deoptReason ? this._boldFont : this._font; |
| 174 } |
| 175 |
| 176 /** |
| 177 * @override |
| 178 * @param {number} entryIndex |
| 179 * @return {string} |
| 180 */ |
| 181 entryColor(entryIndex) { |
| 182 var node = this._entryNodes[entryIndex]; |
| 183 // For idle and program, we want different 'shades of gray', so we fallback
to functionName as scriptId = 0 |
| 184 // For rest of nodes e.g eval scripts, if url is empty then scriptId will be
guaranteed to be non-zero |
| 185 return this._colorGenerator.colorForID(node.url || (node.scriptId !== '0' ?
node.scriptId : node.functionName)); |
| 186 } |
| 187 |
| 188 /** |
| 189 * @override |
| 190 * @param {number} entryIndex |
| 191 * @param {!CanvasRenderingContext2D} context |
| 192 * @param {?string} text |
| 193 * @param {number} barX |
| 194 * @param {number} barY |
| 195 * @param {number} barWidth |
| 196 * @param {number} barHeight |
| 197 * @return {boolean} |
| 198 */ |
| 199 decorateEntry(entryIndex, context, text, barX, barY, barWidth, barHeight) { |
| 200 return false; |
| 201 } |
| 202 |
| 203 /** |
| 204 * @override |
| 205 * @param {number} entryIndex |
| 206 * @return {boolean} |
| 207 */ |
| 208 forceDecoration(entryIndex) { |
| 209 return false; |
| 210 } |
| 211 |
| 212 /** |
| 213 * @override |
| 214 * @return {number} |
| 215 */ |
| 216 paddingLeft() { |
| 217 return 0; |
| 218 } |
| 219 |
| 220 /** |
| 221 * @override |
| 222 * @param {number} entryIndex |
| 223 * @return {string} |
| 224 */ |
| 225 textColor(entryIndex) { |
| 226 return '#333'; |
| 227 } |
250 }; | 228 }; |
251 | 229 |
252 | 230 |
253 /** | 231 /** |
254 * @constructor | |
255 * @implements {WebInspector.Searchable} | 232 * @implements {WebInspector.Searchable} |
256 * @extends {WebInspector.VBox} | 233 * @unrestricted |
257 * @param {!WebInspector.SearchableView} searchableView | |
258 * @param {!WebInspector.FlameChartDataProvider} dataProvider | |
259 */ | 234 */ |
260 WebInspector.CPUProfileFlameChart = function(searchableView, dataProvider) | 235 WebInspector.CPUProfileFlameChart = class extends WebInspector.VBox { |
261 { | 236 /** |
262 WebInspector.VBox.call(this); | 237 * @param {!WebInspector.SearchableView} searchableView |
263 this.element.id = "cpu-flame-chart"; | 238 * @param {!WebInspector.FlameChartDataProvider} dataProvider |
| 239 */ |
| 240 constructor(searchableView, dataProvider) { |
| 241 super(); |
| 242 this.element.id = 'cpu-flame-chart'; |
264 | 243 |
265 this._searchableView = searchableView; | 244 this._searchableView = searchableView; |
266 this._overviewPane = new WebInspector.CPUProfileFlameChart.OverviewPane(data
Provider); | 245 this._overviewPane = new WebInspector.CPUProfileFlameChart.OverviewPane(data
Provider); |
267 this._overviewPane.show(this.element); | 246 this._overviewPane.show(this.element); |
268 | 247 |
269 this._mainPane = new WebInspector.FlameChart(dataProvider, this._overviewPan
e); | 248 this._mainPane = new WebInspector.FlameChart(dataProvider, this._overviewPan
e); |
270 this._mainPane.show(this.element); | 249 this._mainPane.show(this.element); |
271 this._mainPane.addEventListener(WebInspector.FlameChart.Events.EntrySelected
, this._onEntrySelected, this); | 250 this._mainPane.addEventListener(WebInspector.FlameChart.Events.EntrySelected
, this._onEntrySelected, this); |
272 this._overviewPane.addEventListener(WebInspector.OverviewGrid.Events.WindowC
hanged, this._onWindowChanged, this); | 251 this._overviewPane.addEventListener(WebInspector.OverviewGrid.Events.WindowC
hanged, this._onWindowChanged, this); |
273 this._dataProvider = dataProvider; | 252 this._dataProvider = dataProvider; |
274 this._searchResults = []; | 253 this._searchResults = []; |
| 254 } |
| 255 |
| 256 /** |
| 257 * @override |
| 258 */ |
| 259 focus() { |
| 260 this._mainPane.focus(); |
| 261 } |
| 262 |
| 263 /** |
| 264 * @param {!WebInspector.Event} event |
| 265 */ |
| 266 _onWindowChanged(event) { |
| 267 var windowLeft = event.data.windowTimeLeft; |
| 268 var windowRight = event.data.windowTimeRight; |
| 269 this._mainPane.setWindowTimes(windowLeft, windowRight); |
| 270 } |
| 271 |
| 272 /** |
| 273 * @param {number} timeLeft |
| 274 * @param {number} timeRight |
| 275 */ |
| 276 selectRange(timeLeft, timeRight) { |
| 277 this._overviewPane._selectRange(timeLeft, timeRight); |
| 278 } |
| 279 |
| 280 /** |
| 281 * @param {!WebInspector.Event} event |
| 282 */ |
| 283 _onEntrySelected(event) { |
| 284 this.dispatchEventToListeners(WebInspector.FlameChart.Events.EntrySelected,
event.data); |
| 285 } |
| 286 |
| 287 update() { |
| 288 this._overviewPane.update(); |
| 289 this._mainPane.update(); |
| 290 } |
| 291 |
| 292 /** |
| 293 * @override |
| 294 * @param {!WebInspector.SearchableView.SearchConfig} searchConfig |
| 295 * @param {boolean} shouldJump |
| 296 * @param {boolean=} jumpBackwards |
| 297 */ |
| 298 performSearch(searchConfig, shouldJump, jumpBackwards) { |
| 299 var matcher = createPlainTextSearchRegex(searchConfig.query, searchConfig.ca
seSensitive ? '' : 'i'); |
| 300 |
| 301 var selectedEntryIndex = this._searchResultIndex !== -1 ? this._searchResult
s[this._searchResultIndex] : -1; |
| 302 this._searchResults = []; |
| 303 var entriesCount = this._dataProvider._entryNodes.length; |
| 304 for (var index = 0; index < entriesCount; ++index) { |
| 305 if (this._dataProvider.entryTitle(index).match(matcher)) |
| 306 this._searchResults.push(index); |
| 307 } |
| 308 |
| 309 if (this._searchResults.length) { |
| 310 this._searchResultIndex = this._searchResults.indexOf(selectedEntryIndex); |
| 311 if (this._searchResultIndex === -1) |
| 312 this._searchResultIndex = jumpBackwards ? this._searchResults.length - 1
: 0; |
| 313 this._mainPane.setSelectedEntry(this._searchResults[this._searchResultInde
x]); |
| 314 } else { |
| 315 this.searchCanceled(); |
| 316 } |
| 317 this._searchableView.updateSearchMatchesCount(this._searchResults.length); |
| 318 this._searchableView.updateCurrentMatchIndex(this._searchResultIndex); |
| 319 } |
| 320 |
| 321 /** |
| 322 * @override |
| 323 */ |
| 324 searchCanceled() { |
| 325 this._mainPane.setSelectedEntry(-1); |
| 326 this._searchResults = []; |
| 327 this._searchResultIndex = -1; |
| 328 } |
| 329 |
| 330 /** |
| 331 * @override |
| 332 */ |
| 333 jumpToNextSearchResult() { |
| 334 this._searchResultIndex = (this._searchResultIndex + 1) % this._searchResult
s.length; |
| 335 this._mainPane.setSelectedEntry(this._searchResults[this._searchResultIndex]
); |
| 336 this._searchableView.updateCurrentMatchIndex(this._searchResultIndex); |
| 337 } |
| 338 |
| 339 /** |
| 340 * @override |
| 341 */ |
| 342 jumpToPreviousSearchResult() { |
| 343 this._searchResultIndex = (this._searchResultIndex - 1 + this._searchResults
.length) % this._searchResults.length; |
| 344 this._mainPane.setSelectedEntry(this._searchResults[this._searchResultIndex]
); |
| 345 this._searchableView.updateCurrentMatchIndex(this._searchResultIndex); |
| 346 } |
| 347 |
| 348 /** |
| 349 * @override |
| 350 * @return {boolean} |
| 351 */ |
| 352 supportsCaseSensitiveSearch() { |
| 353 return true; |
| 354 } |
| 355 |
| 356 /** |
| 357 * @override |
| 358 * @return {boolean} |
| 359 */ |
| 360 supportsRegexSearch() { |
| 361 return false; |
| 362 } |
275 }; | 363 }; |
276 | 364 |
277 WebInspector.CPUProfileFlameChart.prototype = { | 365 /** |
278 focus: function() | 366 * @implements {WebInspector.TimelineGrid.Calculator} |
279 { | 367 * @unrestricted |
280 this._mainPane.focus(); | 368 */ |
281 }, | 369 WebInspector.CPUProfileFlameChart.OverviewCalculator = class { |
282 | 370 constructor(dataProvider) { |
283 /** | 371 this._dataProvider = dataProvider; |
284 * @param {!WebInspector.Event} event | 372 } |
285 */ | 373 |
286 _onWindowChanged: function(event) | 374 /** |
287 { | 375 * @override |
288 var windowLeft = event.data.windowTimeLeft; | 376 * @return {number} |
289 var windowRight = event.data.windowTimeRight; | 377 */ |
290 this._mainPane.setWindowTimes(windowLeft, windowRight); | 378 paddingLeft() { |
291 }, | 379 return 0; |
292 | 380 } |
293 /** | 381 |
294 * @param {number} timeLeft | 382 /** |
295 * @param {number} timeRight | 383 * @param {!WebInspector.CPUProfileFlameChart.OverviewPane} overviewPane |
296 */ | 384 */ |
297 selectRange: function(timeLeft, timeRight) | 385 _updateBoundaries(overviewPane) { |
298 { | 386 this._minimumBoundaries = overviewPane._dataProvider.minimumBoundary(); |
299 this._overviewPane._selectRange(timeLeft, timeRight); | 387 var totalTime = overviewPane._dataProvider.totalTime(); |
300 }, | 388 this._maximumBoundaries = this._minimumBoundaries + totalTime; |
301 | 389 this._xScaleFactor = overviewPane._overviewContainer.clientWidth / totalTime
; |
302 /** | 390 } |
303 * @param {!WebInspector.Event} event | 391 |
304 */ | 392 /** |
305 _onEntrySelected: function(event) | 393 * @override |
306 { | 394 * @param {number} time |
307 this.dispatchEventToListeners(WebInspector.FlameChart.Events.EntrySelect
ed, event.data); | 395 * @return {number} |
308 }, | 396 */ |
309 | 397 computePosition(time) { |
310 update: function() | 398 return (time - this._minimumBoundaries) * this._xScaleFactor; |
311 { | 399 } |
312 this._overviewPane.update(); | 400 |
313 this._mainPane.update(); | 401 /** |
314 }, | 402 * @override |
315 | 403 * @param {number} value |
316 /** | 404 * @param {number=} precision |
317 * @override | 405 * @return {string} |
318 * @param {!WebInspector.SearchableView.SearchConfig} searchConfig | 406 */ |
319 * @param {boolean} shouldJump | 407 formatValue(value, precision) { |
320 * @param {boolean=} jumpBackwards | 408 return this._dataProvider.formatValue(value - this._minimumBoundaries, preci
sion); |
321 */ | 409 } |
322 performSearch: function(searchConfig, shouldJump, jumpBackwards) | 410 |
323 { | 411 /** |
324 var matcher = createPlainTextSearchRegex(searchConfig.query, searchConfi
g.caseSensitive ? "" : "i"); | 412 * @override |
325 | 413 * @return {number} |
326 var selectedEntryIndex = this._searchResultIndex !== -1 ? this._searchRe
sults[this._searchResultIndex] : -1; | 414 */ |
327 this._searchResults = []; | 415 maximumBoundary() { |
328 var entriesCount = this._dataProvider._entryNodes.length; | 416 return this._maximumBoundaries; |
329 for (var index = 0; index < entriesCount; ++index) { | 417 } |
330 if (this._dataProvider.entryTitle(index).match(matcher)) | 418 |
331 this._searchResults.push(index); | 419 /** |
332 } | 420 * @override |
333 | 421 * @return {number} |
334 if (this._searchResults.length) { | 422 */ |
335 this._searchResultIndex = this._searchResults.indexOf(selectedEntryI
ndex); | 423 minimumBoundary() { |
336 if (this._searchResultIndex === -1) | 424 return this._minimumBoundaries; |
337 this._searchResultIndex = jumpBackwards ? this._searchResults.le
ngth - 1 : 0; | 425 } |
338 this._mainPane.setSelectedEntry(this._searchResults[this._searchResu
ltIndex]); | 426 |
339 } else { | 427 /** |
340 this.searchCanceled(); | 428 * @override |
341 } | 429 * @return {number} |
342 this._searchableView.updateSearchMatchesCount(this._searchResults.length
); | 430 */ |
343 this._searchableView.updateCurrentMatchIndex(this._searchResultIndex); | 431 zeroTime() { |
344 }, | 432 return this._minimumBoundaries; |
345 | 433 } |
346 /** | 434 |
347 * @override | 435 /** |
348 */ | 436 * @override |
349 searchCanceled: function() | 437 * @return {number} |
350 { | 438 */ |
351 this._mainPane.setSelectedEntry(-1); | 439 boundarySpan() { |
352 this._searchResults = []; | 440 return this._maximumBoundaries - this._minimumBoundaries; |
353 this._searchResultIndex = -1; | 441 } |
354 }, | |
355 | |
356 /** | |
357 * @override | |
358 */ | |
359 jumpToNextSearchResult: function() | |
360 { | |
361 this._searchResultIndex = (this._searchResultIndex + 1) % this._searchRe
sults.length; | |
362 this._mainPane.setSelectedEntry(this._searchResults[this._searchResultIn
dex]); | |
363 this._searchableView.updateCurrentMatchIndex(this._searchResultIndex); | |
364 }, | |
365 | |
366 /** | |
367 * @override | |
368 */ | |
369 jumpToPreviousSearchResult: function() | |
370 { | |
371 this._searchResultIndex = (this._searchResultIndex - 1 + this._searchRes
ults.length) % this._searchResults.length; | |
372 this._mainPane.setSelectedEntry(this._searchResults[this._searchResultIn
dex]); | |
373 this._searchableView.updateCurrentMatchIndex(this._searchResultIndex); | |
374 }, | |
375 | |
376 /** | |
377 * @override | |
378 * @return {boolean} | |
379 */ | |
380 supportsCaseSensitiveSearch: function() | |
381 { | |
382 return true; | |
383 }, | |
384 | |
385 /** | |
386 * @override | |
387 * @return {boolean} | |
388 */ | |
389 supportsRegexSearch: function() | |
390 { | |
391 return false; | |
392 }, | |
393 | |
394 __proto__: WebInspector.VBox.prototype | |
395 }; | 442 }; |
396 | 443 |
397 /** | 444 /** |
398 * @constructor | 445 * @implements {WebInspector.FlameChartDelegate} |
399 * @implements {WebInspector.TimelineGrid.Calculator} | 446 * @unrestricted |
400 */ | 447 */ |
401 WebInspector.CPUProfileFlameChart.OverviewCalculator = function(dataProvider) | 448 WebInspector.CPUProfileFlameChart.OverviewPane = class extends WebInspector.VBox
{ |
402 { | 449 /** |
403 this._dataProvider = dataProvider; | 450 * @param {!WebInspector.FlameChartDataProvider} dataProvider |
404 }; | 451 */ |
405 | 452 constructor(dataProvider) { |
406 WebInspector.CPUProfileFlameChart.OverviewCalculator.prototype = { | 453 super(); |
407 /** | 454 this.element.classList.add('cpu-profile-flame-chart-overview-pane'); |
408 * @override | 455 this._overviewContainer = this.element.createChild('div', 'cpu-profile-flame
-chart-overview-container'); |
409 * @return {number} | 456 this._overviewGrid = new WebInspector.OverviewGrid('cpu-profile-flame-chart'
); |
410 */ | 457 this._overviewGrid.element.classList.add('fill'); |
411 paddingLeft: function() | 458 this._overviewCanvas = this._overviewContainer.createChild('canvas', 'cpu-pr
ofile-flame-chart-overview-canvas'); |
412 { | |
413 return 0; | |
414 }, | |
415 | |
416 /** | |
417 * @param {!WebInspector.CPUProfileFlameChart.OverviewPane} overviewPane | |
418 */ | |
419 _updateBoundaries: function(overviewPane) | |
420 { | |
421 this._minimumBoundaries = overviewPane._dataProvider.minimumBoundary(); | |
422 var totalTime = overviewPane._dataProvider.totalTime(); | |
423 this._maximumBoundaries = this._minimumBoundaries + totalTime; | |
424 this._xScaleFactor = overviewPane._overviewContainer.clientWidth / total
Time; | |
425 }, | |
426 | |
427 /** | |
428 * @override | |
429 * @param {number} time | |
430 * @return {number} | |
431 */ | |
432 computePosition: function(time) | |
433 { | |
434 return (time - this._minimumBoundaries) * this._xScaleFactor; | |
435 }, | |
436 | |
437 /** | |
438 * @override | |
439 * @param {number} value | |
440 * @param {number=} precision | |
441 * @return {string} | |
442 */ | |
443 formatValue: function(value, precision) | |
444 { | |
445 return this._dataProvider.formatValue(value - this._minimumBoundaries, p
recision); | |
446 }, | |
447 | |
448 /** | |
449 * @override | |
450 * @return {number} | |
451 */ | |
452 maximumBoundary: function() | |
453 { | |
454 return this._maximumBoundaries; | |
455 }, | |
456 | |
457 /** | |
458 * @override | |
459 * @return {number} | |
460 */ | |
461 minimumBoundary: function() | |
462 { | |
463 return this._minimumBoundaries; | |
464 }, | |
465 | |
466 /** | |
467 * @override | |
468 * @return {number} | |
469 */ | |
470 zeroTime: function() | |
471 { | |
472 return this._minimumBoundaries; | |
473 }, | |
474 | |
475 /** | |
476 * @override | |
477 * @return {number} | |
478 */ | |
479 boundarySpan: function() | |
480 { | |
481 return this._maximumBoundaries - this._minimumBoundaries; | |
482 } | |
483 }; | |
484 | |
485 /** | |
486 * @constructor | |
487 * @extends {WebInspector.VBox} | |
488 * @implements {WebInspector.FlameChartDelegate} | |
489 * @param {!WebInspector.FlameChartDataProvider} dataProvider | |
490 */ | |
491 WebInspector.CPUProfileFlameChart.OverviewPane = function(dataProvider) | |
492 { | |
493 WebInspector.VBox.call(this); | |
494 this.element.classList.add("cpu-profile-flame-chart-overview-pane"); | |
495 this._overviewContainer = this.element.createChild("div", "cpu-profile-flame
-chart-overview-container"); | |
496 this._overviewGrid = new WebInspector.OverviewGrid("cpu-profile-flame-chart"
); | |
497 this._overviewGrid.element.classList.add("fill"); | |
498 this._overviewCanvas = this._overviewContainer.createChild("canvas", "cpu-pr
ofile-flame-chart-overview-canvas"); | |
499 this._overviewContainer.appendChild(this._overviewGrid.element); | 459 this._overviewContainer.appendChild(this._overviewGrid.element); |
500 this._overviewCalculator = new WebInspector.CPUProfileFlameChart.OverviewCal
culator(dataProvider); | 460 this._overviewCalculator = new WebInspector.CPUProfileFlameChart.OverviewCal
culator(dataProvider); |
501 this._dataProvider = dataProvider; | 461 this._dataProvider = dataProvider; |
502 this._overviewGrid.addEventListener(WebInspector.OverviewGrid.Events.WindowC
hanged, this._onWindowChanged, this); | 462 this._overviewGrid.addEventListener(WebInspector.OverviewGrid.Events.WindowC
hanged, this._onWindowChanged, this); |
| 463 } |
| 464 |
| 465 /** |
| 466 * @override |
| 467 * @param {number} windowStartTime |
| 468 * @param {number} windowEndTime |
| 469 */ |
| 470 requestWindowTimes(windowStartTime, windowEndTime) { |
| 471 this._selectRange(windowStartTime, windowEndTime); |
| 472 } |
| 473 |
| 474 /** |
| 475 * @override |
| 476 * @param {number} startTime |
| 477 * @param {number} endTime |
| 478 */ |
| 479 updateRangeSelection(startTime, endTime) { |
| 480 } |
| 481 |
| 482 /** |
| 483 * @param {number} timeLeft |
| 484 * @param {number} timeRight |
| 485 */ |
| 486 _selectRange(timeLeft, timeRight) { |
| 487 var startTime = this._dataProvider.minimumBoundary(); |
| 488 var totalTime = this._dataProvider.totalTime(); |
| 489 this._overviewGrid.setWindow((timeLeft - startTime) / totalTime, (timeRight
- startTime) / totalTime); |
| 490 } |
| 491 |
| 492 /** |
| 493 * @param {!WebInspector.Event} event |
| 494 */ |
| 495 _onWindowChanged(event) { |
| 496 var startTime = this._dataProvider.minimumBoundary(); |
| 497 var totalTime = this._dataProvider.totalTime(); |
| 498 var data = { |
| 499 windowTimeLeft: startTime + this._overviewGrid.windowLeft() * totalTime, |
| 500 windowTimeRight: startTime + this._overviewGrid.windowRight() * totalTime |
| 501 }; |
| 502 this.dispatchEventToListeners(WebInspector.OverviewGrid.Events.WindowChanged
, data); |
| 503 } |
| 504 |
| 505 /** |
| 506 * @return {?WebInspector.FlameChart.TimelineData} |
| 507 */ |
| 508 _timelineData() { |
| 509 return this._dataProvider.timelineData(); |
| 510 } |
| 511 |
| 512 /** |
| 513 * @override |
| 514 */ |
| 515 onResize() { |
| 516 this._scheduleUpdate(); |
| 517 } |
| 518 |
| 519 _scheduleUpdate() { |
| 520 if (this._updateTimerId) |
| 521 return; |
| 522 this._updateTimerId = this.element.window().requestAnimationFrame(this.updat
e.bind(this)); |
| 523 } |
| 524 |
| 525 update() { |
| 526 this._updateTimerId = 0; |
| 527 var timelineData = this._timelineData(); |
| 528 if (!timelineData) |
| 529 return; |
| 530 this._resetCanvas( |
| 531 this._overviewContainer.clientWidth, |
| 532 this._overviewContainer.clientHeight - WebInspector.FlameChart.DividersB
arHeight); |
| 533 this._overviewCalculator._updateBoundaries(this); |
| 534 this._overviewGrid.updateDividers(this._overviewCalculator); |
| 535 this._drawOverviewCanvas(); |
| 536 } |
| 537 |
| 538 _drawOverviewCanvas() { |
| 539 var canvasWidth = this._overviewCanvas.width; |
| 540 var canvasHeight = this._overviewCanvas.height; |
| 541 var drawData = this._calculateDrawData(canvasWidth); |
| 542 var context = this._overviewCanvas.getContext('2d'); |
| 543 var ratio = window.devicePixelRatio; |
| 544 var offsetFromBottom = ratio; |
| 545 var lineWidth = 1; |
| 546 var yScaleFactor = canvasHeight / (this._dataProvider.maxStackDepth() * 1.1)
; |
| 547 context.lineWidth = lineWidth; |
| 548 context.translate(0.5, 0.5); |
| 549 context.strokeStyle = 'rgba(20,0,0,0.4)'; |
| 550 context.fillStyle = 'rgba(214,225,254,0.8)'; |
| 551 context.moveTo(-lineWidth, canvasHeight + lineWidth); |
| 552 context.lineTo(-lineWidth, Math.round(canvasHeight - drawData[0] * yScaleFac
tor - offsetFromBottom)); |
| 553 var value; |
| 554 for (var x = 0; x < canvasWidth; ++x) { |
| 555 value = Math.round(canvasHeight - drawData[x] * yScaleFactor - offsetFromB
ottom); |
| 556 context.lineTo(x, value); |
| 557 } |
| 558 context.lineTo(canvasWidth + lineWidth, value); |
| 559 context.lineTo(canvasWidth + lineWidth, canvasHeight + lineWidth); |
| 560 context.fill(); |
| 561 context.stroke(); |
| 562 context.closePath(); |
| 563 } |
| 564 |
| 565 /** |
| 566 * @param {number} width |
| 567 * @return {!Uint8Array} |
| 568 */ |
| 569 _calculateDrawData(width) { |
| 570 var dataProvider = this._dataProvider; |
| 571 var timelineData = this._timelineData(); |
| 572 var entryStartTimes = timelineData.entryStartTimes; |
| 573 var entryTotalTimes = timelineData.entryTotalTimes; |
| 574 var entryLevels = timelineData.entryLevels; |
| 575 var length = entryStartTimes.length; |
| 576 var minimumBoundary = this._dataProvider.minimumBoundary(); |
| 577 |
| 578 var drawData = new Uint8Array(width); |
| 579 var scaleFactor = width / dataProvider.totalTime(); |
| 580 |
| 581 for (var entryIndex = 0; entryIndex < length; ++entryIndex) { |
| 582 var start = Math.floor((entryStartTimes[entryIndex] - minimumBoundary) * s
caleFactor); |
| 583 var finish = |
| 584 Math.floor((entryStartTimes[entryIndex] - minimumBoundary + entryTotal
Times[entryIndex]) * scaleFactor); |
| 585 for (var x = start; x <= finish; ++x) |
| 586 drawData[x] = Math.max(drawData[x], entryLevels[entryIndex] + 1); |
| 587 } |
| 588 return drawData; |
| 589 } |
| 590 |
| 591 /** |
| 592 * @param {number} width |
| 593 * @param {number} height |
| 594 */ |
| 595 _resetCanvas(width, height) { |
| 596 var ratio = window.devicePixelRatio; |
| 597 this._overviewCanvas.width = width * ratio; |
| 598 this._overviewCanvas.height = height * ratio; |
| 599 this._overviewCanvas.style.width = width + 'px'; |
| 600 this._overviewCanvas.style.height = height + 'px'; |
| 601 } |
503 }; | 602 }; |
504 | |
505 WebInspector.CPUProfileFlameChart.OverviewPane.prototype = { | |
506 /** | |
507 * @override | |
508 * @param {number} windowStartTime | |
509 * @param {number} windowEndTime | |
510 */ | |
511 requestWindowTimes: function(windowStartTime, windowEndTime) | |
512 { | |
513 this._selectRange(windowStartTime, windowEndTime); | |
514 }, | |
515 | |
516 /** | |
517 * @override | |
518 * @param {number} startTime | |
519 * @param {number} endTime | |
520 */ | |
521 updateRangeSelection: function(startTime, endTime) | |
522 { | |
523 }, | |
524 | |
525 /** | |
526 * @param {number} timeLeft | |
527 * @param {number} timeRight | |
528 */ | |
529 _selectRange: function(timeLeft, timeRight) | |
530 { | |
531 var startTime = this._dataProvider.minimumBoundary(); | |
532 var totalTime = this._dataProvider.totalTime(); | |
533 this._overviewGrid.setWindow((timeLeft - startTime) / totalTime, (timeRi
ght - startTime) / totalTime); | |
534 }, | |
535 | |
536 /** | |
537 * @param {!WebInspector.Event} event | |
538 */ | |
539 _onWindowChanged: function(event) | |
540 { | |
541 var startTime = this._dataProvider.minimumBoundary(); | |
542 var totalTime = this._dataProvider.totalTime(); | |
543 var data = { | |
544 windowTimeLeft: startTime + this._overviewGrid.windowLeft() * totalT
ime, | |
545 windowTimeRight: startTime + this._overviewGrid.windowRight() * tota
lTime | |
546 }; | |
547 this.dispatchEventToListeners(WebInspector.OverviewGrid.Events.WindowCha
nged, data); | |
548 }, | |
549 | |
550 /** | |
551 * @return {?WebInspector.FlameChart.TimelineData} | |
552 */ | |
553 _timelineData: function() | |
554 { | |
555 return this._dataProvider.timelineData(); | |
556 }, | |
557 | |
558 onResize: function() | |
559 { | |
560 this._scheduleUpdate(); | |
561 }, | |
562 | |
563 _scheduleUpdate: function() | |
564 { | |
565 if (this._updateTimerId) | |
566 return; | |
567 this._updateTimerId = this.element.window().requestAnimationFrame(this.u
pdate.bind(this)); | |
568 }, | |
569 | |
570 update: function() | |
571 { | |
572 this._updateTimerId = 0; | |
573 var timelineData = this._timelineData(); | |
574 if (!timelineData) | |
575 return; | |
576 this._resetCanvas(this._overviewContainer.clientWidth, this._overviewCon
tainer.clientHeight - WebInspector.FlameChart.DividersBarHeight); | |
577 this._overviewCalculator._updateBoundaries(this); | |
578 this._overviewGrid.updateDividers(this._overviewCalculator); | |
579 this._drawOverviewCanvas(); | |
580 }, | |
581 | |
582 _drawOverviewCanvas: function() | |
583 { | |
584 var canvasWidth = this._overviewCanvas.width; | |
585 var canvasHeight = this._overviewCanvas.height; | |
586 var drawData = this._calculateDrawData(canvasWidth); | |
587 var context = this._overviewCanvas.getContext("2d"); | |
588 var ratio = window.devicePixelRatio; | |
589 var offsetFromBottom = ratio; | |
590 var lineWidth = 1; | |
591 var yScaleFactor = canvasHeight / (this._dataProvider.maxStackDepth() *
1.1); | |
592 context.lineWidth = lineWidth; | |
593 context.translate(0.5, 0.5); | |
594 context.strokeStyle = "rgba(20,0,0,0.4)"; | |
595 context.fillStyle = "rgba(214,225,254,0.8)"; | |
596 context.moveTo(-lineWidth, canvasHeight + lineWidth); | |
597 context.lineTo(-lineWidth, Math.round(canvasHeight - drawData[0] * yScal
eFactor - offsetFromBottom)); | |
598 var value; | |
599 for (var x = 0; x < canvasWidth; ++x) { | |
600 value = Math.round(canvasHeight - drawData[x] * yScaleFactor - offse
tFromBottom); | |
601 context.lineTo(x, value); | |
602 } | |
603 context.lineTo(canvasWidth + lineWidth, value); | |
604 context.lineTo(canvasWidth + lineWidth, canvasHeight + lineWidth); | |
605 context.fill(); | |
606 context.stroke(); | |
607 context.closePath(); | |
608 }, | |
609 | |
610 /** | |
611 * @param {number} width | |
612 * @return {!Uint8Array} | |
613 */ | |
614 _calculateDrawData: function(width) | |
615 { | |
616 var dataProvider = this._dataProvider; | |
617 var timelineData = this._timelineData(); | |
618 var entryStartTimes = timelineData.entryStartTimes; | |
619 var entryTotalTimes = timelineData.entryTotalTimes; | |
620 var entryLevels = timelineData.entryLevels; | |
621 var length = entryStartTimes.length; | |
622 var minimumBoundary = this._dataProvider.minimumBoundary(); | |
623 | |
624 var drawData = new Uint8Array(width); | |
625 var scaleFactor = width / dataProvider.totalTime(); | |
626 | |
627 for (var entryIndex = 0; entryIndex < length; ++entryIndex) { | |
628 var start = Math.floor((entryStartTimes[entryIndex] - minimumBoundar
y) * scaleFactor); | |
629 var finish = Math.floor((entryStartTimes[entryIndex] - minimumBounda
ry + entryTotalTimes[entryIndex]) * scaleFactor); | |
630 for (var x = start; x <= finish; ++x) | |
631 drawData[x] = Math.max(drawData[x], entryLevels[entryIndex] + 1)
; | |
632 } | |
633 return drawData; | |
634 }, | |
635 | |
636 /** | |
637 * @param {number} width | |
638 * @param {number} height | |
639 */ | |
640 _resetCanvas: function(width, height) | |
641 { | |
642 var ratio = window.devicePixelRatio; | |
643 this._overviewCanvas.width = width * ratio; | |
644 this._overviewCanvas.height = height * ratio; | |
645 this._overviewCanvas.style.width = width + "px"; | |
646 this._overviewCanvas.style.height = height + "px"; | |
647 }, | |
648 | |
649 __proto__: WebInspector.VBox.prototype | |
650 }; | |
OLD | NEW |