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

Unified Diff: tools/telemetry/telemetry/core/platform/power_monitor/cros_power_monitor.py

Issue 485003004: [Telemetry] Chrome OS gathers power and time in one command. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 4 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 | « no previous file | tools/telemetry/telemetry/core/platform/power_monitor/cros_power_monitor_unittest.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tools/telemetry/telemetry/core/platform/power_monitor/cros_power_monitor.py
diff --git a/tools/telemetry/telemetry/core/platform/power_monitor/cros_power_monitor.py b/tools/telemetry/telemetry/core/platform/power_monitor/cros_power_monitor.py
index c4cb9e85981c46da235553c27dda007ace245cd5..92e735ddbad699129207ed3275c9789d5d377910 100644
--- a/tools/telemetry/telemetry/core/platform/power_monitor/cros_power_monitor.py
+++ b/tools/telemetry/telemetry/core/platform/power_monitor/cros_power_monitor.py
@@ -22,14 +22,12 @@ class CrosPowerMonitor(sysfs_power_monitor.SysfsPowerMonitor):
Attributes:
_cri: The Chrome interface.
- _end_time: The epoch time at which the test finishes executing.
_initial_power: The result of 'power_supply_info' before the test.
_start_time: The epoch time at which the test starts executing.
"""
super(CrosPowerMonitor, self).__init__(
cros_sysfs_platform.CrosSysfsPlatform(cri))
self._cri = cri
- self._end_time = None
self._initial_power = None
self._start_time = None
@@ -40,22 +38,42 @@ class CrosPowerMonitor(sysfs_power_monitor.SysfsPowerMonitor):
def StartMonitoringPower(self, browser):
super(CrosPowerMonitor, self).StartMonitoringPower(browser)
if self._IsOnBatteryPower():
- self._initial_power = self._cri.RunCmdOnDevice(['power_supply_info'])[0]
- self._start_time = int(self._cri.RunCmdOnDevice(['date', '+%s'])[0])
+ sample = self._cri.RunCmdOnDevice(
+ ['power_supply_info;', 'date', '+%s'])[0]
+ self._initial_power, self._start_time = CrosPowerMonitor.SplitSample(
+ sample)
def StopMonitoringPower(self):
cpu_stats = super(CrosPowerMonitor, self).StopMonitoringPower()
power_stats = {}
if self._IsOnBatteryPower():
- final_power = self._cri.RunCmdOnDevice(['power_supply_info'])[0]
- self._end_time = int(self._cri.RunCmdOnDevice(['date', '+%s'])[0])
+ sample = self._cri.RunCmdOnDevice(
+ ['power_supply_info;', 'date', '+%s'])[0]
+ final_power, end_time = CrosPowerMonitor.SplitSample(sample)
# The length of the test is used to measure energy consumption.
- length_h = (self._end_time - self._start_time) / 3600.0
+ length_h = (end_time - self._start_time) / 3600.0
power_stats = CrosPowerMonitor.ParsePower(self._initial_power,
final_power, length_h)
return CrosPowerMonitor.CombineResults(cpu_stats, power_stats)
@staticmethod
+ def SplitSample(sample):
+ """Splits a power and time sample into the two separate values.
+
+ Args:
+ sample: The result of calling 'power_supply_info; date +%s' on the
+ device.
+
+ Returns:
+ A tuple of power sample and epoch time of the sample.
+ """
+ sample = sample.strip()
+ index = sample.rfind('\n')
+ power = sample[:index]
+ time = sample[index + 1:]
+ return power, int(time)
+
+ @staticmethod
def IsOnBatteryPower(status, board):
"""Determines if the devices is being charged.
« no previous file with comments | « no previous file | tools/telemetry/telemetry/core/platform/power_monitor/cros_power_monitor_unittest.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698