OLD | NEW |
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # | 2 # |
3 # Copyright 2015 The Chromium Authors. All rights reserved. | 3 # Copyright 2015 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 import logging | 7 import logging |
8 import optparse | 8 import optparse |
9 import os | 9 import os |
10 import sys | 10 import sys |
(...skipping 15 matching lines...) Expand all Loading... |
26 from devil.android import device_utils | 26 from devil.android import device_utils |
27 | 27 |
28 | 28 |
29 def _CreateOptionParser(): | 29 def _CreateOptionParser(): |
30 parser = optparse.OptionParser(description='Record about://tracing profiles ' | 30 parser = optparse.OptionParser(description='Record about://tracing profiles ' |
31 'from Android browsers startup, combined with ' | 31 'from Android browsers startup, combined with ' |
32 'Android systrace. See http://dev.chromium.org' | 32 'Android systrace. See http://dev.chromium.org' |
33 '/developers/how-tos/trace-event-profiling-' | 33 '/developers/how-tos/trace-event-profiling-' |
34 'tool for detailed instructions for ' | 34 'tool for detailed instructions for ' |
35 'profiling.') | 35 'profiling.') |
36 parser.add_option('--url', help='URL to visit on startup. Default: ' | |
37 'https://www.google.com. An empty URL launches Chrome with' | |
38 ' a MAIN action instead of VIEW.', | |
39 default='https://www.google.com', metavar='URL') | |
40 parser.add_option('--cold', help='Flush the OS page cache before starting the' | |
41 ' browser. Note that this require a device with root ' | |
42 'access.', default=False, action='store_true') | |
43 parser.add_option_group(flags.AtraceOptions(parser)) | |
44 parser.add_option_group(flags.OutputOptions(parser)) | |
45 | 36 |
46 browsers = sorted(profiler.GetSupportedBrowsers().keys()) | 37 browsers = sorted(profiler.GetSupportedBrowsers().keys()) |
47 parser.add_option('-b', '--browser', help='Select among installed browsers. ' | 38 parser.add_option('-b', '--browser', help='Select among installed browsers. ' |
48 'One of ' + ', '.join(browsers) + ', "stable" is used by ' | 39 'One of ' + ', '.join(browsers) + ', "stable" is used by ' |
49 'default.', type='choice', choices=browsers, | 40 'default.', type='choice', choices=browsers, |
50 default='stable') | 41 default='stable') |
51 parser.add_option('-v', '--verbose', help='Verbose logging.', | 42 parser.add_option('-v', '--verbose', help='Verbose logging.', |
52 action='store_true') | 43 action='store_true') |
53 parser.add_option('-z', '--compress', help='Compress the resulting trace ' | 44 parser.add_option('-z', '--compress', help='Compress the resulting trace ' |
54 'with gzip. ', action='store_true') | 45 'with gzip. ', action='store_true') |
55 parser.add_option('-t', '--time', help='Stops tracing after N seconds, 0 to ' | 46 parser.add_option('-t', '--time', help='Stops tracing after N seconds, 0 to ' |
56 'manually stop (startup trace ends after at most 5s).', | 47 'manually stop (startup trace ends after at most 5s).', |
57 default=5, metavar='N', type='int') | 48 default=5, metavar='N', type='int') |
| 49 |
| 50 parser.add_option_group(chrome_startup_tracing_agent.add_options(parser)) |
| 51 parser.add_option_group(atrace_tracing_agent.add_options(parser)) |
| 52 parser.add_option_group(flags.OutputOptions(parser)) |
| 53 |
58 return parser | 54 return parser |
59 | 55 |
60 | 56 |
61 def main(): | 57 def main(): |
62 parser = _CreateOptionParser() | 58 parser = _CreateOptionParser() |
63 options, _ = parser.parse_args() | 59 options, _ = parser.parse_args() |
64 | 60 |
65 if options.verbose: | 61 if options.verbose: |
66 logging.getLogger().setLevel(logging.DEBUG) | 62 logging.getLogger().setLevel(logging.DEBUG) |
67 | 63 |
(...skipping 14 matching lines...) Expand all Loading... |
82 # Enable the atrace and chrome agents. The atrace agent should go | 78 # Enable the atrace and chrome agents. The atrace agent should go |
83 # first because otherwise the resulting traces miss early atrace data. | 79 # first because otherwise the resulting traces miss early atrace data. |
84 if atrace_categories: | 80 if atrace_categories: |
85 enabled_agents.append(atrace_tracing_agent.AtraceAgent( | 81 enabled_agents.append(atrace_tracing_agent.AtraceAgent( |
86 device, atrace_categories, False)) | 82 device, atrace_categories, False)) |
87 enabled_agents.append( | 83 enabled_agents.append( |
88 chrome_startup_tracing_agent.ChromeStartupTracingAgent( | 84 chrome_startup_tracing_agent.ChromeStartupTracingAgent( |
89 device, package_info, options.cold, options.url)) | 85 device, package_info, options.cold, options.url)) |
90 if options.output: | 86 if options.output: |
91 options.output = os.path.expanduser(options.output) | 87 options.output = os.path.expanduser(options.output) |
92 result = profiler.CaptureProfile(enabled_agents, | 88 result = profiler.CaptureProfile(options, |
| 89 enabled_agents, |
93 options.time, | 90 options.time, |
94 output=options.output, | 91 output=options.output, |
95 compress=options.compress, | 92 compress=options.compress, |
96 write_json=options.json) | 93 write_json=options.json) |
97 if options.view: | 94 if options.view: |
98 if sys.platform == 'darwin': | 95 if sys.platform == 'darwin': |
99 os.system('/usr/bin/open %s' % os.path.abspath(result)) | 96 os.system('/usr/bin/open %s' % os.path.abspath(result)) |
100 else: | 97 else: |
101 webbrowser.open(result) | 98 webbrowser.open(result) |
102 | 99 |
103 | 100 |
104 if __name__ == '__main__': | 101 if __name__ == '__main__': |
105 sys.exit(main()) | 102 sys.exit(main()) |
OLD | NEW |