| 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 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 |