1 // Copyright 2014 The Chromium Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 /** 6 * @constructor 7 * @extends {WebInspector.CountersGraph} 8 * @implements {WebInspector.TimelineModeView} 9 * @param {!WebInspector.TimelineModeViewDelegate} delegate 10 * @param {!WebInspector.TimelineModel} model 11 */ 12 WebInspector.TimelinePowerGraph = function(delegate, model) 13 { 14 WebInspector.CountersGraph.call(this, WebInspector.UIString("POWER"), delegate, model); 15 16 this._counter = this.createCounter(WebInspector.UIString("Power"), WebInspector.UIString("Power: %.2f\u2009watts"), "#d00"); 17 WebInspector.powerProfiler.addEventListener(WebInspector.PowerProfiler.EventTypes.PowerEventRecorded, this._onRecordAdded, this); 18 } 19 20 WebInspector.TimelinePowerGraph.prototype = { 21 dispose: function() 22 { 23 WebInspector.CountersGraph.prototype.dispose.call(this); 24 WebInspector.powerProfiler.removeEventListener(WebInspector.PowerProfiler.EventTypes.PowerEventRecorded, this._onRecordAdded, this); 25 }, 26 27 _onRecordAdded: function(event) 28 { 29 var record = event.data; 30 if (!this._previousRecord) { 31 this._previousRecord = record; 32 return; 33 } 34 35 // "value" of original PowerEvent means the average power between previous sampling to current one. 36 // Here, it is converted to average power between current sampling to next one. 37 this._counter.appendSample(this._previousRecord.timestamp, record.value); 38 this._previousRecord = record; 39 this.scheduleRefresh(); 40 }, 41 42 /** 43 * @param {!WebInspector.TimelineModel.Record} record 44 */ 45 addRecord: function(record) 46 { 47 }, 48 49 __proto__: WebInspector.CountersGraph.prototype 50 } 51