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