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 import time | 5 import time |
6 | 6 |
7 from metrics import Metric | 7 from metrics import Metric |
8 from telemetry.core.platform import process_statistic_timeline_data | 8 from telemetry.core.platform import process_statistic_timeline_data |
9 from telemetry.value import scalar | 9 from telemetry.value import scalar |
10 | 10 |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
62 | 62 |
63 self._platform.StartMonitoringPower(self._browser) | 63 self._platform.StartMonitoringPower(self._browser) |
64 time.sleep(measurement_time_s) | 64 time.sleep(measurement_time_s) |
65 power_results = self._platform.StopMonitoringPower() | 65 power_results = self._platform.StopMonitoringPower() |
66 PowerMetric._quiescent_power_draw_mwh = ( | 66 PowerMetric._quiescent_power_draw_mwh = ( |
67 power_results.get('energy_consumption_mwh', 0)) | 67 power_results.get('energy_consumption_mwh', 0)) |
68 | 68 |
69 def Start(self, _, tab): | 69 def Start(self, _, tab): |
70 self._browser = tab.browser | 70 self._browser = tab.browser |
71 | 71 |
72 if self._platform.CanMeasureIdleWakeUps(): | |
73 self._platform.StartMeasuringIdleWakeUps() | |
74 | |
72 if not self._platform.CanMonitorPower(): | 75 if not self._platform.CanMonitorPower(): |
73 return | 76 return |
74 | 77 |
75 self._results = None | 78 self._results = None |
76 self._StopInternal() | 79 self._StopInternal() |
77 | 80 |
78 # This line invokes top a few times, call before starting power measurement. | 81 # This line invokes top a few times, call before starting power measurement. |
79 self._starting_cpu_stats = self._browser.cpu_stats | 82 self._starting_cpu_stats = self._browser.cpu_stats |
80 self._platform.StartMonitoringPower(self._browser) | 83 self._platform.StartMonitoringPower(self._browser) |
81 self._running = True | 84 self._running = True |
82 | 85 |
83 def Stop(self, _, tab): | 86 def Stop(self, _, tab): |
87 if self._platform.CanMeasureIdleWakeUps(): | |
88 self._platform.StopMeasuringIdleWakeUps() | |
89 | |
84 if not self._platform.CanMonitorPower(): | 90 if not self._platform.CanMonitorPower(): |
85 return | 91 return |
86 | 92 |
87 self._StopInternal() | 93 self._StopInternal() |
88 | 94 |
89 def AddResults(self, _, results): | 95 def AddResults(self, _, results): |
90 """Add the collected power data into the results object. | 96 """Add the collected power data into the results object. |
91 | 97 |
92 This function needs to be robust in the face of differing power data on | 98 This function needs to be robust in the face of differing power data on |
93 various platforms. Therefore data existence needs to be checked when | 99 various platforms. Therefore data existence needs to be checked when |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
157 cstate_percent = whole_package_utilization.get('cstate_residency_percent') | 163 cstate_percent = whole_package_utilization.get('cstate_residency_percent') |
158 if cstate_percent is not None: | 164 if cstate_percent is not None: |
159 for state, percent in cstate_percent.iteritems(): | 165 for state, percent in cstate_percent.iteritems(): |
160 results.AddValue(scalar.ScalarValue( | 166 results.AddValue(scalar.ScalarValue( |
161 results.current_page, 'cpu_cstate_%s_residency_percent' % state, | 167 results.current_page, 'cpu_cstate_%s_residency_percent' % state, |
162 '%', percent, important=False)) | 168 '%', percent, important=False)) |
163 | 169 |
164 self._results = None | 170 self._results = None |
165 | 171 |
166 def _SubtractCpuStats(cpu_stats, start_cpu_stats): | 172 def _SubtractCpuStats(cpu_stats, start_cpu_stats): |
167 """Computes number of idle wakeups that occurred over measurement period. | 173 """Computes number of idle wakeups that occurred over measurement period. |
jdduke (slow)
2015/07/09 21:00:19
Hmm, the way /proc/timer_stats collection works I'
| |
168 | 174 |
169 Each of the two cpu_stats arguments is a dict as returned by the | 175 Each of the two cpu_stats arguments is a dict as returned by the |
170 Browser.cpu_stats call. | 176 Browser.cpu_stats call. |
171 | 177 |
172 Returns: | 178 Returns: |
173 A dict of process type names (Browser, Renderer, etc.) to idle wakeup count | 179 A dict of process type names (Browser, Renderer, etc.) to idle wakeup count |
174 over the period recorded by the input. | 180 over the period recorded by the input. |
175 """ | 181 """ |
176 cpu_delta = {} | 182 cpu_delta = {} |
177 total = 0 | 183 total = 0 |
178 for process_type in cpu_stats: | 184 for process_type in cpu_stats: |
179 assert process_type in start_cpu_stats, 'Mismatching process types' | 185 assert process_type in start_cpu_stats, 'Mismatching process types' |
180 # Skip any process_types that are empty. | 186 # Skip any process_types that are empty. |
181 if (not cpu_stats[process_type]) or (not start_cpu_stats[process_type]): | 187 if (not cpu_stats[process_type]) or (not start_cpu_stats[process_type]): |
182 continue | 188 continue |
183 # Skip if IdleWakeupCount is not present. | 189 # Skip if IdleWakeupCount is not present. |
184 if (('IdleWakeupCount' not in cpu_stats[process_type]) or | 190 if (('IdleWakeupCount' not in cpu_stats[process_type]) or |
185 ('IdleWakeupCount' not in start_cpu_stats[process_type])): | 191 ('IdleWakeupCount' not in start_cpu_stats[process_type])): |
186 continue | 192 continue |
187 | 193 |
188 assert isinstance(cpu_stats[process_type]['IdleWakeupCount'], | 194 assert isinstance(cpu_stats[process_type]['IdleWakeupCount'], |
189 process_statistic_timeline_data.IdleWakeupTimelineData) | 195 process_statistic_timeline_data.IdleWakeupTimelineData) |
190 idle_wakeup_delta = (cpu_stats[process_type]['IdleWakeupCount'] - | 196 idle_wakeup_delta = (cpu_stats[process_type]['IdleWakeupCount'] - |
191 start_cpu_stats[process_type]['IdleWakeupCount']) | 197 start_cpu_stats[process_type]['IdleWakeupCount']) |
192 cpu_delta[process_type] = idle_wakeup_delta.total_sum() | 198 cpu_delta[process_type] = idle_wakeup_delta.total_sum() |
193 total = total + cpu_delta[process_type] | 199 total = total + cpu_delta[process_type] |
194 cpu_delta['Total'] = total | 200 cpu_delta['Total'] = total |
195 return cpu_delta | 201 return cpu_delta |
OLD | NEW |