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"); | |
alph
2014/04/02 08:19:57
You probably want to hide this guy when the power
| |
18 this._energy.style.color = color; | |
19 this._counter = this.createCounter(WebInspector.UIString("Power"), WebInspec tor.UIString("Power: %.2f\u2009watts"), color); | |
alph
2014/04/02 08:19:57
Will it be clear to the user that this value repre
Pan
2014/04/03 13:58:39
I think Energy:xxJoules, Power:xxWatts, is ok.
or
alph
2014/04/03 14:08:16
Showing energy on the values bar seems inconsisten
| |
20 this._calculator = new WebInspector.TimelineCalculator(model); | |
21 | |
22 this._times = []; | |
alph
2014/04/02 08:19:57
there's no real need for this array.
| |
23 this._energies = []; | |
24 | |
17 WebInspector.powerProfiler.addEventListener(WebInspector.PowerProfiler.Event Types.PowerEventRecorded, this._onRecordAdded, this); | 25 WebInspector.powerProfiler.addEventListener(WebInspector.PowerProfiler.Event Types.PowerEventRecorded, this._onRecordAdded, this); |
18 } | 26 } |
19 | 27 |
20 WebInspector.TimelinePowerGraph.prototype = { | 28 WebInspector.TimelinePowerGraph.prototype = { |
21 _onRecordAdded: function(event) | 29 _onRecordAdded: function(event) |
22 { | 30 { |
23 var record = event.data; | 31 var record = event.data; |
24 if (!this._previousRecord) { | 32 if (!this._previousRecord) { |
25 this._previousRecord = record; | 33 this._previousRecord = record; |
26 return; | 34 return; |
27 } | 35 } |
28 | 36 |
29 // "value" of original PowerEvent means the average power between previo us sampling to current one. | 37 // "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. | 38 // Here, it is converted to average power between current sampling to ne xt one. |
31 this._counter.appendSample(this._previousRecord.timestamp, record.value) ; | 39 var previousTime = this._previousRecord.timestamp; |
40 this._counter.appendSample(previousTime, record.value); | |
41 | |
42 this._times.push(previousTime); | |
43 this._energies.push((record.timestamp - previousTime) * record.value); | |
alph
2014/04/02 08:19:57
If you store integral values of energy here, you d
| |
44 | |
32 this._previousRecord = record; | 45 this._previousRecord = record; |
33 this.scheduleRefresh(); | 46 this.scheduleRefresh(); |
34 }, | 47 }, |
35 | 48 |
36 /** | 49 /** |
37 * @param {!WebInspector.TimelineModel.Record} record | 50 * @param {!WebInspector.TimelineModel.Record} record |
38 */ | 51 */ |
39 addRecord: function(record) | 52 addRecord: function(record) |
40 { | 53 { |
41 }, | 54 }, |
42 | 55 |
56 graphDrawn: function() | |
57 { | |
58 var times = this._times; | |
59 | |
60 if (!times.length) | |
61 return; | |
62 | |
63 var minTime = this._calculator.minimumBoundary(); | |
64 var maxTime = this._calculator.maximumBoundary(); | |
65 | |
66 | |
67 // Maximum index of element whose time <= minTime. | |
68 var start = Number.constrain(times.upperBound(minTime) - 1, 0, times.len gth - 1); | |
69 | |
70 // Minimum index of element whose time >= maxTime. | |
71 var end = Number.constrain(times.lowerBound(maxTime), 0, times.length - 1); | |
72 var totalEnergy = 0; | |
73 var energies = this._energies; | |
74 | |
75 for (var i = start + 1; i < end - 1; i++) { | |
alph
2014/04/02 08:19:57
style: drop {}
| |
76 totalEnergy += energies[i]; | |
77 } | |
78 | |
79 if (start + 1 === end) { | |
80 totalEnergy += (maxTime - minTime) / (times[end] - times[start]) * en ergies[start]; | |
81 } else { | |
alph
2014/04/02 08:19:57
There are not handled corner cases, e.g.:
minTime
| |
82 totalEnergy += (times[start + 1] - minTime) / (times[start + 1] - tim es[start]) * energies[start]; | |
83 totalEnergy += (maxTime - times[end - 1]) / (times[end] - times[end - 1]) * energies[end - 1]; | |
84 } | |
85 | |
86 this._energy.textContent = WebInspector.UIString("Energy: %.2f\u2009joul es", totalEnergy / 1000); | |
alph
2014/04/02 08:19:57
How about changing it to "Energy [J]: %.2f" ?
| |
87 }, | |
88 | |
43 __proto__: WebInspector.CountersGraph.prototype | 89 __proto__: WebInspector.CountersGraph.prototype |
44 } | 90 } |
OLD | NEW |