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 def __init__(self): |
| 14 super(PowerMetric, self).__init__() |
| 15 self._results = None |
| 16 |
| 17 def Start(self, _, tab): |
| 18 if not tab.browser.platform.CanMonitorPowerAsync(): |
| 19 logging.warning("System doesn't support async power monitoring.") |
| 20 return |
| 21 |
| 22 tab.browser.platform.StartMonitoringPowerAsync() |
| 23 |
| 24 def Stop(self, _, tab): |
| 25 if not tab.browser.platform.CanMonitorPowerAsync(): |
| 26 return |
| 27 |
| 28 self._results = tab.browser.platform.StopMonitoringPowerAsync() |
| 29 |
| 30 def AddResults(self, _, results): |
| 31 if not self._results: |
| 32 return |
| 33 |
| 34 energy_consumption_mwh = self._results['energy_consumption_mwh'] |
| 35 results.Add('energy_consumption_mwh', 'mWh', energy_consumption_mwh) |
| 36 self._results = None |
OLD | NEW |