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 |
| 9 |
| 10 class PowerMetric(Metric): |
| 11 """A metric for measuring power usage.""" |
| 12 |
| 13 _enabed = True |
| 14 |
| 15 def __init__(self): |
| 16 super(PowerMetric, self).__init__() |
| 17 self._results = None |
| 18 |
| 19 @classmethod |
| 20 def CustomizeBrowserOptions(cls, options): |
| 21 PowerMetric._enabed = options.report_root_metrics |
| 22 |
| 23 def Start(self, _, tab): |
| 24 if not PowerMetric._enabed: |
| 25 return |
| 26 |
| 27 if not tab.browser.platform.CanMonitorPowerAsync(): |
| 28 logging.warning("System doesn't support async power monitoring.") |
| 29 return |
| 30 |
| 31 tab.browser.platform.StartMonitoringPowerAsync() |
| 32 |
| 33 def Stop(self, _, tab): |
| 34 if not PowerMetric._enabed: |
| 35 return |
| 36 |
| 37 if not tab.browser.platform.CanMonitorPowerAsync(): |
| 38 return |
| 39 |
| 40 self._results = tab.browser.platform.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) |
| 48 self._results = None |
OLD | NEW |