| 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 18 matching lines...) Expand all Loading... |
| 29 */ | 29 */ |
| 30 | 30 |
| 31 /** | 31 /** |
| 32 * @constructor | 32 * @constructor |
| 33 * @param {function(string=)} showImageCallback | 33 * @param {function(string=)} showImageCallback |
| 34 * @extends {WebInspector.HBox} | 34 * @extends {WebInspector.HBox} |
| 35 */ | 35 */ |
| 36 WebInspector.PaintProfilerView = function(showImageCallback) | 36 WebInspector.PaintProfilerView = function(showImageCallback) |
| 37 { | 37 { |
| 38 WebInspector.HBox.call(this); | 38 WebInspector.HBox.call(this); |
| 39 this.element.classList.add("paint-profiler-view"); | 39 this.element.classList.add("paint-profiler-overview", "hbox"); |
| 40 this._canvasContainer = this.element.createChild("div", "paint-profiler-canv
as-container"); |
| 41 this._pieChart = new WebInspector.PieChart(55, this._formatPieChartTime.bind
(this)); |
| 42 this.element.createChild("div", "paint-profiler-pie-chart").appendChild(this
._pieChart.element); |
| 40 | 43 |
| 41 this._showImageCallback = showImageCallback; | 44 this._showImageCallback = showImageCallback; |
| 42 | 45 |
| 43 this._canvas = this.element.createChild("canvas", "fill"); | 46 this._canvas = this._canvasContainer.createChild("canvas", "fill"); |
| 44 this._context = this._canvas.getContext("2d"); | 47 this._context = this._canvas.getContext("2d"); |
| 45 this._selectionWindow = new WebInspector.OverviewGrid.Window(this.element, t
his.element); | 48 this._selectionWindow = new WebInspector.OverviewGrid.Window(this._canvasCon
tainer); |
| 46 this._selectionWindow.addEventListener(WebInspector.OverviewGrid.Events.Wind
owChanged, this._onWindowChanged, this); | 49 this._selectionWindow.addEventListener(WebInspector.OverviewGrid.Events.Wind
owChanged, this._onWindowChanged, this); |
| 47 | 50 |
| 48 this._innerBarWidth = 4 * window.devicePixelRatio; | 51 this._innerBarWidth = 4 * window.devicePixelRatio; |
| 49 this._minBarHeight = 4 * window.devicePixelRatio; | 52 this._minBarHeight = window.devicePixelRatio; |
| 50 this._barPaddingWidth = 2 * window.devicePixelRatio; | 53 this._barPaddingWidth = 2 * window.devicePixelRatio; |
| 51 this._outerBarWidth = this._innerBarWidth + this._barPaddingWidth; | 54 this._outerBarWidth = this._innerBarWidth + this._barPaddingWidth; |
| 52 | 55 |
| 53 this._reset(); | 56 this._reset(); |
| 54 } | 57 } |
| 55 | 58 |
| 56 WebInspector.PaintProfilerView.Events = { | 59 WebInspector.PaintProfilerView.Events = { |
| 57 WindowChanged: "WindowChanged" | 60 WindowChanged: "WindowChanged" |
| 58 }; | 61 }; |
| 59 | 62 |
| (...skipping 26 matching lines...) Expand all Loading... |
| 86 */ | 89 */ |
| 87 function onProfileDone(profiles) | 90 function onProfileDone(profiles) |
| 88 { | 91 { |
| 89 this._profiles = profiles; | 92 this._profiles = profiles; |
| 90 this._update(); | 93 this._update(); |
| 91 } | 94 } |
| 92 }, | 95 }, |
| 93 | 96 |
| 94 _update: function() | 97 _update: function() |
| 95 { | 98 { |
| 96 this._canvas.width = this.element.clientWidth * window.devicePixelRatio; | 99 this._canvas.width = this._canvasContainer.clientWidth * window.devicePi
xelRatio; |
| 97 this._canvas.height = this.element.clientHeight * window.devicePixelRati
o; | 100 this._canvas.height = this._canvasContainer.clientHeight * window.device
PixelRatio; |
| 98 this._samplesPerBar = 0; | 101 this._samplesPerBar = 0; |
| 99 if (!this._profiles || !this._profiles.length) | 102 if (!this._profiles || !this._profiles.length) |
| 100 return; | 103 return; |
| 101 | 104 |
| 102 var maxBars = Math.floor((this._canvas.width - 2 * this._barPaddingWidth
) / this._outerBarWidth); | 105 var maxBars = Math.floor((this._canvas.width - 2 * this._barPaddingWidth
) / this._outerBarWidth); |
| 103 var sampleCount = this._log.length; | 106 var sampleCount = this._log.length; |
| 104 this._samplesPerBar = Math.ceil(sampleCount / maxBars); | 107 this._samplesPerBar = Math.ceil(sampleCount / maxBars); |
| 105 var barCount = Math.floor(sampleCount / this._samplesPerBar); | 108 var barCount = Math.floor(sampleCount / this._samplesPerBar); |
| 106 | 109 |
| 107 var maxBarTime = 0; | 110 var maxBarTime = 0; |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 158 continue; | 161 continue; |
| 159 currentHeight += heightByCategory[categoryName]; | 162 currentHeight += heightByCategory[categoryName]; |
| 160 var y = this._canvas.height - currentHeight; | 163 var y = this._canvas.height - currentHeight; |
| 161 this._context.fillStyle = categories[categoryName].color; | 164 this._context.fillStyle = categories[categoryName].color; |
| 162 this._context.fillRect(x, y, this._innerBarWidth, heightByCategory[c
ategoryName]); | 165 this._context.fillRect(x, y, this._innerBarWidth, heightByCategory[c
ategoryName]); |
| 163 } | 166 } |
| 164 }, | 167 }, |
| 165 | 168 |
| 166 _onWindowChanged: function() | 169 _onWindowChanged: function() |
| 167 { | 170 { |
| 171 this.dispatchEventToListeners(WebInspector.PaintProfilerView.Events.Wind
owChanged); |
| 172 |
| 173 // Update pie chart |
| 174 var window = this.windowBoundaries(); |
| 175 var totalTime = 0; |
| 176 var timeByCategory = {}; |
| 177 for (var i = window.left; i <= window.right; ++i) { |
| 178 var logEntry = this._log[i]; |
| 179 var category = WebInspector.PaintProfilerView._categoryForLogItem(lo
gEntry); |
| 180 timeByCategory[category.color] = timeByCategory[category.color] || 0
; |
| 181 for (var j = 0; j < this._profiles.length; ++j) { |
| 182 var time = this._profiles[j][logEntry.commandIndex]; |
| 183 totalTime += time; |
| 184 timeByCategory[category.color] += time; |
| 185 } |
| 186 } |
| 187 this._pieChart.setTotal(totalTime / this._profiles.length); |
| 188 for (var color in timeByCategory) |
| 189 this._pieChart.addSlice(timeByCategory[color] / this._profiles.length,
color); |
| 190 |
| 168 if (this._updateImageTimer) | 191 if (this._updateImageTimer) |
| 169 return; | 192 return; |
| 170 this._updateImageTimer = setTimeout(this._updateImage.bind(this), 100); | 193 this._updateImageTimer = setTimeout(this._updateImage.bind(this), 100); |
| 171 this.dispatchEventToListeners(WebInspector.PaintProfilerView.Events.Wind
owChanged); | |
| 172 }, | 194 }, |
| 173 | 195 |
| 174 /** | 196 /** |
| 197 * @param {number} value |
| 198 * @return {string} |
| 199 */ |
| 200 _formatPieChartTime: function(value) |
| 201 { |
| 202 return Number.millisToString(value * 1000, true); |
| 203 }, |
| 204 |
| 205 /** |
| 175 * @return {{left: number, right: number}} | 206 * @return {{left: number, right: number}} |
| 176 */ | 207 */ |
| 177 windowBoundaries: function() | 208 windowBoundaries: function() |
| 178 { | 209 { |
| 179 var screenLeft = this._selectionWindow.windowLeft * this._canvas.width; | 210 var screenLeft = this._selectionWindow.windowLeft * this._canvas.width; |
| 180 var screenRight = this._selectionWindow.windowRight * this._canvas.width
; | 211 var screenRight = this._selectionWindow.windowRight * this._canvas.width
; |
| 181 var barLeft = Math.floor((screenLeft - this._barPaddingWidth) / this._ou
terBarWidth); | 212 var barLeft = Math.floor((screenLeft - this._barPaddingWidth) / this._ou
terBarWidth); |
| 182 var barRight = Math.floor((screenRight - this._barPaddingWidth + this._i
nnerBarWidth)/ this._outerBarWidth); | 213 var barRight = Math.floor((screenRight - this._barPaddingWidth + this._i
nnerBarWidth)/ this._outerBarWidth); |
| 183 var stepLeft = Math.max(0, barLeft * this._samplesPerBar); | 214 var stepLeft = Number.constrain(barLeft * this._samplesPerBar, 0, this._
log.length - 1); |
| 184 var stepRight = Math.min(barRight * this._samplesPerBar, this._log.lengt
h - 1); | 215 var stepRight = Number.constrain(barRight * this._samplesPerBar, 0, this
._log.length - 1); |
| 185 | 216 |
| 186 return {left: stepLeft, right: stepRight}; | 217 return { left: stepLeft, right: stepRight }; |
| 187 }, | 218 }, |
| 188 | 219 |
| 189 _updateImage: function() | 220 _updateImage: function() |
| 190 { | 221 { |
| 191 delete this._updateImageTimer; | 222 delete this._updateImageTimer; |
| 192 if (!this._profiles || !this._profiles.length) | 223 if (!this._profiles || !this._profiles.length) |
| 193 return; | 224 return; |
| 194 | 225 |
| 195 var window = this.windowBoundaries(); | 226 var window = this.windowBoundaries(); |
| 196 this._snapshot.requestImage(this._log[window.left].commandIndex, this._l
og[window.right].commandIndex, 1, this._showImageCallback); | 227 this._snapshot.requestImage(this._log[window.left].commandIndex, this._l
og[window.right].commandIndex, 1, this._showImageCallback); |
| (...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 414 }; | 445 }; |
| 415 | 446 |
| 416 /** | 447 /** |
| 417 * @return {!Object.<string, !WebInspector.PaintProfilerCategory>} | 448 * @return {!Object.<string, !WebInspector.PaintProfilerCategory>} |
| 418 */ | 449 */ |
| 419 WebInspector.PaintProfilerView.categories = function() | 450 WebInspector.PaintProfilerView.categories = function() |
| 420 { | 451 { |
| 421 if (WebInspector.PaintProfilerView._categories) | 452 if (WebInspector.PaintProfilerView._categories) |
| 422 return WebInspector.PaintProfilerView._categories; | 453 return WebInspector.PaintProfilerView._categories; |
| 423 WebInspector.PaintProfilerView._categories = { | 454 WebInspector.PaintProfilerView._categories = { |
| 424 shapes: new WebInspector.PaintProfilerCategory("shapes", WebInspector.UI
String("Shapes"), "rgba(255, 0, 0, 0.7)"), | 455 shapes: new WebInspector.PaintProfilerCategory("shapes", WebInspector.UI
String("Shapes"), "rgb(255, 161, 129)"), |
| 425 bitmap: new WebInspector.PaintProfilerCategory("bitmap", WebInspector.UI
String("Bitmap"), "rgba(0, 255, 0, 0.7)"), | 456 bitmap: new WebInspector.PaintProfilerCategory("bitmap", WebInspector.UI
String("Bitmap"), "rgb(136, 196, 255)"), |
| 426 text: new WebInspector.PaintProfilerCategory("text", WebInspector.UIStri
ng("Text"), "rgba(0, 0, 255, 0.7)"), | 457 text: new WebInspector.PaintProfilerCategory("text", WebInspector.UIStri
ng("Text"), "rgb(180, 255, 137)"), |
| 427 misc: new WebInspector.PaintProfilerCategory("misc", WebInspector.UIStri
ng("Misc"), "rgba(100, 0, 100, 0.7)") | 458 misc: new WebInspector.PaintProfilerCategory("misc", WebInspector.UIStri
ng("Misc"), "rgb(206, 160, 255)") |
| 428 }; | 459 }; |
| 429 return WebInspector.PaintProfilerView._categories; | 460 return WebInspector.PaintProfilerView._categories; |
| 430 }; | 461 }; |
| 431 | 462 |
| 432 /** | 463 /** |
| 433 * @constructor | 464 * @constructor |
| 434 * @param {string} name | 465 * @param {string} name |
| 435 * @param {string} title | 466 * @param {string} title |
| 436 * @param {string} color | 467 * @param {string} color |
| 437 */ | 468 */ |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 503 var method = logItem.method.toTitleCase(); | 534 var method = logItem.method.toTitleCase(); |
| 504 | 535 |
| 505 var logItemCategories = WebInspector.PaintProfilerView._initLogItemCategorie
s(); | 536 var logItemCategories = WebInspector.PaintProfilerView._initLogItemCategorie
s(); |
| 506 var result = logItemCategories[method]; | 537 var result = logItemCategories[method]; |
| 507 if (!result) { | 538 if (!result) { |
| 508 result = WebInspector.PaintProfilerView.categories()["misc"]; | 539 result = WebInspector.PaintProfilerView.categories()["misc"]; |
| 509 logItemCategories[method] = result; | 540 logItemCategories[method] = result; |
| 510 } | 541 } |
| 511 return result; | 542 return result; |
| 512 } | 543 } |
| OLD | NEW |