Chromium Code Reviews| Index: appengine/swarming/swarming_bot/os_utilities.py |
| diff --git a/appengine/swarming/swarming_bot/os_utilities.py b/appengine/swarming/swarming_bot/os_utilities.py |
| index e88d36ad220dbab095ea8f69a77a14a5ba35762a..b2b93c276419008428402703558750248653a04d 100755 |
| --- a/appengine/swarming/swarming_bot/os_utilities.py |
| +++ b/appengine/swarming/swarming_bot/os_utilities.py |
| @@ -17,6 +17,7 @@ the server to allow additional server-specific functionality. |
| import ctypes |
| import getpass |
| import glob |
| +import hashlib |
| import json |
| import logging |
| import multiprocessing |
| @@ -719,6 +720,90 @@ def get_integrity_level_win(): |
| ### Android. |
| +def initialize_android(pub, priv): |
| + # TODO(maruel): Remove. |
| + return platforms.android.initialize(pub, priv) |
| + |
| + |
| +def get_dimensions_all_devices_android(cmds): |
|
Vadim Sh.
2015/08/21 23:50:27
what is "cmds"? Why not "devices"?
M-A Ruel
2015/08/22 01:38:05
Yeah cmds is a bit obscure. it's a dict of devices
|
| + """Returns the default dimensions for an host with multiple android devices. |
| + """ |
| + dimensions = get_dimensions() |
| + if not cmds: |
| + return dimensions |
| + |
| + # Pop a few dimensions otherwise there will be too many dimensions. |
| + del dimensions[u'cpu'] |
| + del dimensions[u'cores'] |
| + del dimensions[u'gpu'] |
| + dimensions.pop(u'machine_type') |
| + |
| + # Make sure all the devices use the same board. |
| + keys = (u'build.id', u'product.board') |
| + for key in keys: |
| + dimensions[key] = set() |
| + dimensions[u'android'] = [] |
| + for serial_number, cmd in cmds.iteritems(): |
| + if cmd: |
| + properties = platforms.android.get_build_prop(cmd) |
| + if properties: |
| + for key in keys: |
| + dimensions[key].add(properties[u'ro.' + key]) |
| + dimensions[u'android'].append(serial_number) |
| + dimensions[u'android'].sort() |
| + for key in keys: |
| + if not dimensions[key]: |
| + del dimensions[key] |
| + else: |
| + dimensions[key] = sorted(dimensions[key]) |
| + nb_android = len(dimensions[u'android']) |
| + dimensions[u'android_devices'] = map( |
| + str, range(nb_android, max(0, nb_android-2), -1)) |
| + return dimensions |
| + |
| + |
| +def get_state_all_devices_android(cmds): |
| + """Returns state information about all the devices connected to the host. |
| + """ |
| + state = get_state() |
| + if not cmds: |
| + return state |
| + |
| + # Add a few values that were poped from dimensions. |
| + cpu_type = get_cpu_type() |
| + cpu_bitness = get_cpu_bitness() |
| + state[u'cpu'] = [ |
| + cpu_type, |
| + cpu_type + u'-' + cpu_bitness, |
| + ] |
| + state[u'cores'] = [unicode(get_num_processors())] |
| + state[u'gpu'] = get_gpu()[0] |
| + machine_type = get_machine_type() |
| + if machine_type: |
| + state[u'machine_type'] = [machine_type] |
| + |
| + keys = ( |
| + u'board.platform', u'product.cpu.abi', u'build.tags', u'build.type', |
| + u'build.version.sdk') |
| + state['devices'] = {} |
| + for serial_number, cmd in cmds.iteritems(): |
| + if cmd: |
| + properties = platforms.android.get_build_prop(cmd) |
| + if properties: |
| + # TODO(maruel): uptime, diskstats, wifi, power, throttle, etc. |
| + device = { |
| + u'build': {key: properties[u'ro.'+key] for key in keys}, |
| + u'disk': platforms.android.get_disk(cmd), |
| + u'battery': platforms.android.get_battery(cmd), |
| + u'state': u'available', |
| + u'temp': platforms.android.get_temp(cmd), |
| + } |
| + else: |
| + device = {u'state': u'unavailable'} |
| + else: |
| + device = {u'state': 'unauthenticated'} |
| + state[u'devices'][serial_number] = device |
| + return state |
| ### |
| @@ -1051,10 +1136,23 @@ def trim_rolled_log(name): |
| def main(): |
| """Prints out the output of get_dimensions() and get_state().""" |
| # Pass an empty tag, so pop it up since it has no significance. |
| - data = { |
| - u'dimensions': get_dimensions(), |
| - u'state': get_state(), |
| - } |
| + devices = None |
| + if sys.platform == 'linux2': |
| + devices = platforms.android.get_devices() |
| + if devices: |
| + try: |
| + data = { |
| + u'dimensions': get_dimensions_all_devices_android(devices), |
| + u'state': get_state_all_devices_android(devices), |
| + } |
| + finally: |
| + platforms.android.close_devices(devices) |
| + else: |
| + data = { |
| + u'dimensions': get_dimensions(), |
| + u'state': get_state(), |
| + } |
| + |
| json.dump(data, sys.stdout, indent=2, sort_keys=True, separators=(',', ': ')) |
| print('') |
| return 0 |