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

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: Fix review comments 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
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

Powered by Google App Engine
This is Rietveld 408576698