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.value import scalar | 9 from telemetry.value import scalar |
9 | 10 |
10 | 11 |
11 class PowerMetric(Metric): | 12 class PowerMetric(Metric): |
12 """A metric for measuring power usage.""" | 13 """A metric for measuring power usage.""" |
13 | 14 |
14 # System power draw while idle. | 15 # System power draw while idle. |
15 _quiescent_power_draw_mwh = 0 | 16 _quiescent_power_draw_mwh = 0 |
16 | 17 |
17 def __init__(self, browser, quiescent_measurement_time_s=0): | 18 def __init__(self, browser, quiescent_measurement_time_s=0): |
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
171 cpu_delta = {} | 172 cpu_delta = {} |
172 for process_type in cpu_stats: | 173 for process_type in cpu_stats: |
173 assert process_type in start_cpu_stats, 'Mismatching process types' | 174 assert process_type in start_cpu_stats, 'Mismatching process types' |
174 # Skip any process_types that are empty. | 175 # Skip any process_types that are empty. |
175 if (not cpu_stats[process_type]) or (not start_cpu_stats[process_type]): | 176 if (not cpu_stats[process_type]) or (not start_cpu_stats[process_type]): |
176 continue | 177 continue |
177 # Skip if IdleWakeupCount is not present. | 178 # Skip if IdleWakeupCount is not present. |
178 if (('IdleWakeupCount' not in cpu_stats[process_type]) or | 179 if (('IdleWakeupCount' not in cpu_stats[process_type]) or |
179 ('IdleWakeupCount' not in start_cpu_stats[process_type])): | 180 ('IdleWakeupCount' not in start_cpu_stats[process_type])): |
180 continue | 181 continue |
| 182 |
| 183 assert isinstance(cpu_stats[process_type]['IdleWakeupCount'], |
| 184 process_statistic_timeline_data.IdleWakeupTimelineData) |
181 idle_wakeup_delta = (cpu_stats[process_type]['IdleWakeupCount'] - | 185 idle_wakeup_delta = (cpu_stats[process_type]['IdleWakeupCount'] - |
182 start_cpu_stats[process_type]['IdleWakeupCount']) | 186 start_cpu_stats[process_type]['IdleWakeupCount']) |
183 cpu_delta[process_type] = idle_wakeup_delta | 187 cpu_delta[process_type] = idle_wakeup_delta.total_sum() |
184 return cpu_delta | 188 return cpu_delta |
OLD | NEW |