1 /* 2 * Copyright (C) 2013 Google Inc. All rights reserved. 3 * 4 * Redistribution and use in source and binary forms, with or without 5 * modification, are permitted provided that the following conditions are 6 * met: 7 * 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 13 * distribution. 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. 17 * 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. 29 */ 30 31 /** 32 * @constructor 33 * @extends {WebInspector.CountersGraph} 34 * @implements {WebInspector.TimelineModeView} 35 * @param {!WebInspector.TimelineModeViewDelegate} delegate 36 * @param {!WebInspector.TimelineModel} model 37 * @param {!WebInspector.TimelineUIUtils} uiUtils 38 */ 39 WebInspector.MemoryCountersGraph = function(delegate, model, uiUtils) 40 { 41 WebInspector.CountersGraph.call(this, WebInspector.UIString("MEMORY"), delegate, model); 42 this._uiUtils = uiUtils; 43 this._countersByName = {}; 44 this._countersByName["jsHeapSizeUsed"] = this.createCounter(WebInspector.UIString("Used JS Heap"), WebInspector.UIString("JS Heap Size: %d"), "hsl(220, 90%, 43%)"); 45 this._countersByName["documents"] = this.createCounter(WebInspector.UIString("Documents"), WebInspector.UIString("Documents: %d"), "hsl(0, 90%, 43%)"); 46 this._countersByName["nodes"] = this.createCounter(WebInspector.UIString("Nodes"), WebInspector.UIString("Nodes: %d"), "hsl(120, 90%, 43%)"); 47 this._countersByName["jsEventListeners"] = this.createCounter(WebInspector.UIString("Listeners"), WebInspector.UIString("Listeners: %d"), "hsl(38, 90%, 43%)"); 48 if (Runtime.experiments.isEnabled("gpuTimeline")) { 49 this._gpuMemoryCounter = this.createCounter(WebInspector.UIString("GPU Memory"), WebInspector.UIString("GPU Memory [KB]: %d"), "hsl(300, 90%, 43%)"); 50 this._countersByName["gpuMemoryUsedKB"] = this._gpuMemoryCounter; 51 } 52 } 53 54 WebInspector.MemoryCountersGraph.prototype = { 55 timelineStarted: function() 56 { 57 }, 58 59 timelineStopped: function() 60 { 61 }, 62 63 /** 64 * @param {!WebInspector.TimelineModel.Record} record 65 */ 66 addRecord: function(record) 67 { 68 /** 69 * @param {!WebInspector.TimelineModel.Record} record 70 * @this {!WebInspector.MemoryCountersGraph} 71 */ 72 function addStatistics(record) 73 { 74 var counters = this._uiUtils.countersForRecord(record); 75 if (!counters) 76 return; 77 for (var name in counters) { 78 var counter = this._countersByName[name]; 79 if (counter) 80 counter.appendSample(record.endTime() || record.startTime(), counters[name]); 81 } 82 83 var gpuMemoryLimitCounterName = "gpuMemoryLimitKB"; 84 if (this._gpuMemoryCounter && (gpuMemoryLimitCounterName in counters)) 85 this._gpuMemoryCounter.setLimit(counters[gpuMemoryLimitCounterName]); 86 } 87 WebInspector.TimelineModel.forAllRecords([record], null, addStatistics.bind(this)); 88 this.scheduleRefresh(); 89 }, 90 91 refreshRecords: function() 92 { 93 this.reset(); 94 var records = this._model.records(); 95 for (var i = 0; i < records.length; ++i) 96 this.addRecord(records[i]); 97 }, 98 99 __proto__: WebInspector.CountersGraph.prototype 100 } 101