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

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

Issue 470803006: [Telemetry] Android power moniotrs extend SysfsPowerMonitor. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Moved platform files and made other Android monitors extend sysfs. 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
Index: tools/telemetry/telemetry/core/platform/power_monitor/android_dumpsys_power_monitor.py
diff --git a/tools/telemetry/telemetry/core/platform/power_monitor/android_dumpsys_power_monitor.py b/tools/telemetry/telemetry/core/platform/power_monitor/android_dumpsys_power_monitor.py
index c659ee43a99614561665a479a2e382f1a4abd516..16717ce4b762a3fc34c6a464ae693b993f11e962 100644
--- a/tools/telemetry/telemetry/core/platform/power_monitor/android_dumpsys_power_monitor.py
+++ b/tools/telemetry/telemetry/core/platform/power_monitor/android_dumpsys_power_monitor.py
@@ -6,10 +6,11 @@ import csv
import logging
from collections import defaultdict
-from telemetry.core.platform import power_monitor
+from telemetry.core.platform import android_sysfs_platform
+from telemetry.core.platform.power_monitor import sysfs_power_monitor
-class DumpsysPowerMonitor(power_monitor.PowerMonitor):
+class DumpsysPowerMonitor(sysfs_power_monitor.SysfsPowerMonitor):
"""PowerMonitor that relies on the dumpsys batterystats to monitor the power
consumption of a single android application. This measure uses a heuristic
and is the same information end-users see with the battery application.
@@ -20,37 +21,33 @@ class DumpsysPowerMonitor(power_monitor.PowerMonitor):
Args:
device: DeviceUtils instance.
"""
- super(DumpsysPowerMonitor, self).__init__()
+ super(DumpsysPowerMonitor, self).__init__(
+ android_sysfs_platform.AndroidSysfsPlatform(device))
self._device = device
- self._browser = None
def CanMonitorPower(self):
return self._device.old_interface.CanControlUsbCharging()
def StartMonitoringPower(self, browser):
- assert not self._browser, (
- 'Must call StopMonitoringPower().')
- self._browser = browser
+ super(DumpsysPowerMonitor, self).StartMonitoringPower(browser)
# Disable the charging of the device over USB. This is necessary because the
# device only collects information about power usage when the device is not
# charging.
self._device.old_interface.DisableUsbCharging()
def StopMonitoringPower(self):
- assert self._browser, (
- 'StartMonitoringPower() not called.')
- try:
- self._device.old_interface.EnableUsbCharging()
+ if self._browser:
# pylint: disable=W0212
package = self._browser._browser_backend.package
- # By default, 'dumpsys batterystats' measures power consumption during the
- # last unplugged period.
- result = self._device.RunShellCommand(
- 'dumpsys batterystats -c %s' % package)
- assert result, 'Dumpsys produced no output'
- return DumpsysPowerMonitor.ParseSamplingOutput(package, result)
- finally:
- self._browser = None
+ cpu_stats = super(DumpsysPowerMonitor, self).StopMonitoringPower()
+ self._device.old_interface.EnableUsbCharging()
+ # By default, 'dumpsys batterystats' measures power consumption during the
+ # last unplugged period.
+ result = self._device.RunShellCommand(
+ 'dumpsys batterystats -c %s' % package)
+ assert result, 'Dumpsys produced no output'
+ return super(DumpsysPowerMonitor, self).CombineResults(
+ cpu_stats, DumpsysPowerMonitor.ParseSamplingOutput(package, result))
@staticmethod
def ParseSamplingOutput(package, dumpsys_output):

Powered by Google App Engine
This is Rietveld 408576698