michael@0: #!/usr/bin/env python michael@0: # michael@0: # Copyright (c) 2012 The Chromium Authors. All rights reserved. michael@0: # Use of this source code is governed by a BSD-style license that can be michael@0: # found in the LICENSE file. michael@0: michael@0: """Provides iotop/top style profiling for android. michael@0: michael@0: Usage: michael@0: ./device_stats_monitor.py --hz=20 --duration=5 --outfile=/tmp/foo michael@0: """ michael@0: michael@0: import optparse michael@0: import os michael@0: import sys michael@0: import time michael@0: michael@0: from pylib import android_commands michael@0: from pylib import device_stats_monitor michael@0: from pylib import test_options_parser michael@0: michael@0: michael@0: def main(argv): michael@0: option_parser = optparse.OptionParser() michael@0: option_parser.add_option('--hz', type='int', default=20, michael@0: help='Number of samples/sec.') michael@0: option_parser.add_option('--duration', type='int', default=5, michael@0: help='Seconds to monitor.') michael@0: option_parser.add_option('--outfile', default='/tmp/devicestatsmonitor', michael@0: help='Location to start output file.') michael@0: test_options_parser.AddBuildTypeOption(option_parser) michael@0: options, args = option_parser.parse_args(argv) michael@0: michael@0: monitor = device_stats_monitor.DeviceStatsMonitor( michael@0: android_commands.AndroidCommands(), options.hz, options.build_type) michael@0: monitor.Start() michael@0: print 'Waiting for %d seconds while profiling.' % options.duration michael@0: time.sleep(options.duration) michael@0: url = monitor.StopAndCollect(options.outfile) michael@0: print 'View results in browser at %s' % url michael@0: michael@0: if __name__ == '__main__': michael@0: sys.exit(main(sys.argv))