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