Fix import error in mac_platform_backend.py
[chromium-blink-merge.git] / tools / perf / metrics / power.py
blob32461cef91757ca83da90f8b4420895cd92c3340
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.
5 import logging
7 from metrics import Metric
10 class PowerMetric(Metric):
11 """A metric for measuring power usage."""
13 _enabed = True
15 def __init__(self):
16 super(PowerMetric, self).__init__()
17 self._results = None
19 @classmethod
20 def CustomizeBrowserOptions(cls, options):
21 PowerMetric._enabed = options.report_root_metrics
23 def Start(self, _, tab):
24 if not PowerMetric._enabed:
25 return
27 if not tab.browser.platform.CanMonitorPowerAsync():
28 logging.warning("System doesn't support async power monitoring.")
29 return
31 tab.browser.platform.StartMonitoringPowerAsync()
33 def Stop(self, _, tab):
34 if not PowerMetric._enabed:
35 return
37 if not tab.browser.platform.CanMonitorPowerAsync():
38 return
40 self._results = tab.browser.platform.StopMonitoringPowerAsync()
42 def AddResults(self, _, results):
43 if not self._results:
44 return
46 energy_consumption_mwh = self._results['energy_consumption_mwh']
47 results.Add('energy_consumption_mwh', 'mWh', energy_consumption_mwh)
48 self._results = None