aboutsummaryrefslogtreecommitdiff
path: root/catapult/devil/devil/android/tools/device_monitor.py
diff options
context:
space:
mode:
Diffstat (limited to 'catapult/devil/devil/android/tools/device_monitor.py')
-rwxr-xr-xcatapult/devil/devil/android/tools/device_monitor.py73
1 files changed, 40 insertions, 33 deletions
diff --git a/catapult/devil/devil/android/tools/device_monitor.py b/catapult/devil/devil/android/tools/device_monitor.py
index 565f8658..6128dae8 100755
--- a/catapult/devil/devil/android/tools/device_monitor.py
+++ b/catapult/devil/devil/android/tools/device_monitor.py
@@ -2,7 +2,6 @@
# Copyright 2015 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.
-
"""Launches a daemon to monitor android device temperatures & status.
This script will repeatedly poll the given devices for their temperatures and
@@ -22,24 +21,23 @@ import time
if __name__ == '__main__':
sys.path.append(
- os.path.abspath(os.path.join(os.path.dirname(__file__),
- '..', '..', '..')))
+ os.path.abspath(
+ os.path.join(os.path.dirname(__file__), '..', '..', '..')))
from devil.android import battery_utils
-from devil.android import device_blacklist
+from devil.android import device_denylist
from devil.android import device_errors
from devil.android import device_utils
from devil.android.tools import script_common
-
# Various names of sensors used to measure cpu temp
CPU_TEMP_SENSORS = [
- # most nexus devices
- 'tsens_tz_sensor0',
- # android one
- 'mtktscpu',
- # nexus 9
- 'CPU-therm',
+ # most nexus devices
+ 'tsens_tz_sensor0',
+ # android one
+ 'mtktscpu',
+ # nexus 9
+ 'CPU-therm',
]
DEVICE_FILE_VERSION = 1
@@ -47,7 +45,8 @@ DEVICE_FILE = os.path.join(
os.path.expanduser('~'), '.android',
'%s__android_device_status.json' % socket.gethostname().split('.')[0])
-MEM_INFO_REGEX = re.compile(r'.*?\:\s*(\d+)\s*kB') # ex: 'MemTotal: 185735 kB'
+MEM_INFO_REGEX = re.compile(
+ r'.*?\:\s*(\d+)\s*kB') # ex: 'MemTotal: 185735 kB'
def get_device_status_unsafe(device):
@@ -129,14 +128,16 @@ def get_device_status_unsafe(device):
files = []
try:
files = device.RunShellCommand(
- 'grep -lE "%s" /sys/class/thermal/thermal_zone*/type' % '|'.join(
- CPU_TEMP_SENSORS), shell=True, check_return=True)
+ 'grep -lE "%s" /sys/class/thermal/thermal_zone*/type' %
+ '|'.join(CPU_TEMP_SENSORS),
+ shell=True,
+ check_return=True)
except device_errors.AdbShellCommandFailedError:
logging.exception('Unable to list thermal sensors.')
for f in files:
try:
sensor_name = device.ReadFile(f).strip()
- temp = float(device.ReadFile(f[:-4] + 'temp').strip()) # s/type^/temp
+ temp = float(device.ReadFile(f[:-4] + 'temp').strip()) # s/type^/temp
status['temp'][sensor_name] = temp
except (device_errors.AdbShellCommandFailedError, ValueError):
logging.exception('Unable to read thermal sensor %s', f)
@@ -144,7 +145,7 @@ def get_device_status_unsafe(device):
# Uptime
try:
uptimes = device.ReadFile('/proc/uptime').split()
- status['uptime'] = float(uptimes[0]) # Take the first field (actual uptime)
+ status['uptime'] = float(uptimes[0]) # Take the first field (actual uptime)
except (device_errors.AdbShellCommandFailedError, ValueError):
logging.exception('Unable to read /proc/uptime')
@@ -167,24 +168,26 @@ def get_device_status(device):
return status
-def get_all_status(blacklist):
+def get_all_status(denylist):
status_dict = {
'version': DEVICE_FILE_VERSION,
'devices': {},
}
- healthy_devices = device_utils.DeviceUtils.HealthyDevices(blacklist)
+ healthy_devices = device_utils.DeviceUtils.HealthyDevices(denylist)
parallel_devices = device_utils.DeviceUtils.parallel(healthy_devices)
results = parallel_devices.pMap(get_device_status).pGet(None)
status_dict['devices'] = {
- device.serial: result for device, result in zip(healthy_devices, results)
+ device.serial: result
+ for device, result in zip(healthy_devices, results)
}
- if blacklist:
- for device, reason in blacklist.Read().iteritems():
+ if denylist:
+ for device, reason in denylist.Read().iteritems():
status_dict['devices'][device] = {
- 'state': reason.get('reason', 'blacklisted')}
+ 'state': reason.get('reason', 'denylisted')
+ }
status_dict['timestamp'] = time.time()
return status_dict
@@ -194,33 +197,37 @@ def main(argv):
"""Launches the device monitor.
Polls the devices for their battery and cpu temperatures and scans the
- blacklist file every 60 seconds and dumps the data to DEVICE_FILE.
+ denylist file every 60 seconds and dumps the data to DEVICE_FILE.
"""
- parser = argparse.ArgumentParser(
- description='Launches the device monitor.')
+ parser = argparse.ArgumentParser(description='Launches the device monitor.')
script_common.AddEnvironmentArguments(parser)
- parser.add_argument('--blacklist-file', help='Path to device blacklist file.')
+ parser.add_argument('--denylist-file', help='Path to device denylist file.')
+ # TODO(crbug.com/1097306): Remove this once chromium_android/api.py stops
+ # using it.
+ parser.add_argument('--blacklist-file',
+ dest='denylist_file',
+ help=argparse.SUPPRESS)
args = parser.parse_args(argv)
logger = logging.getLogger()
logger.setLevel(logging.DEBUG)
handler = logging.handlers.RotatingFileHandler(
'/tmp/device_monitor.log', maxBytes=10 * 1024 * 1024, backupCount=5)
- fmt = logging.Formatter('%(asctime)s %(levelname)s %(message)s',
- datefmt='%y%m%d %H:%M:%S')
+ fmt = logging.Formatter(
+ '%(asctime)s %(levelname)s %(message)s', datefmt='%y%m%d %H:%M:%S')
handler.setFormatter(fmt)
logger.addHandler(handler)
script_common.InitializeEnvironment(args)
- blacklist = (device_blacklist.Blacklist(args.blacklist_file)
- if args.blacklist_file else None)
+ denylist = (device_denylist.Denylist(args.denylist_file)
+ if args.denylist_file else None)
- logging.info('Device monitor running with pid %d, adb: %s, blacklist: %s',
- os.getpid(), args.adb_path, args.blacklist_file)
+ logging.info('Device monitor running with pid %d, adb: %s, denylist: %s',
+ os.getpid(), args.adb_path, args.denylist_file)
while True:
start = time.time()
- status_dict = get_all_status(blacklist)
+ status_dict = get_all_status(denylist)
with open(DEVICE_FILE, 'wb') as f:
json.dump(status_dict, f, indent=2, sort_keys=True)
logging.info('Got status of all devices in %.2fs.', time.time() - start)