Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 # Copyright 2014 The Swarming Authors. All rights reserved. | 2 # Copyright 2014 The Swarming Authors. All rights reserved. |
| 3 # Use of this source code is governed by the Apache v2.0 license that can be | 3 # Use of this source code is governed by the Apache v2.0 license that can be |
| 4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
| 5 | 5 |
| 6 """OS specific utility functions. | 6 """OS specific utility functions. |
| 7 | 7 |
| 8 Includes code: | 8 Includes code: |
| 9 - to declare the current system this code is running under. | 9 - to declare the current system this code is running under. |
| 10 - to run a command on user login. | 10 - to run a command on user login. |
| 11 - to restart the host. | 11 - to restart the host. |
| 12 | 12 |
| 13 This file serves as an API to bot_config.py. bot_config.py can be replaced on | 13 This file serves as an API to bot_config.py. bot_config.py can be replaced on |
| 14 the server to allow additional server-specific functionality. | 14 the server to allow additional server-specific functionality. |
| 15 """ | 15 """ |
| 16 | 16 |
| 17 import ctypes | 17 import ctypes |
| 18 import getpass | 18 import getpass |
| 19 import glob | 19 import glob |
| 20 import hashlib | |
| 20 import json | 21 import json |
| 21 import logging | 22 import logging |
| 22 import multiprocessing | 23 import multiprocessing |
| 23 import os | 24 import os |
| 24 import pipes | 25 import pipes |
| 25 import platform | 26 import platform |
| 26 import re | 27 import re |
| 27 import signal | 28 import signal |
| 28 import socket | 29 import socket |
| 29 import string | 30 import string |
| (...skipping 682 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 712 token_info.Label.Sid, p_sid_size.contents.value - 1) | 713 token_info.Label.Sid, p_sid_size.contents.value - 1) |
| 713 value = res.contents.value | 714 value = res.contents.value |
| 714 return mapping.get(value) or u'0x%04x' % value | 715 return mapping.get(value) or u'0x%04x' % value |
| 715 finally: | 716 finally: |
| 716 ctypes.windll.kernel32.CloseHandle(token) | 717 ctypes.windll.kernel32.CloseHandle(token) |
| 717 | 718 |
| 718 | 719 |
| 719 ### Android. | 720 ### Android. |
| 720 | 721 |
| 721 | 722 |
| 723 def initialize_android(pub, priv): | |
| 724 # TODO(maruel): Remove. | |
| 725 return platforms.android.initialize(pub, priv) | |
| 726 | |
| 727 | |
| 728 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
| |
| 729 """Returns the default dimensions for an host with multiple android devices. | |
| 730 """ | |
| 731 dimensions = get_dimensions() | |
| 732 if not cmds: | |
| 733 return dimensions | |
| 734 | |
| 735 # Pop a few dimensions otherwise there will be too many dimensions. | |
| 736 del dimensions[u'cpu'] | |
| 737 del dimensions[u'cores'] | |
| 738 del dimensions[u'gpu'] | |
| 739 dimensions.pop(u'machine_type') | |
| 740 | |
| 741 # Make sure all the devices use the same board. | |
| 742 keys = (u'build.id', u'product.board') | |
| 743 for key in keys: | |
| 744 dimensions[key] = set() | |
| 745 dimensions[u'android'] = [] | |
| 746 for serial_number, cmd in cmds.iteritems(): | |
| 747 if cmd: | |
| 748 properties = platforms.android.get_build_prop(cmd) | |
| 749 if properties: | |
| 750 for key in keys: | |
| 751 dimensions[key].add(properties[u'ro.' + key]) | |
| 752 dimensions[u'android'].append(serial_number) | |
| 753 dimensions[u'android'].sort() | |
| 754 for key in keys: | |
| 755 if not dimensions[key]: | |
| 756 del dimensions[key] | |
| 757 else: | |
| 758 dimensions[key] = sorted(dimensions[key]) | |
| 759 nb_android = len(dimensions[u'android']) | |
| 760 dimensions[u'android_devices'] = map( | |
| 761 str, range(nb_android, max(0, nb_android-2), -1)) | |
| 762 return dimensions | |
| 763 | |
| 764 | |
| 765 def get_state_all_devices_android(cmds): | |
| 766 """Returns state information about all the devices connected to the host. | |
| 767 """ | |
| 768 state = get_state() | |
| 769 if not cmds: | |
| 770 return state | |
| 771 | |
| 772 # Add a few values that were poped from dimensions. | |
| 773 cpu_type = get_cpu_type() | |
| 774 cpu_bitness = get_cpu_bitness() | |
| 775 state[u'cpu'] = [ | |
| 776 cpu_type, | |
| 777 cpu_type + u'-' + cpu_bitness, | |
| 778 ] | |
| 779 state[u'cores'] = [unicode(get_num_processors())] | |
| 780 state[u'gpu'] = get_gpu()[0] | |
| 781 machine_type = get_machine_type() | |
| 782 if machine_type: | |
| 783 state[u'machine_type'] = [machine_type] | |
| 784 | |
| 785 keys = ( | |
| 786 u'board.platform', u'product.cpu.abi', u'build.tags', u'build.type', | |
| 787 u'build.version.sdk') | |
| 788 state['devices'] = {} | |
| 789 for serial_number, cmd in cmds.iteritems(): | |
| 790 if cmd: | |
| 791 properties = platforms.android.get_build_prop(cmd) | |
| 792 if properties: | |
| 793 # TODO(maruel): uptime, diskstats, wifi, power, throttle, etc. | |
| 794 device = { | |
| 795 u'build': {key: properties[u'ro.'+key] for key in keys}, | |
| 796 u'disk': platforms.android.get_disk(cmd), | |
| 797 u'battery': platforms.android.get_battery(cmd), | |
| 798 u'state': u'available', | |
| 799 u'temp': platforms.android.get_temp(cmd), | |
| 800 } | |
| 801 else: | |
| 802 device = {u'state': u'unavailable'} | |
| 803 else: | |
| 804 device = {u'state': 'unauthenticated'} | |
| 805 state[u'devices'][serial_number] = device | |
| 806 return state | |
| 722 | 807 |
| 723 | 808 |
| 724 ### | 809 ### |
| 725 | 810 |
| 726 | 811 |
| 727 def get_dimensions(): | 812 def get_dimensions(): |
| 728 """Returns the default dimensions.""" | 813 """Returns the default dimensions.""" |
| 729 os_name = get_os_name() | 814 os_name = get_os_name() |
| 730 cpu_type = get_cpu_type() | 815 cpu_type = get_cpu_type() |
| 731 cpu_bitness = get_cpu_bitness() | 816 cpu_bitness = get_cpu_bitness() |
| (...skipping 312 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1044 os.remove(item) | 1129 os.remove(item) |
| 1045 for item in glob.iglob('%s.???' % name): | 1130 for item in glob.iglob('%s.???' % name): |
| 1046 os.remove(item) | 1131 os.remove(item) |
| 1047 except Exception as e: | 1132 except Exception as e: |
| 1048 logging.exception('trim_rolled_log(%s) failed: %s', name, e) | 1133 logging.exception('trim_rolled_log(%s) failed: %s', name, e) |
| 1049 | 1134 |
| 1050 | 1135 |
| 1051 def main(): | 1136 def main(): |
| 1052 """Prints out the output of get_dimensions() and get_state().""" | 1137 """Prints out the output of get_dimensions() and get_state().""" |
| 1053 # Pass an empty tag, so pop it up since it has no significance. | 1138 # Pass an empty tag, so pop it up since it has no significance. |
| 1054 data = { | 1139 devices = None |
| 1055 u'dimensions': get_dimensions(), | 1140 if sys.platform == 'linux2': |
| 1056 u'state': get_state(), | 1141 devices = platforms.android.get_devices() |
| 1057 } | 1142 if devices: |
| 1143 try: | |
| 1144 data = { | |
| 1145 u'dimensions': get_dimensions_all_devices_android(devices), | |
| 1146 u'state': get_state_all_devices_android(devices), | |
| 1147 } | |
| 1148 finally: | |
| 1149 platforms.android.close_devices(devices) | |
| 1150 else: | |
| 1151 data = { | |
| 1152 u'dimensions': get_dimensions(), | |
| 1153 u'state': get_state(), | |
| 1154 } | |
| 1155 | |
| 1058 json.dump(data, sys.stdout, indent=2, sort_keys=True, separators=(',', ': ')) | 1156 json.dump(data, sys.stdout, indent=2, sort_keys=True, separators=(',', ': ')) |
| 1059 print('') | 1157 print('') |
| 1060 return 0 | 1158 return 0 |
| 1061 | 1159 |
| 1062 | 1160 |
| 1063 if __name__ == '__main__': | 1161 if __name__ == '__main__': |
| 1064 sys.exit(main()) | 1162 sys.exit(main()) |
| OLD | NEW |