OLD | NEW |
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # | 2 # |
3 # Copyright 2014 The Chromium Authors. All rights reserved. | 3 # Copyright 2014 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 from profile_chrome import chrome_tracing_agent | 13 from profile_chrome import chrome_tracing_agent |
14 from profile_chrome import ddms_tracing_agent | 14 from profile_chrome import ddms_tracing_agent |
15 from profile_chrome import flags | 15 from profile_chrome import flags |
16 from profile_chrome import perf_tracing_agent | 16 from profile_chrome import perf_tracing_agent |
17 from profile_chrome import profiler | 17 from profile_chrome import profiler |
18 from profile_chrome import atrace_tracing_agent | 18 from profile_chrome import atrace_tracing_agent |
19 from profile_chrome import ui | 19 from profile_chrome import ui |
20 | 20 |
21 from devil.android import device_utils | 21 from devil.android import device_utils |
22 | 22 |
23 | 23 |
24 PROFILE_CHROME_AGENT_MODULES = [chrome_tracing_agent, ddms_tracing_agent, | 24 _PROFILE_CHROME_AGENT_MODULES = [chrome_tracing_agent, ddms_tracing_agent, |
25 perf_tracing_agent, atrace_tracing_agent] | 25 perf_tracing_agent, atrace_tracing_agent] |
26 | 26 |
27 | 27 |
28 def _CreateOptionParser(): | 28 def _CreateOptionParser(): |
29 parser = optparse.OptionParser(description='Record about://tracing profiles ' | 29 parser = optparse.OptionParser(description='Record about://tracing profiles ' |
30 'from Android browsers. See http://dev.' | 30 'from Android browsers. See http://dev.' |
31 'chromium.org/developers/how-tos/trace-event-' | 31 'chromium.org/developers/how-tos/trace-event-' |
32 'profiling-tool for detailed instructions for ' | 32 'profiling-tool for detailed instructions for ' |
33 'profiling.') | 33 'profiling.') |
34 | 34 |
35 timed_options = optparse.OptionGroup(parser, 'Timed tracing') | 35 timed_options = optparse.OptionGroup(parser, 'Timed tracing') |
36 timed_options.add_option('-t', '--time', help='Profile for N seconds and ' | 36 timed_options.add_option('-t', '--time', help='Profile for N seconds and ' |
37 'download the resulting trace.', metavar='N', | 37 'download the resulting trace.', metavar='N', |
38 type='float') | 38 type='float', dest='trace_time') |
39 parser.add_option_group(timed_options) | 39 parser.add_option_group(timed_options) |
40 | 40 |
41 cont_options = optparse.OptionGroup(parser, 'Continuous tracing') | 41 cont_options = optparse.OptionGroup(parser, 'Continuous tracing') |
42 cont_options.add_option('--continuous', help='Profile continuously until ' | 42 cont_options.add_option('--continuous', help='Profile continuously until ' |
43 'stopped.', action='store_true') | 43 'stopped.', action='store_true') |
44 cont_options.add_option('--ring-buffer', help='Use the trace buffer as a ' | 44 cont_options.add_option('--ring-buffer', help='Use the trace buffer as a ' |
45 'ring buffer and save its contents when stopping ' | 45 'ring buffer and save its contents when stopping ' |
46 'instead of appending events into one long trace.', | 46 'instead of appending events into one long trace.', |
47 action='store_true') | 47 action='store_true') |
48 parser.add_option_group(cont_options) | 48 parser.add_option_group(cont_options) |
49 | 49 |
50 parser.add_option_group(flags.OutputOptions(parser)) | 50 parser.add_option_group(flags.OutputOptions(parser)) |
51 | 51 |
52 browsers = sorted(profiler.GetSupportedBrowsers().keys()) | 52 browsers = sorted(profiler.GetSupportedBrowsers().keys()) |
53 parser.add_option('-b', '--browser', help='Select among installed browsers. ' | 53 parser.add_option('-b', '--browser', help='Select among installed browsers. ' |
54 'One of ' + ', '.join(browsers) + ', "stable" is used by ' | 54 'One of ' + ', '.join(browsers) + ', "stable" is used by ' |
55 'default.', type='choice', choices=browsers, | 55 'default.', type='choice', choices=browsers, |
56 default='stable') | 56 default='stable') |
57 parser.add_option('-v', '--verbose', help='Verbose logging.', | 57 parser.add_option('-v', '--verbose', help='Verbose logging.', |
58 action='store_true') | 58 action='store_true') |
59 parser.add_option('-z', '--compress', help='Compress the resulting trace ' | 59 parser.add_option('-z', '--compress', help='Compress the resulting trace ' |
60 'with gzip. ', action='store_true') | 60 'with gzip. ', action='store_true') |
61 parser.add_option('-d', '--device', help='The Android device ID to use, ' | 61 parser.add_option('-d', '--device', help='The Android device ID to use, ' |
62 'defaults to the value of ANDROID_SERIAL environment ' | 62 'defaults to the value of ANDROID_SERIAL environment ' |
63 'variable. If not specified, only 0 or 1 connected ' | 63 'variable. If not specified, only 0 or 1 connected ' |
64 'devices are supported.') | 64 'devices are supported.', dest='device_serial_number') |
65 | 65 |
66 # Add options from profile_chrome agents. | 66 # Add options from profile_chrome agents. |
67 for module in PROFILE_CHROME_AGENT_MODULES: | 67 for module in _PROFILE_CHROME_AGENT_MODULES: |
68 parser.add_option_group(module.add_options(parser)) | 68 parser.add_option_group(module.add_options(parser)) |
69 | 69 |
70 return parser | 70 return parser |
71 | 71 |
72 | 72 |
73 def main(): | 73 def main(): |
74 parser = _CreateOptionParser() | 74 parser = _CreateOptionParser() |
75 options, _args = parser.parse_args() # pylint: disable=unused-variable | 75 options, _args = parser.parse_args() # pylint: disable=unused-variable |
76 if options.trace_cc: | 76 if options.trace_cc: |
77 parser.error("""--trace-cc is deprecated. | 77 parser.error("""--trace-cc is deprecated. |
78 | 78 |
79 For basic jank busting uses, use --trace-frame-viewer | 79 For basic jank busting uses, use --trace-frame-viewer |
80 For detailed study of ubercompositor, pass --trace-ubercompositor. | 80 For detailed study of ubercompositor, pass --trace-ubercompositor. |
81 | 81 |
82 When in doubt, just try out --trace-frame-viewer. | 82 When in doubt, just try out --trace-frame-viewer. |
83 """) | 83 """) |
84 | 84 |
85 if options.verbose: | 85 if options.verbose: |
86 logging.getLogger().setLevel(logging.DEBUG) | 86 logging.getLogger().setLevel(logging.DEBUG) |
87 | 87 |
88 device = device_utils.DeviceUtils.HealthyDevices(device_arg=options.device)[0] | 88 device = device_utils.DeviceUtils.HealthyDevices(device_arg= |
| 89 options.device_serial_number)[0] |
89 package_info = profiler.GetSupportedBrowsers()[options.browser] | 90 package_info = profiler.GetSupportedBrowsers()[options.browser] |
90 | 91 |
| 92 options.device = device |
| 93 options.package_info = package_info |
| 94 |
| 95 # Add options that are present in Systrace but not in profile_chrome (since |
| 96 # they both use the same tracing controller). |
| 97 # TODO(washingtonp): Once Systrace uses all of the profile_chrome agents, |
| 98 # manually setting these options will no longer be necessary and should be |
| 99 # removed. |
| 100 options.list_categories = None |
| 101 options.link_assets = None |
| 102 options.asset_dir = None |
| 103 options.timeout = None |
| 104 options.collection_timeout = None |
| 105 options.target = None |
| 106 |
91 if options.chrome_categories in ['list', 'help']: | 107 if options.chrome_categories in ['list', 'help']: |
92 ui.PrintMessage('Collecting record categories list...', eol='') | 108 ui.PrintMessage('Collecting record categories list...', eol='') |
93 record_categories = [] | 109 record_categories = [] |
94 disabled_by_default_categories = [] | 110 disabled_by_default_categories = [] |
95 record_categories, disabled_by_default_categories = \ | 111 record_categories, disabled_by_default_categories = \ |
96 chrome_tracing_agent.ChromeTracingAgent.GetCategories( | 112 chrome_tracing_agent.ChromeTracingAgent.GetCategories( |
97 device, package_info) | 113 device, package_info) |
98 | 114 |
99 ui.PrintMessage('done') | 115 ui.PrintMessage('done') |
100 ui.PrintMessage('Record Categories:') | 116 ui.PrintMessage('Record Categories:') |
(...skipping 10 matching lines...) Expand all Loading... |
111 ui.PrintMessage('\n'.join( | 127 ui.PrintMessage('\n'.join( |
112 atrace_tracing_agent.AtraceAgent.GetCategories(device))) | 128 atrace_tracing_agent.AtraceAgent.GetCategories(device))) |
113 return 0 | 129 return 0 |
114 | 130 |
115 if (perf_tracing_agent.PerfProfilerAgent.IsSupported() and | 131 if (perf_tracing_agent.PerfProfilerAgent.IsSupported() and |
116 options.perf_categories in ['list', 'help']): | 132 options.perf_categories in ['list', 'help']): |
117 ui.PrintMessage('\n'.join( | 133 ui.PrintMessage('\n'.join( |
118 perf_tracing_agent.PerfProfilerAgent.GetCategories(device))) | 134 perf_tracing_agent.PerfProfilerAgent.GetCategories(device))) |
119 return 0 | 135 return 0 |
120 | 136 |
121 if not options.time and not options.continuous: | 137 if not options.trace_time and not options.continuous: |
122 ui.PrintMessage('Time interval or continuous tracing should be specified.') | 138 ui.PrintMessage('Time interval or continuous tracing should be specified.') |
123 return 1 | 139 return 1 |
124 | 140 |
125 if options.chrome_categories and 'webview' in options.atrace_categories: | 141 if options.chrome_categories and 'webview' in options.atrace_categories: |
126 logging.warning('Using the "webview" category in atrace together with ' | 142 logging.warning('Using the "webview" category in atrace together with ' |
127 'Chrome tracing results in duplicate trace events.') | 143 'Chrome tracing results in duplicate trace events.') |
128 | 144 |
129 enabled_agents = [] | 145 if options.output_file: |
130 if options.chrome_categories: | 146 options.output_file = os.path.expanduser(options.output_file) |
131 enabled_agents.append( | |
132 chrome_tracing_agent.ChromeTracingAgent(device, | |
133 package_info, | |
134 options.ring_buffer, | |
135 options.trace_memory)) | |
136 if options.atrace_categories: | |
137 enabled_agents.append( | |
138 atrace_tracing_agent.AtraceAgent(device, | |
139 options.ring_buffer)) | |
140 | |
141 if options.perf_categories: | |
142 enabled_agents.append( | |
143 perf_tracing_agent.PerfProfilerAgent(device)) | |
144 | |
145 if options.ddms: | |
146 enabled_agents.append( | |
147 ddms_tracing_agent.DdmsAgent(device, | |
148 package_info)) | |
149 | |
150 if not enabled_agents: | |
151 ui.PrintMessage('No trace categories enabled.') | |
152 return 1 | |
153 | |
154 if options.output: | |
155 options.output = os.path.expanduser(options.output) | |
156 result = profiler.CaptureProfile( | 147 result = profiler.CaptureProfile( |
157 options, | 148 options, |
158 enabled_agents, | 149 options.trace_time if not options.continuous else 0, |
159 options.time if not options.continuous else 0, | 150 _PROFILE_CHROME_AGENT_MODULES, |
160 output=options.output, | 151 output=options.output_file, |
161 compress=options.compress, | 152 compress=options.compress, |
162 write_json=options.json) | 153 write_json=options.write_json) |
163 if options.view: | 154 if options.view: |
164 if sys.platform == 'darwin': | 155 if sys.platform == 'darwin': |
165 os.system('/usr/bin/open %s' % os.path.abspath(result)) | 156 os.system('/usr/bin/open %s' % os.path.abspath(result)) |
166 else: | 157 else: |
167 webbrowser.open(result) | 158 webbrowser.open(result) |
OLD | NEW |