• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#! /usr/bin/env python
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
4# found in the LICENSE file.
5
6"""A script to manipulate device CPU frequency."""
7
8import argparse
9import os
10import pprint
11import sys
12
13if __name__ == '__main__':
14  sys.path.append(
15      os.path.abspath(os.path.join(os.path.dirname(__file__),
16                                   '..', '..', '..')))
17
18from devil import devil_env
19from devil.android import device_utils
20from devil.android.perf import perf_control
21from devil.utils import run_tests_helper
22
23
24def SetScalingGovernor(device, args):
25  p = perf_control.PerfControl(device)
26  p.SetScalingGovernor(args.governor)
27
28
29def GetScalingGovernor(device, _args):
30  p = perf_control.PerfControl(device)
31  for cpu, governor in p.GetScalingGovernor():
32    print '%s %s: %s' % (str(device), cpu, governor)
33
34
35def ListAvailableGovernors(device, _args):
36  p = perf_control.PerfControl(device)
37  for cpu, governors in p.ListAvailableGovernors():
38    print '%s %s: %s' % (str(device), cpu, pprint.pformat(governors))
39
40
41def main(raw_args):
42  parser = argparse.ArgumentParser()
43  parser.add_argument(
44      '--adb-path',
45      help='ADB binary path.')
46  parser.add_argument(
47      '--device', dest='devices', action='append', default=[],
48      help='Devices for which the governor should be set. Defaults to all.')
49  parser.add_argument(
50      '-v', '--verbose', action='count',
51      help='Log more.')
52
53  subparsers = parser.add_subparsers()
54
55  set_governor = subparsers.add_parser('set-governor')
56  set_governor.add_argument(
57      'governor',
58      help='Desired CPU governor.')
59  set_governor.set_defaults(func=SetScalingGovernor)
60
61  get_governor = subparsers.add_parser('get-governor')
62  get_governor.set_defaults(func=GetScalingGovernor)
63
64  list_governors = subparsers.add_parser('list-governors')
65  list_governors.set_defaults(func=ListAvailableGovernors)
66
67  args = parser.parse_args(raw_args)
68
69  run_tests_helper.SetLogLevel(args.verbose)
70
71  devil_dynamic_config = devil_env.EmptyConfig()
72  if args.adb_path:
73    devil_dynamic_config['dependencies'].update(
74        devil_env.LocalConfigItem(
75            'adb', devil_env.GetPlatform(), args.adb_path))
76  devil_env.config.Initialize(configs=[devil_dynamic_config])
77
78  devices = device_utils.DeviceUtils.HealthyDevices(device_arg=args.devices)
79
80  parallel_devices = device_utils.DeviceUtils.parallel(devices)
81  parallel_devices.pMap(args.func, args)
82
83  return 0
84
85
86if __name__ == '__main__':
87  sys.exit(main(sys.argv[1:]))
88