| 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 14 matching lines...) Expand all Loading... |
| 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 /** | 31 /** |
| 32 * @constructor | 32 * @constructor |
| 33 * @extends {WebInspector.TimelineOverviewBase} | 33 * @extends {WebInspector.TimelineOverviewBase} |
| 34 * @param {!WebInspector.TimelineModel} model | 34 * @param {!WebInspector.TimelineModel} model |
| 35 * @param {!WebInspector.TimelineUIUtils} uiUtils | |
| 36 */ | 35 */ |
| 37 WebInspector.TimelineMemoryOverview = function(model, uiUtils) | 36 WebInspector.TimelineMemoryOverview = function(model) |
| 38 { | 37 { |
| 39 WebInspector.TimelineOverviewBase.call(this, model); | 38 WebInspector.TimelineOverviewBase.call(this, model); |
| 40 this._uiUtils = uiUtils; | |
| 41 this.element.id = "timeline-overview-memory"; | 39 this.element.id = "timeline-overview-memory"; |
| 42 | 40 |
| 43 this._heapSizeLabel = this.element.createChild("div", "memory-graph-label"); | 41 this._heapSizeLabel = this.element.createChild("div", "memory-graph-label"); |
| 44 } | 42 } |
| 45 | 43 |
| 46 WebInspector.TimelineMemoryOverview.prototype = { | 44 WebInspector.TimelineMemoryOverview.prototype = { |
| 47 resetHeapSizeLabels: function() | 45 resetHeapSizeLabels: function() |
| 48 { | 46 { |
| 49 this._heapSizeLabel.textContent = ""; | 47 this._heapSizeLabel.textContent = ""; |
| 50 }, | 48 }, |
| 51 | 49 |
| 52 update: function() | 50 update: function() |
| 53 { | 51 { |
| 54 this.resetCanvas(); | 52 this.resetCanvas(); |
| 55 var ratio = window.devicePixelRatio; | 53 var ratio = window.devicePixelRatio; |
| 56 | 54 |
| 57 var records = this._model.records(); | 55 var records = this._model.records(); |
| 58 if (!records.length) { | 56 if (!records.length) { |
| 59 this.resetHeapSizeLabels(); | 57 this.resetHeapSizeLabels(); |
| 60 return; | 58 return; |
| 61 } | 59 } |
| 62 | 60 |
| 63 var lowerOffset = 3 * ratio; | 61 var lowerOffset = 3 * ratio; |
| 64 var maxUsedHeapSize = 0; | 62 var maxUsedHeapSize = 0; |
| 65 var minUsedHeapSize = 100000000000; | 63 var minUsedHeapSize = 100000000000; |
| 66 var minTime = this._model.minimumRecordTime(); | 64 var minTime = this._model.minimumRecordTime(); |
| 67 var maxTime = this._model.maximumRecordTime(); | 65 var maxTime = this._model.maximumRecordTime(); |
| 68 var uiUtils = this._uiUtils; | |
| 69 /** | 66 /** |
| 70 * @param {!WebInspector.TimelineModel.Record} record | 67 * @param {!WebInspector.TimelineModel.Record} record |
| 71 */ | 68 */ |
| 72 function calculateMinMaxSizes(record) | 69 function calculateMinMaxSizes(record) |
| 73 { | 70 { |
| 74 var counters = uiUtils.countersForRecord(record); | 71 var counters = WebInspector.TimelineUIUtils.isCoalescable.countersFo
rRecord(record); |
| 75 if (!counters || !counters.jsHeapSizeUsed) | 72 if (!counters || !counters.jsHeapSizeUsed) |
| 76 return; | 73 return; |
| 77 maxUsedHeapSize = Math.max(maxUsedHeapSize, counters.jsHeapSizeUsed)
; | 74 maxUsedHeapSize = Math.max(maxUsedHeapSize, counters.jsHeapSizeUsed)
; |
| 78 minUsedHeapSize = Math.min(minUsedHeapSize, counters.jsHeapSizeUsed)
; | 75 minUsedHeapSize = Math.min(minUsedHeapSize, counters.jsHeapSizeUsed)
; |
| 79 } | 76 } |
| 80 this._model.forAllRecords(calculateMinMaxSizes); | 77 this._model.forAllRecords(calculateMinMaxSizes); |
| 81 minUsedHeapSize = Math.min(minUsedHeapSize, maxUsedHeapSize); | 78 minUsedHeapSize = Math.min(minUsedHeapSize, maxUsedHeapSize); |
| 82 | 79 |
| 83 var lineWidth = 1; | 80 var lineWidth = 1; |
| 84 var width = this._canvas.width; | 81 var width = this._canvas.width; |
| 85 var height = this._canvas.height - lowerOffset; | 82 var height = this._canvas.height - lowerOffset; |
| 86 var xFactor = width / (maxTime - minTime); | 83 var xFactor = width / (maxTime - minTime); |
| 87 var yFactor = (height - lineWidth) / Math.max(maxUsedHeapSize - minUsedH
eapSize, 1); | 84 var yFactor = (height - lineWidth) / Math.max(maxUsedHeapSize - minUsedH
eapSize, 1); |
| 88 | 85 |
| 89 var histogram = new Array(width); | 86 var histogram = new Array(width); |
| 90 | 87 |
| 91 /** | 88 /** |
| 92 * @param {!WebInspector.TimelineModel.Record} record | 89 * @param {!WebInspector.TimelineModel.Record} record |
| 93 */ | 90 */ |
| 94 function buildHistogram(record) | 91 function buildHistogram(record) |
| 95 { | 92 { |
| 96 var counters = uiUtils.countersForRecord(record); | 93 var counters = WebInspector.TimelineUIUtils.isCoalescable.countersFo
rRecord(record); |
| 97 if (!counters || !counters.jsHeapSizeUsed) | 94 if (!counters || !counters.jsHeapSizeUsed) |
| 98 return; | 95 return; |
| 99 var x = Math.round((record.endTime() - minTime) * xFactor); | 96 var x = Math.round((record.endTime() - minTime) * xFactor); |
| 100 var y = Math.round((counters.jsHeapSizeUsed - minUsedHeapSize) * yFa
ctor); | 97 var y = Math.round((counters.jsHeapSizeUsed - minUsedHeapSize) * yFa
ctor); |
| 101 histogram[x] = Math.max(histogram[x] || 0, y); | 98 histogram[x] = Math.max(histogram[x] || 0, y); |
| 102 } | 99 } |
| 103 this._model.forAllRecords(buildHistogram); | 100 this._model.forAllRecords(buildHistogram); |
| 104 | 101 |
| 105 var ctx = this._context; | 102 var ctx = this._context; |
| 106 var heightBeyondView = height + lowerOffset + lineWidth; | 103 var heightBeyondView = height + lowerOffset + lineWidth; |
| (...skipping 27 matching lines...) Expand all Loading... |
| 134 ctx.fill(); | 131 ctx.fill(); |
| 135 ctx.lineWidth = lineWidth; | 132 ctx.lineWidth = lineWidth; |
| 136 ctx.strokeStyle = "hsl(220, 90%, 70%)"; | 133 ctx.strokeStyle = "hsl(220, 90%, 70%)"; |
| 137 ctx.stroke(); | 134 ctx.stroke(); |
| 138 | 135 |
| 139 this._heapSizeLabel.textContent = WebInspector.UIString("%s \u2013 %s",
Number.bytesToString(minUsedHeapSize), Number.bytesToString(maxUsedHeapSize)); | 136 this._heapSizeLabel.textContent = WebInspector.UIString("%s \u2013 %s",
Number.bytesToString(minUsedHeapSize), Number.bytesToString(maxUsedHeapSize)); |
| 140 }, | 137 }, |
| 141 | 138 |
| 142 __proto__: WebInspector.TimelineOverviewBase.prototype | 139 __proto__: WebInspector.TimelineOverviewBase.prototype |
| 143 } | 140 } |
| OLD | NEW |