OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 /** | 5 /** |
6 * @constructor | 6 * @constructor |
7 * @extends {WebInspector.CountersGraph} | 7 * @extends {WebInspector.CountersGraph} |
8 * @implements {WebInspector.TimelineModeView} | 8 * @implements {WebInspector.TimelineModeView} |
9 * @param {!WebInspector.TimelineModeViewDelegate} delegate | 9 * @param {!WebInspector.TimelineModeViewDelegate} delegate |
10 * @param {!WebInspector.TimelineModel} model | 10 * @param {!WebInspector.TimelineModel} model |
11 */ | 11 */ |
12 WebInspector.TimelinePowerGraph = function(delegate, model) | 12 WebInspector.TimelinePowerGraph = function(delegate, model) |
13 { | 13 { |
14 WebInspector.CountersGraph.call(this, delegate, model); | 14 WebInspector.CountersGraph.call(this, delegate, model); |
15 | 15 |
16 this._counter = this.createCounter(WebInspector.UIString("Power"), WebInspec tor.UIString("Power: %.2f\u2009watts"), "#d00"); | 16 var color = "#d00"; |
17 this._energy = this._currentValuesBar.createChild("span", "memory-counter-va lue"); | |
18 this._energy.style.color = color; | |
19 this._counter = this.createCounter(WebInspector.UIString("Power"), WebInspec tor.UIString("Power: %.2f\u2009watts"), color); | |
20 | |
17 WebInspector.powerProfiler.addEventListener(WebInspector.PowerProfiler.Event Types.PowerEventRecorded, this._onRecordAdded, this); | 21 WebInspector.powerProfiler.addEventListener(WebInspector.PowerProfiler.Event Types.PowerEventRecorded, this._onRecordAdded, this); |
18 } | 22 } |
19 | 23 |
20 WebInspector.TimelinePowerGraph.prototype = { | 24 WebInspector.TimelinePowerGraph.prototype = { |
21 _onRecordAdded: function(event) | 25 _onRecordAdded: function(event) |
22 { | 26 { |
23 var record = event.data; | 27 var record = event.data; |
24 if (!this._previousRecord) { | 28 if (!this._previousRecord) { |
25 this._previousRecord = record; | 29 this._previousRecord = record; |
26 return; | 30 return; |
27 } | 31 } |
28 | 32 |
29 // "value" of original PowerEvent means the average power between previo us sampling to current one. | 33 // "value" of original PowerEvent means the average power between previo us sampling to current one. |
30 // Here, it is converted to average power between current sampling to ne xt one. | 34 // Here, it is converted to average power between current sampling to ne xt one. |
31 this._counter.appendSample(this._previousRecord.timestamp, record.value) ; | 35 this._counter.appendSample(this._previousRecord.timestamp, record.value) ; |
32 this._previousRecord = record; | 36 this._previousRecord = record; |
33 this.scheduleRefresh(); | 37 this.scheduleRefresh(); |
34 }, | 38 }, |
35 | 39 |
36 /** | 40 /** |
37 * @param {!WebInspector.TimelineModel.Record} record | 41 * @param {!WebInspector.TimelineModel.Record} record |
38 */ | 42 */ |
39 addRecord: function(record) | 43 addRecord: function(record) |
40 { | 44 { |
41 }, | 45 }, |
42 | 46 |
47 /** | |
48 * @param {!WebInspector.CountersGraph.CounterUI} counterUI | |
49 */ | |
50 _drawGraph: function(counterUI) | |
pfeldman
2014/04/01 14:21:10
You can't override _drawGraph from another file -
| |
51 { | |
52 WebInspector.CountersGraph.prototype._drawGraph.call(this, counterUI); | |
53 var counter = this._counter; | |
54 var values = counter.values; | |
55 | |
56 if (!values.length) | |
57 return; | |
58 | |
59 var energy = 0; | |
60 var start = counter.minimumIndex; | |
61 var end = counter.maximumIndex; | |
62 var times = counter.times; | |
63 | |
64 for (var i = start + 1; i < end - 1; i++) { | |
65 energy += (times[i + 1] - times[i]) * values[i]; | |
66 } | |
67 | |
68 if (start + 1 === end) { | |
69 energy += (counter.maxTime - counter.minTime) * values[start]; | |
70 } else { | |
71 energy += (times[start + 1] - counter.minTime) * values[start]; | |
72 energy += (counter.maxTime - times[end - 1]) * values[end - 1]; | |
73 } | |
74 | |
75 this._energy.textContent = WebInspector.UIString("Energy: %.2f\u2009joul es", energy / 1000); | |
76 }, | |
77 | |
43 __proto__: WebInspector.CountersGraph.prototype | 78 __proto__: WebInspector.CountersGraph.prototype |
44 } | 79 } |
OLD | NEW |