2 * Copyright (C) 2013 Google Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above
11 * copyright notice, this list of conditions and the following disclaimer
12 * in the documentation and/or other materials provided with the
14 * * Neither the name of Google Inc. nor the names of its
15 * contributors may be used to endorse or promote products derived from
16 * this software without specific prior written permission.
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
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.
33 * @extends {WebInspector.TimelineOverviewBase}
34 * @param {!WebInspector.TimelineModel} model
36 WebInspector.TimelineMemoryOverview = function(model)
38 WebInspector.TimelineOverviewBase.call(this, model);
39 this.element.id = "timeline-overview-memory";
41 this._maxHeapSizeLabel = this.element.createChild("div", "max memory-graph-label");
42 this._minHeapSizeLabel = this.element.createChild("div", "min memory-graph-label");
45 WebInspector.TimelineMemoryOverview.prototype = {
46 resetHeapSizeLabels: function()
48 this._maxHeapSizeLabel.textContent = "";
49 this._minHeapSizeLabel.textContent = "";
56 var records = this._model.records;
57 if (!records.length) {
58 this.resetHeapSizeLabels();
62 const lowerOffset = 3;
63 var maxUsedHeapSize = 0;
64 var minUsedHeapSize = 100000000000;
65 var minTime = this._model.minimumRecordTime();
66 var maxTime = this._model.maximumRecordTime();
67 WebInspector.TimelinePresentationModel.forAllRecords(records, function(r) {
68 if (!r.counters || !r.counters.jsHeapSizeUsed)
70 maxUsedHeapSize = Math.max(maxUsedHeapSize, r.counters.jsHeapSizeUsed);
71 minUsedHeapSize = Math.min(minUsedHeapSize, r.counters.jsHeapSizeUsed);
73 minUsedHeapSize = Math.min(minUsedHeapSize, maxUsedHeapSize);
75 var width = this._canvas.width;
76 var height = this._canvas.height - lowerOffset;
77 var xFactor = width / (maxTime - minTime);
78 var yFactor = height / Math.max(maxUsedHeapSize - minUsedHeapSize, 1);
80 var histogram = new Array(width);
81 WebInspector.TimelinePresentationModel.forAllRecords(records, function(r) {
82 if (!r.counters || !r.counters.jsHeapSizeUsed)
84 var x = Math.round((WebInspector.TimelineModel.endTimeInSeconds(r) - minTime) * xFactor);
85 var y = (r.counters.jsHeapSizeUsed - minUsedHeapSize) * yFactor;
86 histogram[x] = Math.max(histogram[x] || 0, y);
90 var isFirstPoint = true;
91 var ctx = this._context;
93 ctx.translate(0.5, 0.5);
95 ctx.moveTo(-1, this._canvas.height);
96 for (var x = 0; x < histogram.length; x++) {
97 if (typeof histogram[x] === "undefined")
100 isFirstPoint = false;
102 ctx.lineTo(-1, height - y);
104 ctx.lineTo(x, height - y);
106 ctx.lineTo(x, height - y);
108 ctx.lineTo(width, height - y);
109 ctx.lineTo(width, this._canvas.height);
110 ctx.lineTo(-1, this._canvas.height);
113 var gradient = ctx.createLinearGradient(0, 0, 0, height);
114 gradient.addColorStop(0, "rgba(192,204,255,1)");
115 gradient.addColorStop(1, "rgba(192,204,255,0.4)");
116 ctx.fillStyle = gradient;
120 ctx.strokeStyle = "#666";
124 this._maxHeapSizeLabel.textContent = Number.bytesToString(maxUsedHeapSize);
125 this._minHeapSizeLabel.textContent = Number.bytesToString(minUsedHeapSize);
128 __proto__: WebInspector.TimelineOverviewBase.prototype