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

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: 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
« no previous file with comments | « Source/devtools/front_end/TimelinePanel.js ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 * @return {number} energy in joules.
32 */
33 _calculateEnergy : function(minTime, maxTime)
34 {
35 var times = this._times;
36 var energies = this._energies;
37 var last = times.length - 1;
38
39 if (last < 1 || minTime >= times[last] || maxTime <= times[0])
40 return 0;
41
42 // Maximum index of element whose time <= minTime.
43 var start = Number.constrain(times.upperBound(minTime) - 1, 0, last);
44
45 // Minimum index of element whose time >= maxTime.
46 var end = Number.constrain(times.lowerBound(maxTime), 0, last);
47
48 var startTime = minTime < times[0] ? times[0] : minTime;
49 var endTime = maxTime > times[last] ? times[last] : maxTime;
50
51 if (start + 1 === end)
52 return (endTime - startTime) / (times[end] - times[start]) * (energie s[end] - energies[start]) / 1000;
53
54 var totalEnergy = 0;
55 totalEnergy += energies[end - 1] - energies[start + 1];
56 totalEnergy += (times[start + 1] - startTime) / (times[start + 1] - time s[start]) * (energies[start + 1] - energies[start]);
57 totalEnergy += (endTime - times[end - 1]) / (times[end] - times[end - 1] ) * (energies[end] - energies[end - 1]);
58 return totalEnergy / 1000;
59 },
60
26 _onRecordAdded: function(event) 61 _onRecordAdded: function(event)
27 { 62 {
28 // "value" of original PowerEvent means the average power between previo us sampling to current one. 63 // "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. 64 // Here, it is converted to average power between current sampling to ne xt one.
30 var record = event.data; 65 var record = event.data;
66 var curTime = record.timestamp;
31 var length = this._records.length; 67 var length = this._records.length;
32 if (length) 68 var accumulatedEnergy = 0;
69 if (length) {
33 this._records[length - 1].value = record.value; 70 this._records[length - 1].value = record.value;
71
72 var prevTime = this._records[length - 1].timestamp;
73 accumulatedEnergy = this._energies[length - 1];
74 accumulatedEnergy += (curTime - prevTime) * record.value;
75 }
76 this._energies.push(accumulatedEnergy);
34 this._records.push(record); 77 this._records.push(record);
78 this._times.push(curTime);
35 }, 79 },
36 80
37 __proto__: WebInspector.Object.prototype 81 __proto__: WebInspector.Object.prototype
38 } 82 }
39 83
40 /** 84 /**
41 * @constructor 85 * @constructor
42 * @extends {WebInspector.TimelineOverviewBase} 86 * @extends {WebInspector.TimelineOverviewBase}
43 * @param {!WebInspector.TimelineModel} model 87 * @param {!WebInspector.TimelineModel} model
44 */ 88 */
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
138 182
139 ctx.fillStyle = "rgba(255,192,0, 0.8);"; 183 ctx.fillStyle = "rgba(255,192,0, 0.8);";
140 ctx.fill(); 184 ctx.fill();
141 185
142 ctx.lineWidth = 0.5; 186 ctx.lineWidth = 0.5;
143 ctx.strokeStyle = "rgba(20,0,0,0.8)"; 187 ctx.strokeStyle = "rgba(20,0,0,0.8)";
144 ctx.stroke(); 188 ctx.stroke();
145 ctx.restore(); 189 ctx.restore();
146 190
147 this._maxPowerLabel.textContent = WebInspector.UIString("%.2f\u2009watts ", maxPower); 191 this._maxPowerLabel.textContent = WebInspector.UIString("%.2f\u2009watts ", maxPower);
148 this._minPowerLabel.textContent = WebInspector.UIString("%.2f\u2009watts ", minPower);; 192 this._minPowerLabel.textContent = WebInspector.UIString("%.2f\u2009watts ", minPower);
193 },
194
195 /**
196 * @param {number} minTime
197 * @param {number} maxTime
198 * @return {number} energy in joules.
199 */
200 calculateEnergy: function(minTime, maxTime)
201 {
202 return this._dataProvider._calculateEnergy(minTime, maxTime);
149 }, 203 },
150 204
151 __proto__: WebInspector.TimelineOverviewBase.prototype 205 __proto__: WebInspector.TimelineOverviewBase.prototype
152 } 206 }
153 207
154 208
OLDNEW
« no previous file with comments | « Source/devtools/front_end/TimelinePanel.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698