Index: tools/perf/metrics/power.py |
diff --git a/tools/perf/metrics/power.py b/tools/perf/metrics/power.py |
new file mode 100644 |
index 0000000000000000000000000000000000000000..a14d32d0e39eea1a179cddbbcc9cc3216f636a65 |
--- /dev/null |
+++ b/tools/perf/metrics/power.py |
@@ -0,0 +1,36 @@ |
+# Copyright 2014 The Chromium Authors. All rights reserved. |
+# Use of this source code is governed by a BSD-style license that can be |
+# found in the LICENSE file. |
+ |
+import logging |
+ |
+from metrics import Metric |
+ |
+ |
+class PowerMetric(Metric): |
+ """A metric for measuring power usage.""" |
+ |
+ def __init__(self): |
+ super(PowerMetric, self).__init__() |
+ self._results = None |
+ |
+ def Start(self, _, tab): |
+ if not tab.browser.platform.CanMonitorPowerAsync(): |
+ logging.warning("System doesn't support async power monitoring.") |
+ return |
+ |
+ tab.browser.platform.StartMonitoringPowerAsync() |
+ |
+ def Stop(self, _, tab): |
+ if not tab.browser.platform.CanMonitorPowerAsync(): |
+ return |
+ |
+ self._results = tab.browser.platform.StopMonitoringPowerAsync() |
+ |
+ def AddResults(self, _, results): |
+ if not self._results: |
+ return |
+ |
+ energy_consumption_mwh = self._results['energy_consumption_mwh'] |
+ results.Add('energy_consumption_mwh', 'mWh', energy_consumption_mwh) |
+ self._results = None |