OLD | NEW |
---|---|
(Empty) | |
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 | |
3 # found in the LICENSE file. | |
4 | |
5 import logging | |
6 | |
7 from metrics import Metric | |
8 from telemetry.core import exceptions | |
9 from telemetry.core import platform | |
10 | |
11 | |
12 class PowerMetric(Metric): | |
13 """A metric for measuring power usage.""" | |
14 | |
15 def __init__(self): | |
16 super(PowerMetric, self).__init__() | |
17 self._backend = None | |
18 self._results = None | |
19 | |
20 # pylint: disable=W0613 | |
21 def Start(self, unused_page, unused_tab): | |
22 if not self._backend: | |
23 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.
| |
24 | |
25 if self._results: | |
26 raise exceptions.ProfilingException( | |
27 "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.
| |
28 | |
29 if not self._backend.CanMonitorPowerAsync(): | |
30 logging.warning("System doesn't support async power monitoring.") | |
31 return | |
32 | |
33 self._backend.StartMonitoringPowerAsync() | |
34 | |
35 # pylint: disable=W0613 | |
36 def Stop(self, unused_page, unused_tab): | |
37 if not self._backend.CanMonitorPowerAsync(): | |
38 return | |
39 | |
40 self._results = self._backend.StopMonitoringPowerAsync() | |
41 | |
42 def AddResults(self, _, results): | |
43 if not self._results: | |
44 return | |
45 | |
46 energy_consumption_mwh = self._results['energy_consumption_mwh'] | |
47 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.
| |
OLD | NEW |