Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(873)

Side by Side Diff: Source/devtools/front_end/TimelinePowerOverview.js

Issue 220963002: DevTools: Add energy value under Timeline pie chart (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Add to Pie Chart Created 6 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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.Object} 7 * @extends {WebInspector.Object}
8 */ 8 */
9 WebInspector.TimelinePowerOverviewDataProvider = function() 9 WebInspector.TimelinePowerOverviewDataProvider = function()
10 { 10 {
11 this._records = []; 11 this._records = [];
12 this._energies = [];
13 this._times = [];
12 if (Capabilities.canProfilePower) 14 if (Capabilities.canProfilePower)
13 WebInspector.powerProfiler.addEventListener(WebInspector.PowerProfiler.E ventTypes.PowerEventRecorded, this._onRecordAdded, this); 15 WebInspector.powerProfiler.addEventListener(WebInspector.PowerProfiler.E ventTypes.PowerEventRecorded, this._onRecordAdded, this);
14 } 16 }
15 17
16 WebInspector.TimelinePowerOverviewDataProvider.prototype = { 18 WebInspector.TimelinePowerOverviewDataProvider.prototype = {
17 /** 19 /**
18 * @return {!Array.<!PowerAgent.PowerEvent>} 20 * @return {!Array.<!PowerAgent.PowerEvent>}
19 */ 21 */
20 records : function() 22 records : function()
21 { 23 {
22 // The last record is not used, as its "value" is not set. 24 // The last record is not used, as its "value" is not set.
23 return this._records.slice(0, this._records.length - 1); 25 return this._records.slice(0, this._records.length - 1);
24 }, 26 },
25 27
28 /**
29 * @param {number} minTime
30 * @param {number} maxTime
31 */
32 _calculateEnergy : function(minTime, maxTime)
33 {
34 var times = this._times;
35 var energies = this._energies;
36
37 if (times.length < 2)
38 return 0;
39
40 // Maximum index of element whose time <= minTime.
41 var start = minTime >= times[0] ? Number.constrain(times.upperBound(minT ime) - 1, 0, times.length - 1) : 0;
alph 2014/04/09 16:02:27 no need for "minTime >= times[0]" check as constra
Pan 2014/04/10 13:38:57 Done.
42
43 // Minimum index of element whose time >= maxTime.
44 var end = maxTime <= times[times.length - 1] ? Number.constrain(times.lo werBound(maxTime), 0, times.length - 1) : times.length - 1;
alph 2014/04/09 16:02:27 ditto for maxTime <= times[...] check.
Pan 2014/04/10 13:38:57 Done.
45
46 if (start + 1 === end)
alph 2014/04/09 16:02:27 There seems to be another case when start === end,
Pan 2014/04/10 13:38:57 thanks, I'd like to return 0 when window is out of
47 return (maxTime - minTime) / (times[end] - times[start]) * (energies[ end] - energies[start]) / 1000;
alph 2014/04/09 16:02:27 seems to be incorrect if minTime < times[0]. same
Pan 2014/04/10 13:38:57 thanks, if window's range is bigger than times[],
48
49 var totalEnergy = 0;
50 totalEnergy += energies[end - 1] - energies[start + 1];
51 totalEnergy += (times[start + 1] - minTime) / (times[start + 1] - times[ start]) * (energies[start + 1] - energies[start]);
alph 2014/04/09 16:02:27 A case of minTime < times[0] and the same at the o
Pan 2014/04/10 13:38:57 Done.
52 totalEnergy += (maxTime - times[end - 1]) / (times[end] - times[end - 1] ) * (energies[end] - energies[end - 1]);
53 return totalEnergy / 1000;
54 },
55
26 _onRecordAdded: function(event) 56 _onRecordAdded: function(event)
27 { 57 {
28 // "value" of original PowerEvent means the average power between previo us sampling to current one. 58 // "value" of original PowerEvent means the average power between previo us sampling to current one.
29 // Here, it is converted to average power between current sampling to ne xt one. 59 // Here, it is converted to average power between current sampling to ne xt one.
30 var record = event.data; 60 var record = event.data;
61 var curTime = record.timestamp;
31 var length = this._records.length; 62 var length = this._records.length;
32 if (length) 63 var accumulatedEnergy = 0;
64 if (length) {
33 this._records[length - 1].value = record.value; 65 this._records[length - 1].value = record.value;
66
67 var prevTime = this._records[length - 1].timestamp;
68 accumulatedEnergy = this._energies[length - 1];
69 accumulatedEnergy += (curTime - prevTime) * record.value;
70 }
71 this._energies.push(accumulatedEnergy);
34 this._records.push(record); 72 this._records.push(record);
73 this._times.push(curTime);
35 }, 74 },
36 75
37 __proto__: WebInspector.Object.prototype 76 __proto__: WebInspector.Object.prototype
38 } 77 }
39 78
40 /** 79 /**
41 * @constructor 80 * @constructor
42 * @extends {WebInspector.TimelineOverviewBase} 81 * @extends {WebInspector.TimelineOverviewBase}
43 * @param {!WebInspector.TimelineModel} model 82 * @param {!WebInspector.TimelineModel} model
44 */ 83 */
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
138 177
139 ctx.fillStyle = "rgba(255,192,0, 0.8);"; 178 ctx.fillStyle = "rgba(255,192,0, 0.8);";
140 ctx.fill(); 179 ctx.fill();
141 180
142 ctx.lineWidth = 0.5; 181 ctx.lineWidth = 0.5;
143 ctx.strokeStyle = "rgba(20,0,0,0.8)"; 182 ctx.strokeStyle = "rgba(20,0,0,0.8)";
144 ctx.stroke(); 183 ctx.stroke();
145 ctx.restore(); 184 ctx.restore();
146 185
147 this._maxPowerLabel.textContent = WebInspector.UIString("%.2f\u2009watts ", maxPower); 186 this._maxPowerLabel.textContent = WebInspector.UIString("%.2f\u2009watts ", maxPower);
148 this._minPowerLabel.textContent = WebInspector.UIString("%.2f\u2009watts ", minPower);; 187 this._minPowerLabel.textContent = WebInspector.UIString("%.2f\u2009watts ", minPower);
188 },
189
190 /**
191 * @param {number} minTime
192 * @param {number} maxTime
193 */
194 calculateEnergy: function(minTime, maxTime)
195 {
196 return this._dataProvider._calculateEnergy(minTime, maxTime);
149 }, 197 },
150 198
151 __proto__: WebInspector.TimelineOverviewBase.prototype 199 __proto__: WebInspector.TimelineOverviewBase.prototype
152 } 200 }
153 201
154 202
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698