| 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 telemetry.util import process_statistic_timeline_data | 7 from telemetry.util import process_statistic_timeline_data |
| 8 from telemetry.value import scalar | 8 from telemetry.value import scalar |
| 9 | 9 |
| 10 from metrics import Metric | 10 from metrics import Metric |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 63 | 63 |
| 64 self._platform.StartMonitoringPower(self._browser) | 64 self._platform.StartMonitoringPower(self._browser) |
| 65 time.sleep(measurement_time_s) | 65 time.sleep(measurement_time_s) |
| 66 power_results = self._platform.StopMonitoringPower() | 66 power_results = self._platform.StopMonitoringPower() |
| 67 PowerMetric._quiescent_power_draw_mwh = ( | 67 PowerMetric._quiescent_power_draw_mwh = ( |
| 68 power_results.get('energy_consumption_mwh', 0)) | 68 power_results.get('energy_consumption_mwh', 0)) |
| 69 | 69 |
| 70 def Start(self, _, tab): | 70 def Start(self, _, tab): |
| 71 self._browser = tab.browser | 71 self._browser = tab.browser |
| 72 | 72 |
| 73 if self._platform.CanMeasureIdleWakeUps(): |
| 74 self._platform.StartMeasuringIdleWakeUps() |
| 75 |
| 73 if not self._platform.CanMonitorPower(): | 76 if not self._platform.CanMonitorPower(): |
| 74 return | 77 return |
| 75 | 78 |
| 76 self._results = None | 79 self._results = None |
| 77 self._StopInternal() | 80 self._StopInternal() |
| 78 | 81 |
| 79 # This line invokes top a few times, call before starting power measurement. | 82 # This line invokes top a few times, call before starting power measurement. |
| 83 # TODO(jdduke): Move idle wakeup measurement into standalone PowerMonitor |
| 84 # instances. Including wakeups in the "instantaneous" CPU stats object is |
| 85 # awkward on Linux-based platforms. |
| 80 self._starting_cpu_stats = self._browser.cpu_stats | 86 self._starting_cpu_stats = self._browser.cpu_stats |
| 81 self._platform.StartMonitoringPower(self._browser) | 87 self._platform.StartMonitoringPower(self._browser) |
| 82 self._running = True | 88 self._running = True |
| 83 | 89 |
| 84 def Stop(self, _, tab): | 90 def Stop(self, _, tab): |
| 91 if self._platform.CanMeasureIdleWakeUps(): |
| 92 self._platform.StopMeasuringIdleWakeUps() |
| 93 |
| 85 if not self._platform.CanMonitorPower(): | 94 if not self._platform.CanMonitorPower(): |
| 86 return | 95 return |
| 87 | 96 |
| 88 self._StopInternal() | 97 self._StopInternal() |
| 89 | 98 |
| 90 def AddResults(self, _, results): | 99 def AddResults(self, _, results): |
| 91 """Add the collected power data into the results object. | 100 """Add the collected power data into the results object. |
| 92 | 101 |
| 93 This function needs to be robust in the face of differing power data on | 102 This function needs to be robust in the face of differing power data on |
| 94 various platforms. Therefore data existence needs to be checked when | 103 various platforms. Therefore data existence needs to be checked when |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 194 continue | 203 continue |
| 195 | 204 |
| 196 assert isinstance(cpu_stats[process_type]['IdleWakeupCount'], | 205 assert isinstance(cpu_stats[process_type]['IdleWakeupCount'], |
| 197 process_statistic_timeline_data.IdleWakeupTimelineData) | 206 process_statistic_timeline_data.IdleWakeupTimelineData) |
| 198 idle_wakeup_delta = (cpu_stats[process_type]['IdleWakeupCount'] - | 207 idle_wakeup_delta = (cpu_stats[process_type]['IdleWakeupCount'] - |
| 199 start_cpu_stats[process_type]['IdleWakeupCount']) | 208 start_cpu_stats[process_type]['IdleWakeupCount']) |
| 200 cpu_delta[process_type] = idle_wakeup_delta.total_sum() | 209 cpu_delta[process_type] = idle_wakeup_delta.total_sum() |
| 201 total = total + cpu_delta[process_type] | 210 total = total + cpu_delta[process_type] |
| 202 cpu_delta['Total'] = total | 211 cpu_delta['Total'] = total |
| 203 return cpu_delta | 212 return cpu_delta |
| OLD | NEW |