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.
7 from metrics
import Metric
10 class PowerMetric(Metric
):
11 """A metric for measuring power usage."""
16 super(PowerMetric
, self
).__init
__()
20 def CustomizeBrowserOptions(cls
, options
):
21 PowerMetric
._enabed
= options
.report_root_metrics
23 def Start(self
, _
, tab
):
24 if not PowerMetric
._enabed
:
27 if not tab
.browser
.platform
.CanMonitorPowerAsync():
28 logging
.warning("System doesn't support async power monitoring.")
31 tab
.browser
.platform
.StartMonitoringPowerAsync()
33 def Stop(self
, _
, tab
):
34 if not PowerMetric
._enabed
:
37 if not tab
.browser
.platform
.CanMonitorPowerAsync():
40 self
._results
= tab
.browser
.platform
.StopMonitoringPowerAsync()
42 def AddResults(self
, _
, results
):
46 energy_consumption_mwh
= self
._results
['energy_consumption_mwh']
47 results
.Add('energy_consumption_mwh', 'mWh', energy_consumption_mwh
)