OLD | NEW |
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # | 2 # |
3 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 3 # Copyright (c) 2012 The Chromium Authors. All rights reserved. |
4 # Use of this source code is governed by a BSD-style license that can be | 4 # Use of this source code is governed by a BSD-style license that can be |
5 # found in the LICENSE file. | 5 # found in the LICENSE file. |
6 | 6 |
7 """Provides iotop/top style profiling for android. | 7 """Provides iotop/top style profiling for android. |
8 | 8 |
9 Usage: | 9 Usage: |
10 ./device_stats_monitor.py --hz=20 --duration=5 --outfile=/tmp/foo | 10 ./device_stats_monitor.py --hz=20 --duration=5 --outfile=/tmp/foo |
11 """ | 11 """ |
12 | 12 |
13 import optparse | 13 import optparse |
14 import os | 14 import os |
15 import sys | 15 import sys |
16 import time | 16 import time |
17 | 17 |
18 from pylib import android_commands | 18 from pylib import android_commands |
19 from pylib import device_stats_monitor | 19 from pylib import device_stats_monitor |
20 from pylib import test_options_parser | 20 from pylib.utils import test_options_parser |
21 | 21 |
22 | 22 |
23 def main(argv): | 23 def main(argv): |
24 option_parser = optparse.OptionParser() | 24 option_parser = optparse.OptionParser() |
25 option_parser.add_option('--hz', type='int', default=20, | 25 option_parser.add_option('--hz', type='int', default=20, |
26 help='Number of samples/sec.') | 26 help='Number of samples/sec.') |
27 option_parser.add_option('--duration', type='int', default=5, | 27 option_parser.add_option('--duration', type='int', default=5, |
28 help='Seconds to monitor.') | 28 help='Seconds to monitor.') |
29 option_parser.add_option('--outfile', default='/tmp/devicestatsmonitor', | 29 option_parser.add_option('--outfile', default='/tmp/devicestatsmonitor', |
30 help='Location to start output file.') | 30 help='Location to start output file.') |
31 test_options_parser.AddBuildTypeOption(option_parser) | 31 test_options_parser.AddBuildTypeOption(option_parser) |
32 options, args = option_parser.parse_args(argv) | 32 options, args = option_parser.parse_args(argv) |
33 | 33 |
34 monitor = device_stats_monitor.DeviceStatsMonitor( | 34 monitor = device_stats_monitor.DeviceStatsMonitor( |
35 android_commands.AndroidCommands(), options.hz, options.build_type) | 35 android_commands.AndroidCommands(), options.hz, options.build_type) |
36 monitor.Start() | 36 monitor.Start() |
37 print 'Waiting for %d seconds while profiling.' % options.duration | 37 print 'Waiting for %d seconds while profiling.' % options.duration |
38 time.sleep(options.duration) | 38 time.sleep(options.duration) |
39 url = monitor.StopAndCollect(options.outfile) | 39 url = monitor.StopAndCollect(options.outfile) |
40 print 'View results in browser at %s' % url | 40 print 'View results in browser at %s' % url |
41 | 41 |
42 if __name__ == '__main__': | 42 if __name__ == '__main__': |
43 sys.exit(main(sys.argv)) | 43 sys.exit(main(sys.argv)) |
OLD | NEW |