| OLD | NEW |
| 1 #! /usr/bin/env python | 1 #! /usr/bin/env python |
| 2 # Copyright 2016 The Chromium Authors. All rights reserved. | 2 # Copyright 2016 The Chromium Authors. All rights reserved. |
| 3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
| 4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
| 5 | 5 |
| 6 """A script to manipulate device CPU frequency.""" | 6 """A script to manipulate device CPU frequency.""" |
| 7 | 7 |
| 8 import argparse | 8 import argparse |
| 9 import os | 9 import os |
| 10 import pprint | 10 import pprint |
| 11 import sys | 11 import sys |
| 12 | 12 |
| 13 if __name__ == '__main__': | 13 if __name__ == '__main__': |
| 14 sys.path.append( | 14 sys.path.append( |
| 15 os.path.abspath(os.path.join(os.path.dirname(__file__), | 15 os.path.abspath(os.path.join(os.path.dirname(__file__), |
| 16 '..', '..', '..'))) | 16 '..', '..', '..'))) |
| 17 | 17 |
| 18 from devil.android import device_utils | 18 from devil.android import device_utils |
| 19 from devil.android.perf import perf_control | 19 from devil.android.perf import perf_control |
| 20 from devil.android.tools import script_common | 20 from devil.android.tools import script_common |
| 21 from devil.utils import logging_common | 21 from devil.utils import run_tests_helper |
| 22 | 22 |
| 23 | 23 |
| 24 def SetScalingGovernor(device, args): | 24 def SetScalingGovernor(device, args): |
| 25 p = perf_control.PerfControl(device) | 25 p = perf_control.PerfControl(device) |
| 26 p.SetScalingGovernor(args.governor) | 26 p.SetScalingGovernor(args.governor) |
| 27 | 27 |
| 28 | 28 |
| 29 def GetScalingGovernor(device, _args): | 29 def GetScalingGovernor(device, _args): |
| 30 p = perf_control.PerfControl(device) | 30 p = perf_control.PerfControl(device) |
| 31 for cpu, governor in p.GetScalingGovernor(): | 31 for cpu, governor in p.GetScalingGovernor(): |
| 32 print '%s %s: %s' % (str(device), cpu, governor) | 32 print '%s %s: %s' % (str(device), cpu, governor) |
| 33 | 33 |
| 34 | 34 |
| 35 def ListAvailableGovernors(device, _args): | 35 def ListAvailableGovernors(device, _args): |
| 36 p = perf_control.PerfControl(device) | 36 p = perf_control.PerfControl(device) |
| 37 for cpu, governors in p.ListAvailableGovernors(): | 37 for cpu, governors in p.ListAvailableGovernors(): |
| 38 print '%s %s: %s' % (str(device), cpu, pprint.pformat(governors)) | 38 print '%s %s: %s' % (str(device), cpu, pprint.pformat(governors)) |
| 39 | 39 |
| 40 | 40 |
| 41 def main(raw_args): | 41 def main(raw_args): |
| 42 parser = argparse.ArgumentParser() | 42 parser = argparse.ArgumentParser() |
| 43 logging_common.AddLoggingArguments(parser) | |
| 44 script_common.AddEnvironmentArguments(parser) | 43 script_common.AddEnvironmentArguments(parser) |
| 45 parser.add_argument( | 44 parser.add_argument( |
| 46 '--device', dest='devices', action='append', default=[], | 45 '--device', dest='devices', action='append', default=[], |
| 47 help='Devices for which the governor should be set. Defaults to all.') | 46 help='Devices for which the governor should be set. Defaults to all.') |
| 47 parser.add_argument( |
| 48 '-v', '--verbose', action='count', |
| 49 help='Log more.') |
| 48 | 50 |
| 49 subparsers = parser.add_subparsers() | 51 subparsers = parser.add_subparsers() |
| 50 | 52 |
| 51 set_governor = subparsers.add_parser('set-governor') | 53 set_governor = subparsers.add_parser('set-governor') |
| 52 set_governor.add_argument( | 54 set_governor.add_argument( |
| 53 'governor', | 55 'governor', |
| 54 help='Desired CPU governor.') | 56 help='Desired CPU governor.') |
| 55 set_governor.set_defaults(func=SetScalingGovernor) | 57 set_governor.set_defaults(func=SetScalingGovernor) |
| 56 | 58 |
| 57 get_governor = subparsers.add_parser('get-governor') | 59 get_governor = subparsers.add_parser('get-governor') |
| 58 get_governor.set_defaults(func=GetScalingGovernor) | 60 get_governor.set_defaults(func=GetScalingGovernor) |
| 59 | 61 |
| 60 list_governors = subparsers.add_parser('list-governors') | 62 list_governors = subparsers.add_parser('list-governors') |
| 61 list_governors.set_defaults(func=ListAvailableGovernors) | 63 list_governors.set_defaults(func=ListAvailableGovernors) |
| 62 | 64 |
| 63 args = parser.parse_args(raw_args) | 65 args = parser.parse_args(raw_args) |
| 64 | 66 |
| 65 logging_common.InitializeLogging(args) | 67 run_tests_helper.SetLogLevel(args.verbose) |
| 66 script_common.InitializeEnvironment(args) | 68 script_common.InitializeEnvironment(args) |
| 67 | 69 |
| 68 devices = device_utils.DeviceUtils.HealthyDevices(device_arg=args.devices) | 70 devices = device_utils.DeviceUtils.HealthyDevices(device_arg=args.devices) |
| 69 | 71 |
| 70 parallel_devices = device_utils.DeviceUtils.parallel(devices) | 72 parallel_devices = device_utils.DeviceUtils.parallel(devices) |
| 71 parallel_devices.pMap(args.func, args) | 73 parallel_devices.pMap(args.func, args) |
| 72 | 74 |
| 73 return 0 | 75 return 0 |
| 74 | 76 |
| 75 | 77 |
| 76 if __name__ == '__main__': | 78 if __name__ == '__main__': |
| 77 sys.exit(main(sys.argv[1:])) | 79 sys.exit(main(sys.argv[1:])) |
| OLD | NEW |