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 |
11 import webbrowser | 11 import webbrowser |
12 | 12 |
13 _SYSTRACE_DIR = os.path.abspath(os.path.join(os.path.dirname(__file__), '..')) | 13 _SYSTRACE_DIR = os.path.abspath(os.path.join(os.path.dirname(__file__), '..')) |
14 sys.path.append(_SYSTRACE_DIR) | 14 sys.path.append(_SYSTRACE_DIR) |
15 | 15 |
16 from profile_chrome import atrace_tracing_agent | 16 from profile_chrome import atrace_tracing_agent |
17 from profile_chrome import chrome_startup_tracing_agent | 17 from profile_chrome import chrome_startup_tracing_agent |
18 from profile_chrome import flags | 18 from profile_chrome import flags |
19 from profile_chrome import profiler | 19 from profile_chrome import profiler |
20 from profile_chrome import ui | 20 from profile_chrome import ui |
21 | 21 |
22 _CATAPULT_DIR = os.path.join( | 22 _CATAPULT_DIR = os.path.join( |
23 os.path.dirname(os.path.abspath(__file__)), '..', '..') | 23 os.path.dirname(os.path.abspath(__file__)), '..', '..') |
24 sys.path.append(os.path.join(_CATAPULT_DIR, 'devil')) | 24 sys.path.append(os.path.join(_CATAPULT_DIR, 'devil')) |
25 | 25 |
26 from devil.android import device_utils | 26 from devil.android import device_utils |
27 | 27 |
28 | 28 |
29 _DEFAULT_CHROME_CATEGORIES = '_DEFAULT_CHROME_CATEGORIES' | |
30 | |
31 | |
29 def _CreateOptionParser(): | 32 def _CreateOptionParser(): |
30 parser = optparse.OptionParser(description='Record about://tracing profiles ' | 33 parser = optparse.OptionParser(description='Record about://tracing profiles ' |
31 'from Android browsers startup, combined with ' | 34 'from Android browsers startup, combined with ' |
32 'Android systrace. See http://dev.chromium.org' | 35 'Android systrace. See http://dev.chromium.org' |
33 '/developers/how-tos/trace-event-profiling-' | 36 '/developers/how-tos/trace-event-profiling-' |
34 'tool for detailed instructions for ' | 37 'tool for detailed instructions for ' |
35 'profiling.') | 38 'profiling.') |
36 | 39 |
37 browsers = sorted(profiler.GetSupportedBrowsers().keys()) | 40 browsers = sorted(profiler.GetSupportedBrowsers().keys()) |
38 parser.add_option('-b', '--browser', help='Select among installed browsers. ' | 41 parser.add_option('-b', '--browser', help='Select among installed browsers. ' |
39 'One of ' + ', '.join(browsers) + ', "stable" is used by ' | 42 'One of ' + ', '.join(browsers) + ', "stable" is used by ' |
40 'default.', type='choice', choices=browsers, | 43 'default.', type='choice', choices=browsers, |
41 default='stable') | 44 default='stable') |
42 parser.add_option('-v', '--verbose', help='Verbose logging.', | 45 parser.add_option('-v', '--verbose', help='Verbose logging.', |
43 action='store_true') | 46 action='store_true') |
44 parser.add_option('-z', '--compress', help='Compress the resulting trace ' | 47 parser.add_option('-z', '--compress', help='Compress the resulting trace ' |
45 'with gzip. ', action='store_true') | 48 'with gzip. ', action='store_true') |
46 parser.add_option('-t', '--time', help='Stops tracing after N seconds, 0 to ' | 49 parser.add_option('-t', '--time', help='Stops tracing after N seconds, 0 to ' |
47 'manually stop (startup trace ends after at most 5s).', | 50 'manually stop (startup trace ends after at most 5s).', |
48 default=5, metavar='N', type='int') | 51 default=5, metavar='N', type='int', dest='trace_time') |
49 | 52 |
50 parser.add_option_group(chrome_startup_tracing_agent.add_options(parser)) | 53 parser.add_option_group(chrome_startup_tracing_agent.add_options(parser)) |
51 parser.add_option_group(atrace_tracing_agent.add_options(parser)) | 54 parser.add_option_group(atrace_tracing_agent.add_options(parser)) |
52 parser.add_option_group(flags.OutputOptions(parser)) | 55 parser.add_option_group(flags.OutputOptions(parser)) |
53 | 56 |
54 return parser | 57 return parser |
55 | 58 |
56 | 59 |
57 def main(): | 60 def main(): |
58 parser = _CreateOptionParser() | 61 parser = _CreateOptionParser() |
59 options, _ = parser.parse_args() | 62 options, _ = parser.parse_args() |
60 | 63 |
61 if options.verbose: | 64 if options.verbose: |
62 logging.getLogger().setLevel(logging.DEBUG) | 65 logging.getLogger().setLevel(logging.DEBUG) |
63 | 66 |
64 devices = device_utils.DeviceUtils.HealthyDevices() | 67 devices = device_utils.DeviceUtils.HealthyDevices() |
65 if len(devices) != 1: | 68 if len(devices) != 1: |
66 logging.error('Exactly 1 device must be attached.') | 69 logging.error('Exactly 1 device must be attached.') |
67 return 1 | 70 return 1 |
68 device = devices[0] | 71 device = devices[0] |
69 package_info = profiler.GetSupportedBrowsers()[options.browser] | 72 package_info = profiler.GetSupportedBrowsers()[options.browser] |
70 | 73 |
74 options.chrome_startup = True | |
Sami
2016/09/01 12:15:59
Why are we overriding the options set by the user
washingtonp
2016/09/01 17:44:41
adb_profile_chrome_startup does not provide the us
Sami
2016/09/02 12:57:42
My worry is that in 1) the list will quickly get o
washingtonp
2016/09/02 20:10:27
I like that idea, and have implemented it in the m
| |
75 options.device = device | |
76 options.package_info = package_info | |
77 options.ring_buffer = False | |
78 options.trace_memory = False | |
79 options.trace_cc = None | |
80 options.trace_frame_viewer = None | |
81 options.trace_ubercompositor = None | |
82 options.trace_gpu = None | |
83 options.trace_flow = None | |
84 options.trace_scheduler = None | |
85 options.ddms = None | |
86 options.perf_categories = None | |
87 options.list_categories = None | |
88 options.link_assets = None | |
89 options.asset_dir = None | |
90 options.timeout = None | |
91 options.collection_timeout = None | |
92 options.device_serial_number = device | |
93 options.target = None | |
94 options.chrome_categories = _DEFAULT_CHROME_CATEGORIES | |
95 if options.output_file: | |
96 options.output_file = os.path.expanduser(options.output_file) | |
97 | |
71 if options.atrace_categories in ['list', 'help']: | 98 if options.atrace_categories in ['list', 'help']: |
72 ui.PrintMessage('\n'.join( | 99 ui.PrintMessage('\n'.join( |
73 atrace_tracing_agent.AtraceAgent.GetCategories(device))) | 100 atrace_tracing_agent.AtraceAgent.GetCategories(device))) |
74 return 0 | 101 return 0 |
75 atrace_categories = (options.atrace_categories.split(',') | |
76 if options.atrace_categories else []) | |
77 enabled_agents = [] | |
78 # Enable the atrace and chrome agents. The atrace agent should go | |
79 # first because otherwise the resulting traces miss early atrace data. | |
80 if atrace_categories: | |
81 enabled_agents.append(atrace_tracing_agent.AtraceAgent( | |
82 device, atrace_categories, False)) | |
83 enabled_agents.append( | |
84 chrome_startup_tracing_agent.ChromeStartupTracingAgent( | |
85 device, package_info, options.cold, options.url)) | |
86 if options.output: | |
87 options.output = os.path.expanduser(options.output) | |
88 result = profiler.CaptureProfile(options, | 102 result = profiler.CaptureProfile(options, |
89 enabled_agents, | 103 options.trace_time, |
90 options.time, | 104 output=options.output_file, |
91 output=options.output, | |
92 compress=options.compress, | 105 compress=options.compress, |
93 write_json=options.json) | 106 write_json=options.write_json) |
94 if options.view: | 107 if options.view: |
95 if sys.platform == 'darwin': | 108 if sys.platform == 'darwin': |
96 os.system('/usr/bin/open %s' % os.path.abspath(result)) | 109 os.system('/usr/bin/open %s' % os.path.abspath(result)) |
97 else: | 110 else: |
98 webbrowser.open(result) | 111 webbrowser.open(result) |
99 | 112 |
100 | 113 |
101 if __name__ == '__main__': | 114 if __name__ == '__main__': |
102 sys.exit(main()) | 115 sys.exit(main()) |
OLD | NEW |