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". The "warm" start does not perform ' |
| 79 'special steps, while the "cols" flushes the OS page cache ' |
| 80 'before start. Note that "cold" requires a device with root' |
| 81 ' access.', default=None, choices=['warm', 'cold']) |
| 82 |
77 timed_options = optparse.OptionGroup(parser, 'Timed tracing') | 83 timed_options = optparse.OptionGroup(parser, 'Timed tracing') |
78 timed_options.add_option('-t', '--time', help='Profile for N seconds and ' | 84 timed_options.add_option('-t', '--time', help='Profile for N seconds and ' |
79 'download the resulting trace.', metavar='N', | 85 'download the resulting trace.', metavar='N', |
80 type='float') | 86 type='float') |
81 parser.add_option_group(timed_options) | 87 parser.add_option_group(timed_options) |
82 | 88 |
83 cont_options = optparse.OptionGroup(parser, 'Continuous tracing') | 89 cont_options = optparse.OptionGroup(parser, 'Continuous tracing') |
84 cont_options.add_option('--continuous', help='Profile continuously until ' | 90 cont_options.add_option('--continuous', help='Profile continuously until ' |
85 'stopped.', action='store_true') | 91 'stopped.', action='store_true') |
86 cont_options.add_option('--ring-buffer', help='Use the trace buffer as a ' | 92 cont_options.add_option('--ring-buffer', help='Use the trace buffer as a ' |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
203 ui.PrintMessage('\n'.join( | 209 ui.PrintMessage('\n'.join( |
204 systrace_controller.SystraceController.GetCategories(device))) | 210 systrace_controller.SystraceController.GetCategories(device))) |
205 return 0 | 211 return 0 |
206 | 212 |
207 if (perf_controller.PerfProfilerController.IsSupported() and | 213 if (perf_controller.PerfProfilerController.IsSupported() and |
208 options.perf_categories in ['list', 'help']): | 214 options.perf_categories in ['list', 'help']): |
209 ui.PrintMessage('\n'.join( | 215 ui.PrintMessage('\n'.join( |
210 perf_controller.PerfProfilerController.GetCategories(device))) | 216 perf_controller.PerfProfilerController.GetCategories(device))) |
211 return 0 | 217 return 0 |
212 | 218 |
213 if not options.time and not options.continuous: | 219 if not options.time and not options.continuous and not options.startup: |
214 ui.PrintMessage('Time interval or continuous tracing should be specified.') | 220 ui.PrintMessage('Time interval, continuous or startup tracing should be ' |
| 221 'specified.') |
215 return 1 | 222 return 1 |
216 | 223 |
217 chrome_categories = _ComputeChromeCategories(options) | 224 chrome_categories = _ComputeChromeCategories(options) |
218 systrace_categories = _ComputeSystraceCategories(options) | 225 systrace_categories = _ComputeSystraceCategories(options) |
219 perf_categories = _ComputePerfCategories(options) | 226 perf_categories = _ComputePerfCategories(options) |
220 | 227 |
221 if chrome_categories and 'webview' in systrace_categories: | 228 if chrome_categories and 'webview' in systrace_categories: |
222 logging.warning('Using the "webview" category in systrace together with ' | 229 logging.warning('Using the "webview" category in systrace together with ' |
223 'Chrome tracing results in duplicate trace events.') | 230 'Chrome tracing results in duplicate trace events.') |
224 | 231 |
225 enabled_controllers = [] | 232 enabled_controllers = [] |
| 233 # Enable the systrace and chrome controller. The systrace controller should go |
| 234 # first because it provides early events used in the chrome controller. |
| 235 if systrace_categories: |
| 236 enabled_controllers.append( |
| 237 systrace_controller.SystraceController(device, |
| 238 systrace_categories, |
| 239 options.ring_buffer)) |
| 240 |
226 if chrome_categories: | 241 if chrome_categories: |
227 enabled_controllers.append( | 242 enabled_controllers.append( |
228 chrome_controller.ChromeTracingController(device, | 243 chrome_controller.ChromeTracingController(device, |
229 package_info, | 244 package_info, |
230 chrome_categories, | 245 chrome_categories, |
231 options.ring_buffer, | 246 options.ring_buffer, |
232 options.trace_memory)) | 247 options.trace_memory, |
233 if systrace_categories: | 248 options.startup)) |
234 enabled_controllers.append( | |
235 systrace_controller.SystraceController(device, | |
236 systrace_categories, | |
237 options.ring_buffer)) | |
238 | |
239 if perf_categories: | 249 if perf_categories: |
240 enabled_controllers.append( | 250 enabled_controllers.append( |
241 perf_controller.PerfProfilerController(device, | 251 perf_controller.PerfProfilerController(device, |
242 perf_categories)) | 252 perf_categories)) |
243 | 253 |
244 if not enabled_controllers: | 254 if not enabled_controllers: |
245 ui.PrintMessage('No trace categories enabled.') | 255 ui.PrintMessage('No trace categories enabled.') |
246 return 1 | 256 return 1 |
247 | 257 |
248 if options.output: | 258 if options.output: |
249 options.output = os.path.expanduser(options.output) | 259 options.output = os.path.expanduser(options.output) |
250 result = profiler.CaptureProfile( | 260 result = profiler.CaptureProfile( |
251 enabled_controllers, | 261 enabled_controllers, |
252 options.time if not options.continuous else 0, | 262 options.time if options.time else 0, |
253 output=options.output, | 263 output=options.output, |
254 compress=options.compress, | 264 compress=options.compress, |
255 write_json=options.json) | 265 write_json=options.json) |
256 if options.view: | 266 if options.view: |
257 if sys.platform == 'darwin': | 267 if sys.platform == 'darwin': |
258 os.system('/usr/bin/open %s' % os.path.abspath(result)) | 268 os.system('/usr/bin/open %s' % os.path.abspath(result)) |
259 else: | 269 else: |
260 webbrowser.open(result) | 270 webbrowser.open(result) |
OLD | NEW |