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

Side by Side Diff: infra/services/sysmon/android_device_metrics.py

Issue 2023003004: Don't report android device port paths. (Closed) Base URL: https://chromium.googlesource.com/infra/infra.git@master
Patch Set: Created 4 years, 6 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 unified diff | Download patch
« no previous file with comments | « no previous file | infra/services/sysmon/test/android_device_metrics_test.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 # Copyright (c) 2016 The Chromium Authors. All rights reserved. 1 # Copyright (c) 2016 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be 2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file. 3 # found in the LICENSE file.
4 4
5 import json 5 import json
6 import logging 6 import logging
7 import os 7 import os
8 import re
8 import socket 9 import socket
9 import time 10 import time
10 11
11 12
12 from infra_libs import ts_mon 13 from infra_libs import ts_mon
13 from infra_libs.ts_mon.common import interface 14 from infra_libs.ts_mon.common import interface
14 from infra_libs.ts_mon.common import targets 15 from infra_libs.ts_mon.common import targets
15 16
16 17
17 ANDROID_DEVICE_FILE_VERSION = 1 18 ANDROID_DEVICE_FILE_VERSION = 1
18 19
19 ANDROID_PREVIOUS_DEVICE_FILE_VERSION = ANDROID_DEVICE_FILE_VERSION - 1 20 ANDROID_PREVIOUS_DEVICE_FILE_VERSION = ANDROID_DEVICE_FILE_VERSION - 1
20 ANDROID_DEVICE_FILE = os.path.join(os.path.expanduser('~'), 21 ANDROID_DEVICE_FILE = os.path.join(os.path.expanduser('~'),
21 'android_device_status.json') 22 'android_device_status.json')
22 23
23 # Don't read a file older than this many seconds. 24 # Don't read a file older than this many seconds.
24 ANDROID_DEVICE_FILE_STALENESS_S = 120 25 ANDROID_DEVICE_FILE_STALENESS_S = 120
25 26
27 PORT_PATH_RE = re.compile(r'\d+\/\d+')
28
26 29
27 cpu_temp = ts_mon.FloatMetric('dev/cpu/temperature', 30 cpu_temp = ts_mon.FloatMetric('dev/cpu/temperature',
28 description='device CPU temperature in deg C') 31 description='device CPU temperature in deg C')
29 batt_temp = ts_mon.FloatMetric('dev/battery/temperature', 32 batt_temp = ts_mon.FloatMetric('dev/battery/temperature',
30 description='battery temperature in deg C') 33 description='battery temperature in deg C')
31 batt_charge = ts_mon.FloatMetric('dev/battery/charge', 34 batt_charge = ts_mon.FloatMetric('dev/battery/charge',
32 description='percentage charge of battery') 35 description='percentage charge of battery')
33 dev_status = ts_mon.StringMetric('dev/status', 36 dev_status = ts_mon.StringMetric('dev/status',
34 description='operational state of device') 37 description='operational state of device')
35 dev_type = ts_mon.StringMetric('dev/type', 38 dev_type = ts_mon.StringMetric('dev/type',
36 description='device hardware or type') 39 description='device hardware or type')
37 dev_os = ts_mon.StringMetric('dev/os', 40 dev_os = ts_mon.StringMetric('dev/os',
38 description='operating system of the device') 41 description='operating system of the device')
39 dev_uptime = ts_mon.FloatMetric('dev/device_uptime', 42 dev_uptime = ts_mon.FloatMetric('dev/device_uptime',
40 description='device uptime in seconds') 43 description='device uptime in seconds')
41 44
42 metric_read_status = ts_mon.StringMetric( 45 metric_read_status = ts_mon.StringMetric(
43 'dev/android_device_metric_read/status', 46 'dev/android_device_metric_read/status',
44 description='status of the last metric read') 47 description='status of the last metric read')
45 48
46 49
47 def get_device_statuses(device_file=ANDROID_DEVICE_FILE, now=None): 50 def get_device_statuses(device_file=ANDROID_DEVICE_FILE, now=None):
48 now = now or time.time() 51 now = now or time.time()
49 devices = _load_android_device_file(device_file, now) 52 devices = _load_android_device_file(device_file, now)
50 if not devices: 53 if not devices:
51 return 54 return
52 55
53 for device_name, device in devices.iteritems(): 56 for device_name, device in devices.iteritems():
57 if PORT_PATH_RE.match(device_name):
58 logging.warning('Found port path %s as device id. Skipping.',
ghost stip (do not use) 2016/06/01 18:03:37 interesting. when would this come up instead of de
bpastene 2016/06/01 21:43:30 I imagine it happens when there's a protocol/usb f
59 device_name)
60 continue
61
54 fields = {'device_id': device_name} 62 fields = {'device_id': device_name}
55 63
56 # Fields with special handling. 64 # Fields with special handling.
57 65
58 build = device.get('build', {}) 66 build = device.get('build', {})
59 d_type = build.get('build_product', 67 d_type = build.get('build_product',
60 build.get('product.board', 68 build.get('product.board',
61 build.get('product.device'))) 69 build.get('product.device')))
62 70
63 battery_temp = device.get('battery', {}).get('temperature') 71 battery_temp = device.get('battery', {}).get('temperature')
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
114 timestamp = json_data.get('timestamp', 0) 122 timestamp = json_data.get('timestamp', 0)
115 if now >= timestamp + ANDROID_DEVICE_FILE_STALENESS_S: 123 if now >= timestamp + ANDROID_DEVICE_FILE_STALENESS_S:
116 metric_read_status.set('stale_file') 124 metric_read_status.set('stale_file')
117 logging.error('Android device file %s is %ss stale (max %ss)', 125 logging.error('Android device file %s is %ss stale (max %ss)',
118 device_file, now - timestamp, 126 device_file, now - timestamp,
119 ANDROID_DEVICE_FILE_STALENESS_S) 127 ANDROID_DEVICE_FILE_STALENESS_S)
120 return [] 128 return []
121 129
122 metric_read_status.set('good') 130 metric_read_status.set('good')
123 return json_data.get('devices', []) 131 return json_data.get('devices', [])
OLDNEW
« no previous file with comments | « no previous file | infra/services/sysmon/test/android_device_metrics_test.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698