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 * @param {?WebInspector.Target} target |
8 */ | 9 */ |
9 WebInspector.TimelinePowerOverviewDataProvider = function() | 10 WebInspector.TimelinePowerOverviewDataProvider = function(target) |
10 { | 11 { |
11 this._records = []; | 12 this._records = []; |
12 this._energies = []; | 13 this._energies = []; |
13 this._times = []; | 14 this._times = []; |
14 WebInspector.powerProfiler.addEventListener(WebInspector.PowerProfiler.Event
Types.PowerEventRecorded, this._onRecordAdded, this); | 15 this._target = target; |
| 16 if (this._target) |
| 17 this._target.powerProfiler.addEventListener(WebInspector.PowerProfiler.E
ventTypes.PowerEventRecorded, this._onRecordAdded, this); |
15 } | 18 } |
16 | 19 |
17 WebInspector.TimelinePowerOverviewDataProvider.prototype = { | 20 WebInspector.TimelinePowerOverviewDataProvider.prototype = { |
18 dispose: function() | 21 dispose: function() |
19 { | 22 { |
20 WebInspector.powerProfiler.removeEventListener(WebInspector.PowerProfile
r.EventTypes.PowerEventRecorded, this._onRecordAdded, this); | 23 if (this._target) |
| 24 this._target.powerProfiler.removeEventListener(WebInspector.PowerPro
filer.EventTypes.PowerEventRecorded, this._onRecordAdded, this); |
21 }, | 25 }, |
22 | 26 |
23 /** | 27 /** |
24 * @return {!Array.<!PowerAgent.PowerEvent>} | 28 * @return {!Array.<!PowerAgent.PowerEvent>} |
25 */ | 29 */ |
26 records : function() | 30 records : function() |
27 { | 31 { |
28 // The last record is not used, as its "value" is not set. | 32 // The last record is not used, as its "value" is not set. |
29 return this._records.slice(0, this._records.length - 1); | 33 return this._records.slice(0, this._records.length - 1); |
30 }, | 34 }, |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
86 } | 90 } |
87 | 91 |
88 /** | 92 /** |
89 * @constructor | 93 * @constructor |
90 * @extends {WebInspector.TimelineOverviewBase} | 94 * @extends {WebInspector.TimelineOverviewBase} |
91 * @param {!WebInspector.TimelineModel} model | 95 * @param {!WebInspector.TimelineModel} model |
92 */ | 96 */ |
93 WebInspector.TimelinePowerOverview = function(model) | 97 WebInspector.TimelinePowerOverview = function(model) |
94 { | 98 { |
95 WebInspector.TimelineOverviewBase.call(this, model); | 99 WebInspector.TimelineOverviewBase.call(this, model); |
| 100 |
| 101 // FIXME: Figure out optional targets in timeline. |
| 102 this._target = model.target(); |
96 this.element.id = "timeline-overview-power"; | 103 this.element.id = "timeline-overview-power"; |
97 this._dataProvider = new WebInspector.TimelinePowerOverviewDataProvider(); | 104 this._dataProvider = new WebInspector.TimelinePowerOverviewDataProvider(this
._target); |
98 | 105 |
99 this._maxPowerLabel = this.element.createChild("div", "max memory-graph-labe
l"); | 106 this._maxPowerLabel = this.element.createChild("div", "max memory-graph-labe
l"); |
100 this._minPowerLabel = this.element.createChild("div", "min memory-graph-labe
l"); | 107 this._minPowerLabel = this.element.createChild("div", "min memory-graph-labe
l"); |
101 } | 108 } |
102 | 109 |
103 WebInspector.TimelinePowerOverview.prototype = { | 110 WebInspector.TimelinePowerOverview.prototype = { |
104 /** | 111 /** |
105 * @override | 112 * @override |
106 */ | 113 */ |
107 dispose: function() | 114 dispose: function() |
108 { | 115 { |
109 this._dataProvider.dispose(); | 116 this._dataProvider.dispose(); |
110 }, | 117 }, |
111 | 118 |
112 timelineStarted: function() | 119 timelineStarted: function() |
113 { | 120 { |
114 if (WebInspector.targetManager.mainTarget().hasCapability(WebInspector.T
arget.Capabilities.CanProfilePower)) | 121 if (this._target && this._target.hasCapability(WebInspector.Target.Capab
ilities.CanProfilePower)) |
115 WebInspector.powerProfiler.startProfile(); | 122 this._target.powerProfiler.startProfile(); |
116 }, | 123 }, |
117 | 124 |
118 timelineStopped: function() | 125 timelineStopped: function() |
119 { | 126 { |
120 if (WebInspector.targetManager.mainTarget().hasCapability(WebInspector.T
arget.Capabilities.CanProfilePower)) | 127 if (this._target && this._target.hasCapability(WebInspector.Target.Capab
ilities.CanProfilePower)) |
121 WebInspector.powerProfiler.stopProfile(); | 128 this._target.powerProfiler.stopProfile(); |
122 }, | 129 }, |
123 | 130 |
124 _resetPowerLabels: function() | 131 _resetPowerLabels: function() |
125 { | 132 { |
126 this._maxPowerLabel.textContent = ""; | 133 this._maxPowerLabel.textContent = ""; |
127 this._minPowerLabel.textContent = ""; | 134 this._minPowerLabel.textContent = ""; |
128 }, | 135 }, |
129 | 136 |
130 /** | 137 /** |
131 * @override | 138 * @override |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
210 /** | 217 /** |
211 * @param {number} minTime | 218 * @param {number} minTime |
212 * @param {number} maxTime | 219 * @param {number} maxTime |
213 * @return {number} energy in joules. | 220 * @return {number} energy in joules. |
214 */ | 221 */ |
215 calculateEnergy: function(minTime, maxTime) | 222 calculateEnergy: function(minTime, maxTime) |
216 { | 223 { |
217 return this._dataProvider._calculateEnergy(minTime, maxTime); | 224 return this._dataProvider._calculateEnergy(minTime, maxTime); |
218 }, | 225 }, |
219 | 226 |
| 227 /** |
| 228 * @return {string} |
| 229 */ |
| 230 accuracyLevel: function() |
| 231 { |
| 232 return this._target ? this._target.powerProfiler.accuracyLevel() : ""; |
| 233 }, |
| 234 |
220 __proto__: WebInspector.TimelineOverviewBase.prototype | 235 __proto__: WebInspector.TimelineOverviewBase.prototype |
221 } | 236 } |
OLD | NEW |