Chromium Code Reviews| Index: tools/perf/metrics/power.py |
| diff --git a/tools/perf/metrics/power.py b/tools/perf/metrics/power.py |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..32eef9d0cd338896c7dddaa3fcdc57d52aab204c |
| --- /dev/null |
| +++ b/tools/perf/metrics/power.py |
| @@ -0,0 +1,47 @@ |
| +# Copyright 2014 The Chromium Authors. All rights reserved. |
| +# Use of this source code is governed by a BSD-style license that can be |
| +# found in the LICENSE file. |
| + |
| +import logging |
| + |
| +from metrics import Metric |
| +from telemetry.core import exceptions |
| +from telemetry.core import platform |
| + |
| + |
| +class PowerMetric(Metric): |
| + """A metric for measuring power usage.""" |
| + |
| + def __init__(self): |
| + super(PowerMetric, self).__init__() |
| + self._backend = None |
| + self._results = None |
| + |
| + # pylint: disable=W0613 |
| + def Start(self, unused_page, unused_tab): |
| + if not self._backend: |
| + self._backend = platform.CreatePlatformBackendForCurrentOS() |
|
tonyg
2014/01/23 18:23:40
We should access this via tab.browser.platform and
jeremy
2014/01/23 18:58:41
Done.
|
| + |
| + if self._results: |
| + raise exceptions.ProfilingException( |
| + "Reusing a power profiler is not supported") |
|
tonyg
2014/01/23 18:23:40
Why? Shouldn't we just clear self._results in AddR
jeremy
2014/01/23 18:58:41
Done.
|
| + |
| + if not self._backend.CanMonitorPowerAsync(): |
| + logging.warning("System doesn't support async power monitoring.") |
| + return |
| + |
| + self._backend.StartMonitoringPowerAsync() |
| + |
| + # pylint: disable=W0613 |
| + def Stop(self, unused_page, unused_tab): |
| + if not self._backend.CanMonitorPowerAsync(): |
| + return |
| + |
| + self._results = self._backend.StopMonitoringPowerAsync() |
| + |
| + def AddResults(self, _, results): |
| + if not self._results: |
| + return |
| + |
| + energy_consumption_mwh = self._results['energy_consumption_mwh'] |
| + results.Add('energy_consumption_mwh', 'mwh', energy_consumption_mwh) |
|
tonyg
2014/01/23 18:23:40
For the unit display string, let's use the correct
jeremy
2014/01/23 18:58:41
Done.
|