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 |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
67 return callback | 67 return callback |
68 | 68 |
69 | 69 |
70 def _CreateOptionParser(): | 70 def _CreateOptionParser(): |
71 parser = optparse.OptionParser(description='Record about://tracing profiles ' | 71 parser = optparse.OptionParser(description='Record about://tracing profiles ' |
72 'from Android browsers. See http://dev.' | 72 'from Android browsers. See http://dev.' |
73 'chromium.org/developers/how-tos/trace-event-' | 73 'chromium.org/developers/how-tos/trace-event-' |
74 'profiling-tool for detailed instructions for ' | 74 'profiling-tool for detailed instructions for ' |
75 'profiling.') | 75 'profiling.') |
76 | 76 |
77 parser.add_option('--startup', help='Trace Chrome Startup. Possible values ' | |
78 'are "warm" and "cold". Cold start is done with the page ' | |
pasko
2015/01/27 12:59:00
nit: maybe rephrase:
The "warm" does not perform s
Benoit L
2015/01/27 13:50:26
Done.
| |
79 'cache flushed before, warm without. Note that "cold" ' | |
80 'requires a device with root access.', default=None) | |
81 | |
77 timed_options = optparse.OptionGroup(parser, 'Timed tracing') | 82 timed_options = optparse.OptionGroup(parser, 'Timed tracing') |
78 timed_options.add_option('-t', '--time', help='Profile for N seconds and ' | 83 timed_options.add_option('-t', '--time', help='Profile for N seconds and ' |
79 'download the resulting trace.', metavar='N', | 84 'download the resulting trace.', metavar='N', |
80 type='float') | 85 type='float') |
81 parser.add_option_group(timed_options) | 86 parser.add_option_group(timed_options) |
82 | 87 |
83 cont_options = optparse.OptionGroup(parser, 'Continuous tracing') | 88 cont_options = optparse.OptionGroup(parser, 'Continuous tracing') |
84 cont_options.add_option('--continuous', help='Profile continuously until ' | 89 cont_options.add_option('--continuous', help='Profile continuously until ' |
85 'stopped.', action='store_true') | 90 'stopped.', action='store_true') |
86 cont_options.add_option('--ring-buffer', help='Use the trace buffer as a ' | 91 cont_options.add_option('--ring-buffer', help='Use the trace buffer as a ' |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
173 | 178 |
174 if options.verbose: | 179 if options.verbose: |
175 logging.getLogger().setLevel(logging.DEBUG) | 180 logging.getLogger().setLevel(logging.DEBUG) |
176 | 181 |
177 devices = android_commands.GetAttachedDevices() | 182 devices = android_commands.GetAttachedDevices() |
178 if len(devices) != 1: | 183 if len(devices) != 1: |
179 parser.error('Exactly 1 device must be attached.') | 184 parser.error('Exactly 1 device must be attached.') |
180 device = device_utils.DeviceUtils(devices[0]) | 185 device = device_utils.DeviceUtils(devices[0]) |
181 package_info = profiler.GetSupportedBrowsers()[options.browser] | 186 package_info = profiler.GetSupportedBrowsers()[options.browser] |
182 | 187 |
188 if options.startup and options.startup not in ['cold', 'warm']: | |
Sami
2015/01/27 13:15:47
Could you use optparser's "choices" mechanism to l
Benoit L
2015/01/27 13:50:25
Didn't know about this mechanism. Thank you !
Done
| |
189 ui.PrintMessage('Startup mode should be one of ["cold", "warm"]') | |
190 return 1 | |
191 | |
183 if options.chrome_categories in ['list', 'help']: | 192 if options.chrome_categories in ['list', 'help']: |
184 ui.PrintMessage('Collecting record categories list...', eol='') | 193 ui.PrintMessage('Collecting record categories list...', eol='') |
185 record_categories = [] | 194 record_categories = [] |
186 disabled_by_default_categories = [] | 195 disabled_by_default_categories = [] |
187 record_categories, disabled_by_default_categories = \ | 196 record_categories, disabled_by_default_categories = \ |
188 chrome_controller.ChromeTracingController.GetCategories( | 197 chrome_controller.ChromeTracingController.GetCategories( |
189 device, package_info) | 198 device, package_info) |
190 | 199 |
191 ui.PrintMessage('done') | 200 ui.PrintMessage('done') |
192 ui.PrintMessage('Record Categories:') | 201 ui.PrintMessage('Record Categories:') |
(...skipping 10 matching lines...) Expand all Loading... | |
203 ui.PrintMessage('\n'.join( | 212 ui.PrintMessage('\n'.join( |
204 systrace_controller.SystraceController.GetCategories(device))) | 213 systrace_controller.SystraceController.GetCategories(device))) |
205 return 0 | 214 return 0 |
206 | 215 |
207 if (perf_controller.PerfProfilerController.IsSupported() and | 216 if (perf_controller.PerfProfilerController.IsSupported() and |
208 options.perf_categories in ['list', 'help']): | 217 options.perf_categories in ['list', 'help']): |
209 ui.PrintMessage('\n'.join( | 218 ui.PrintMessage('\n'.join( |
210 perf_controller.PerfProfilerController.GetCategories(device))) | 219 perf_controller.PerfProfilerController.GetCategories(device))) |
211 return 0 | 220 return 0 |
212 | 221 |
213 if not options.time and not options.continuous: | 222 if not options.time and not options.continuous and not options.startup: |
214 ui.PrintMessage('Time interval or continuous tracing should be specified.') | 223 ui.PrintMessage('Time interval, continuous or startup tracing should be ' |
224 'specified.') | |
215 return 1 | 225 return 1 |
216 | 226 |
217 chrome_categories = _ComputeChromeCategories(options) | 227 chrome_categories = _ComputeChromeCategories(options) |
218 systrace_categories = _ComputeSystraceCategories(options) | 228 systrace_categories = _ComputeSystraceCategories(options) |
219 perf_categories = _ComputePerfCategories(options) | 229 perf_categories = _ComputePerfCategories(options) |
220 | 230 |
221 if chrome_categories and 'webview' in systrace_categories: | 231 if chrome_categories and 'webview' in systrace_categories: |
222 logging.warning('Using the "webview" category in systrace together with ' | 232 logging.warning('Using the "webview" category in systrace together with ' |
223 'Chrome tracing results in duplicate trace events.') | 233 'Chrome tracing results in duplicate trace events.') |
224 | 234 |
225 enabled_controllers = [] | 235 enabled_controllers = [] |
236 # Systrace need to be put first, because when we profile startup, we want to | |
pasko
2015/01/27 12:59:00
nit: we usually try to avoid 'we' in the comments.
Benoit L
2015/01/27 13:50:26
Done.
| |
237 # see events from the start of execution, which is initiated in the chrome | |
238 # controller. | |
239 if systrace_categories: | |
240 enabled_controllers.append( | |
241 systrace_controller.SystraceController(device, | |
242 systrace_categories, | |
243 options.ring_buffer)) | |
244 | |
226 if chrome_categories: | 245 if chrome_categories: |
227 enabled_controllers.append( | 246 enabled_controllers.append( |
228 chrome_controller.ChromeTracingController(device, | 247 chrome_controller.ChromeTracingController(device, |
229 package_info, | 248 package_info, |
230 chrome_categories, | 249 chrome_categories, |
231 options.ring_buffer, | 250 options.ring_buffer, |
232 options.trace_memory)) | 251 options.trace_memory, |
233 if systrace_categories: | 252 options.startup)) |
234 enabled_controllers.append( | |
235 systrace_controller.SystraceController(device, | |
236 systrace_categories, | |
237 options.ring_buffer)) | |
238 | |
239 if perf_categories: | 253 if perf_categories: |
240 enabled_controllers.append( | 254 enabled_controllers.append( |
241 perf_controller.PerfProfilerController(device, | 255 perf_controller.PerfProfilerController(device, |
242 perf_categories)) | 256 perf_categories)) |
243 | 257 |
244 if not enabled_controllers: | 258 if not enabled_controllers: |
245 ui.PrintMessage('No trace categories enabled.') | 259 ui.PrintMessage('No trace categories enabled.') |
246 return 1 | 260 return 1 |
247 | 261 |
248 if options.output: | 262 if options.output: |
249 options.output = os.path.expanduser(options.output) | 263 options.output = os.path.expanduser(options.output) |
250 result = profiler.CaptureProfile( | 264 result = profiler.CaptureProfile( |
251 enabled_controllers, | 265 enabled_controllers, |
252 options.time if not options.continuous else 0, | 266 options.time if options.time else 0, |
Sami
2015/01/27 13:15:47
Why this change?
Benoit L
2015/01/27 13:50:26
Because options.time is None when options.continuo
| |
253 output=options.output, | 267 output=options.output, |
254 compress=options.compress, | 268 compress=options.compress, |
255 write_json=options.json) | 269 write_json=options.json) |
256 if options.view: | 270 if options.view: |
257 if sys.platform == 'darwin': | 271 if sys.platform == 'darwin': |
258 os.system('/usr/bin/open %s' % os.path.abspath(result)) | 272 os.system('/usr/bin/open %s' % os.path.abspath(result)) |
259 else: | 273 else: |
260 webbrowser.open(result) | 274 webbrowser.open(result) |
OLD | NEW |