OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2013 Google Inc. All rights reserved. | 2 * Copyright (C) 2013 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 236 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
247 path["transfer"].rect(r - tickWidth / 2, y, tickWidth, bandHeight -
1); | 247 path["transfer"].rect(r - tickWidth / 2, y, tickWidth, bandHeight -
1); |
248 } | 248 } |
249 }, | 249 }, |
250 | 250 |
251 __proto__: WebInspector.TimelineEventOverview.prototype | 251 __proto__: WebInspector.TimelineEventOverview.prototype |
252 } | 252 } |
253 | 253 |
254 /** | 254 /** |
255 * @constructor | 255 * @constructor |
256 * @extends {WebInspector.TimelineEventOverview} | 256 * @extends {WebInspector.TimelineEventOverview} |
257 * @param {string} id | |
258 * @param {string} title | |
259 * @param {!WebInspector.TimelineModel} model | 257 * @param {!WebInspector.TimelineModel} model |
260 */ | 258 */ |
261 WebInspector.TimelineEventOverview.Thread = function(id, title, model) | 259 WebInspector.TimelineEventOverview.CPUActivity = function(model) |
262 { | 260 { |
263 WebInspector.TimelineEventOverview.call(this, id, title, model) | 261 WebInspector.TimelineEventOverview.call(this, "cpu-activity", WebInspector.U
IString("CPU"), model); |
264 this._fillStyles = {}; | 262 this._fillStyles = {}; |
265 var categories = WebInspector.TimelineUIUtils.categories(); | 263 var categories = WebInspector.TimelineUIUtils.categories(); |
266 for (var category in categories) { | 264 for (var category in categories) { |
267 this._fillStyles[category] = categories[category].fillColorStop1; | 265 this._fillStyles[category] = categories[category].fillColorStop1; |
268 categories[category].addEventListener(WebInspector.TimelineCategory.Even
ts.VisibilityChanged, this._onCategoryVisibilityChanged, this); | 266 categories[category].addEventListener(WebInspector.TimelineCategory.Even
ts.VisibilityChanged, this._onCategoryVisibilityChanged, this); |
269 } | 267 } |
270 this._disabledCategoryFillStyle = "hsl(0, 0%, 67%)"; | 268 this._disabledCategoryFillStyle = "hsl(0, 0%, 67%)"; |
| 269 this._backgroundCanvas = this.element.createChild("canvas", "fill background
"); |
271 } | 270 } |
272 | 271 |
273 WebInspector.TimelineEventOverview.Thread.prototype = { | 272 WebInspector.TimelineEventOverview.CPUActivity.prototype = { |
274 /** | 273 /** |
275 * @override | 274 * @override |
276 */ | 275 */ |
277 dispose: function() | 276 dispose: function() |
278 { | 277 { |
279 WebInspector.TimelineOverviewBase.prototype.dispose.call(this); | 278 WebInspector.TimelineOverviewBase.prototype.dispose.call(this); |
280 var categories = WebInspector.TimelineUIUtils.categories(); | 279 var categories = WebInspector.TimelineUIUtils.categories(); |
281 for (var category in categories) | 280 for (var category in categories) |
282 categories[category].removeEventListener(WebInspector.TimelineCatego
ry.Events.VisibilityChanged, this._onCategoryVisibilityChanged, this); | 281 categories[category].removeEventListener(WebInspector.TimelineCatego
ry.Events.VisibilityChanged, this._onCategoryVisibilityChanged, this); |
283 }, | 282 }, |
284 | 283 |
285 _onCategoryVisibilityChanged: function() | 284 _onCategoryVisibilityChanged: function() |
286 { | 285 { |
287 this.update(); | 286 this.update(); |
288 }, | 287 }, |
289 | 288 |
290 /** | 289 /** |
291 * @param {!WebInspector.TimelineCategory} category | 290 * @param {!WebInspector.TimelineCategory} category |
292 * @return {string} | 291 * @return {string} |
293 */ | 292 */ |
294 _categoryColor: function(category) | 293 _categoryColor: function(category) |
295 { | 294 { |
296 return category.hidden ? this._disabledCategoryFillStyle : this._fillSty
les[category.name]; | 295 return category.hidden ? this._disabledCategoryFillStyle : this._fillSty
les[category.name]; |
297 }, | 296 }, |
298 | 297 |
299 __proto__: WebInspector.TimelineEventOverview.prototype | 298 /** |
300 } | 299 * @override |
| 300 */ |
| 301 resetCanvas: function() |
| 302 { |
| 303 WebInspector.TimelineEventOverview.prototype.resetCanvas.call(this); |
| 304 this._backgroundCanvas.width = this.element.clientWidth * window.deviceP
ixelRatio; |
| 305 this._backgroundCanvas.height = this.element.clientHeight * window.devic
ePixelRatio; |
| 306 }, |
301 | 307 |
302 /** | |
303 * @constructor | |
304 * @extends {WebInspector.TimelineEventOverview.Thread} | |
305 * @param {!WebInspector.TimelineModel} model | |
306 */ | |
307 WebInspector.TimelineEventOverview.MainThread = function(model) | |
308 { | |
309 WebInspector.TimelineEventOverview.Thread.call(this, "main-thread", WebInspe
ctor.UIString("CPU"), model) | |
310 } | |
311 | |
312 WebInspector.TimelineEventOverview.MainThread.prototype = { | |
313 /** | 308 /** |
314 * @override | 309 * @override |
315 */ | 310 */ |
316 update: function() | 311 update: function() |
317 { | 312 { |
318 WebInspector.TimelineEventOverview.prototype.update.call(this); | 313 WebInspector.TimelineEventOverview.prototype.update.call(this); |
319 var events = this._model.mainThreadEvents(); | |
320 if (!events.length) | |
321 return; | |
322 var /** @const */ quantSizePx = 4 * window.devicePixelRatio; | 314 var /** @const */ quantSizePx = 4 * window.devicePixelRatio; |
323 var height = this._canvas.height; | 315 var height = this._canvas.height; |
324 var baseLine = height; | 316 var baseLine = height; |
325 var timeOffset = this._model.minimumRecordTime(); | 317 var timeOffset = this._model.minimumRecordTime(); |
326 var timeSpan = this._model.maximumRecordTime() - timeOffset; | 318 var timeSpan = this._model.maximumRecordTime() - timeOffset; |
327 var scale = this._canvas.width / timeSpan; | 319 var scale = this._canvas.width / timeSpan; |
328 var quantTime = quantSizePx / scale; | 320 var quantTime = quantSizePx / scale; |
329 var quantizer = new WebInspector.Quantizer(timeOffset, quantTime, drawSa
mple.bind(this)); | |
330 var ctx = this._context; | |
331 var x = 0; | |
332 var categories = WebInspector.TimelineUIUtils.categories(); | 321 var categories = WebInspector.TimelineUIUtils.categories(); |
333 var categoryOrder = ["idle", "loading", "painting", "rendering", "script
ing", "other"]; | 322 var categoryOrder = ["idle", "loading", "painting", "rendering", "script
ing", "other"]; |
334 var otherIndex = categoryOrder.indexOf("other"); | 323 var otherIndex = categoryOrder.indexOf("other"); |
335 var idleIndex = 0; | 324 var idleIndex = 0; |
336 console.assert(idleIndex === categoryOrder.indexOf("idle")); | 325 console.assert(idleIndex === categoryOrder.indexOf("idle")); |
337 for (var i = idleIndex + 1; i < categoryOrder.length; ++i) | 326 for (var i = idleIndex + 1; i < categoryOrder.length; ++i) |
338 categories[categoryOrder[i]]._overviewIndex = i; | 327 categories[categoryOrder[i]]._overviewIndex = i; |
339 var categoryIndexStack = []; | 328 |
| 329 for (var thread of this._model.virtualThreads()) |
| 330 drawThreadEvents.call(this, this._backgroundCanvas.getContext("2d"),
thread.events); |
| 331 drawThreadEvents.call(this, this._context, this._model.mainThreadEvents(
)); |
340 | 332 |
341 /** | 333 /** |
342 * @param {!Array<number>} counters | 334 * @param {!CanvasRenderingContext2D} ctx |
| 335 * @param {!Array<!WebInspector.TracingModel.Event>} events |
343 * @this {WebInspector.TimelineEventOverview} | 336 * @this {WebInspector.TimelineEventOverview} |
344 */ | 337 */ |
345 function drawSample(counters) | 338 function drawThreadEvents(ctx, events) |
346 { | 339 { |
347 var y = baseLine; | 340 var quantizer = new WebInspector.Quantizer(timeOffset, quantTime, dr
awSample.bind(this)); |
348 for (var i = idleIndex + 1; i < counters.length; ++i) { | 341 var x = 0; |
349 if (!counters[i]) | 342 var categoryIndexStack = []; |
350 continue; | 343 |
351 var h = counters[i] / quantTime * height; | 344 /** |
352 ctx.fillStyle = this._categoryColor(categories[categoryOrder[i]]
); | 345 * @param {!Array<number>} counters |
353 ctx.fillRect(x, y - h, quantSizePx, h); | 346 * @this {WebInspector.TimelineEventOverview} |
354 y -= h; | 347 */ |
| 348 function drawSample(counters) |
| 349 { |
| 350 var y = baseLine; |
| 351 for (var i = idleIndex + 1; i < counters.length; ++i) { |
| 352 if (!counters[i]) |
| 353 continue; |
| 354 var h = counters[i] / quantTime * height; |
| 355 ctx.fillStyle = this._categoryColor(categories[categoryOrder
[i]]); |
| 356 ctx.fillRect(x, y - h, quantSizePx, h); |
| 357 y -= h; |
| 358 } |
| 359 x += quantSizePx; |
355 } | 360 } |
356 x += quantSizePx; | 361 |
| 362 /** |
| 363 * @param {!WebInspector.TracingModel.Event} e |
| 364 */ |
| 365 function onEventStart(e) |
| 366 { |
| 367 var index = categoryIndexStack.length ? categoryIndexStack.peekL
ast() : idleIndex; |
| 368 quantizer.appendInterval(e.startTime, index); |
| 369 categoryIndexStack.push(WebInspector.TimelineUIUtils.eventStyle(
e).category._overviewIndex || otherIndex); |
| 370 } |
| 371 |
| 372 /** |
| 373 * @param {!WebInspector.TracingModel.Event} e |
| 374 */ |
| 375 function onEventEnd(e) |
| 376 { |
| 377 quantizer.appendInterval(e.endTime, categoryIndexStack.pop()); |
| 378 } |
| 379 |
| 380 WebInspector.TimelineModel.forEachEvent(events, onEventStart, onEven
tEnd); |
| 381 quantizer.appendInterval(timeOffset + timeSpan + quantTime, idleInde
x); // Kick drawing the last bucket. |
357 } | 382 } |
358 | |
359 /** | |
360 * @param {!WebInspector.TracingModel.Event} e | |
361 */ | |
362 function onEventStart(e) | |
363 { | |
364 var index = categoryIndexStack.length ? categoryIndexStack.peekLast(
) : idleIndex; | |
365 quantizer.appendInterval(e.startTime, index); | |
366 categoryIndexStack.push(WebInspector.TimelineUIUtils.eventStyle(e).c
ategory._overviewIndex || otherIndex); | |
367 } | |
368 | |
369 /** | |
370 * @param {!WebInspector.TracingModel.Event} e | |
371 */ | |
372 function onEventEnd(e) | |
373 { | |
374 quantizer.appendInterval(e.endTime, categoryIndexStack.pop()); | |
375 } | |
376 | |
377 WebInspector.TimelineModel.forEachEvent(events, onEventStart, onEventEnd
); | |
378 quantizer.appendInterval(timeOffset + timeSpan + quantTime, idleIndex);
// Kick drawing the last bucket. | |
379 }, | 383 }, |
380 | 384 |
381 __proto__: WebInspector.TimelineEventOverview.Thread.prototype | 385 __proto__: WebInspector.TimelineEventOverview.prototype |
382 } | 386 } |
383 | 387 |
384 /** | 388 /** |
385 * @constructor | 389 * @constructor |
386 * @extends {WebInspector.TimelineEventOverview} | 390 * @extends {WebInspector.TimelineEventOverview} |
387 * @param {!WebInspector.TimelineModel} model | 391 * @param {!WebInspector.TimelineModel} model |
388 * @param {!WebInspector.TimelineFrameModelBase} frameModel | 392 * @param {!WebInspector.TimelineFrameModelBase} frameModel |
389 */ | 393 */ |
390 WebInspector.TimelineEventOverview.Responsiveness = function(model, frameModel) | 394 WebInspector.TimelineEventOverview.Responsiveness = function(model, frameModel) |
391 { | 395 { |
(...skipping 455 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
847 counters[group] = this._quantDuration; | 851 counters[group] = this._quantDuration; |
848 this._callback(counters); | 852 this._callback(counters); |
849 interval -= this._quantDuration; | 853 interval -= this._quantDuration; |
850 } | 854 } |
851 this._counters = []; | 855 this._counters = []; |
852 this._counters[group] = interval; | 856 this._counters[group] = interval; |
853 this._lastTime = time; | 857 this._lastTime = time; |
854 this._remainder = this._quantDuration - interval; | 858 this._remainder = this._quantDuration - interval; |
855 } | 859 } |
856 } | 860 } |
OLD | NEW |