Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(26)

Unified Diff: tools/perf/metrics/power.py

Issue 144543007: [Telemetry] Add power usage metric (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Whitespace fix Created 6 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « tools/perf/measurements/smoothness.py ('k') | tools/perf/unit-info.json » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..32461cef91757ca83da90f8b4420895cd92c3340
--- /dev/null
+++ b/tools/perf/metrics/power.py
@@ -0,0 +1,48 @@
+# 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."""
+
+ _enabed = True
+
+ def __init__(self):
+ super(PowerMetric, self).__init__()
+ self._results = None
+
+ @classmethod
+ def CustomizeBrowserOptions(cls, options):
+ PowerMetric._enabed = options.report_root_metrics
+
+ def Start(self, _, tab):
+ if not PowerMetric._enabed:
+ return
+
+ 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 PowerMetric._enabed:
+ return
+
+ 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
« no previous file with comments | « tools/perf/measurements/smoothness.py ('k') | tools/perf/unit-info.json » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698