Chromium Code Reviews| 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_controller | 13 from profile_chrome import chrome_controller |
| 14 from profile_chrome import flags | |
| 14 from profile_chrome import perf_controller | 15 from profile_chrome import perf_controller |
| 15 from profile_chrome import profiler | 16 from profile_chrome import profiler |
| 16 from profile_chrome import systrace_controller | 17 from profile_chrome import systrace_controller |
| 17 from profile_chrome import ui | 18 from profile_chrome import ui |
| 18 | 19 |
| 19 from pylib import android_commands | 20 from pylib import android_commands |
| 20 from pylib.device import device_utils | 21 from pylib.device import device_utils |
| 21 | 22 |
| 22 | 23 |
| 23 _DEFAULT_CHROME_CATEGORIES = '_DEFAULT_CHROME_CATEGORIES' | 24 _DEFAULT_CHROME_CATEGORIES = '_DEFAULT_CHROME_CATEGORIES' |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 112 chrome_opts.add_option('--trace-flow', help='Enable extra trace categories ' | 113 chrome_opts.add_option('--trace-flow', help='Enable extra trace categories ' |
| 113 'for IPC message flows.', action='store_true') | 114 'for IPC message flows.', action='store_true') |
| 114 chrome_opts.add_option('--trace-memory', help='Enable extra trace categories ' | 115 chrome_opts.add_option('--trace-memory', help='Enable extra trace categories ' |
| 115 'for memory profile. (tcmalloc required)', | 116 'for memory profile. (tcmalloc required)', |
| 116 action='store_true') | 117 action='store_true') |
| 117 chrome_opts.add_option('--trace-scheduler', help='Enable extra trace ' | 118 chrome_opts.add_option('--trace-scheduler', help='Enable extra trace ' |
| 118 'categories for scheduler state', | 119 'categories for scheduler state', |
| 119 action='store_true') | 120 action='store_true') |
| 120 parser.add_option_group(chrome_opts) | 121 parser.add_option_group(chrome_opts) |
| 121 | 122 |
| 122 systrace_opts = optparse.OptionGroup(parser, 'Systrace tracing options') | 123 parser.add_option_group(flags.SystraceOptions(parser)) |
| 123 systrace_opts.add_option('-s', '--systrace', help='Capture a systrace with ' | |
| 124 'the chosen comma-delimited systrace categories. You ' | |
| 125 'can also capture a combined Chrome + systrace by ' | |
| 126 'enable both types of categories. Use "list" to see ' | |
| 127 'the available categories. Systrace is disabled by ' | |
| 128 'default.', metavar='SYS_CATEGORIES', | |
| 129 dest='systrace_categories', default='') | |
| 130 parser.add_option_group(systrace_opts) | |
| 131 | 124 |
| 132 if perf_controller.PerfProfilerController.IsSupported(): | 125 if perf_controller.PerfProfilerController.IsSupported(): |
| 133 perf_opts = optparse.OptionGroup(parser, 'Perf profiling options') | 126 perf_opts = optparse.OptionGroup(parser, 'Perf profiling options') |
| 134 perf_opts.add_option('-p', '--perf', help='Capture a perf profile with ' | 127 perf_opts.add_option('-p', '--perf', help='Capture a perf profile with ' |
| 135 'the chosen comma-delimited event categories. ' | 128 'the chosen comma-delimited event categories. ' |
| 136 'Samples CPU cycles by default. Use "list" to see ' | 129 'Samples CPU cycles by default. Use "list" to see ' |
| 137 'the available sample types.', action='callback', | 130 'the available sample types.', action='callback', |
| 138 default='', callback=_OptionalValueCallback('cycles'), | 131 default='', callback=_OptionalValueCallback('cycles'), |
| 139 metavar='PERF_CATEGORIES', dest='perf_categories') | 132 metavar='PERF_CATEGORIES', dest='perf_categories') |
| 140 parser.add_option_group(perf_opts) | 133 parser.add_option_group(perf_opts) |
| 141 | 134 |
| 142 output_options = optparse.OptionGroup(parser, 'Output options') | 135 parser.add_option_group(flags.OutputOptions(parser)) |
| 143 output_options.add_option('-o', '--output', help='Save trace output to file.') | |
| 144 output_options.add_option('--json', help='Save trace as raw JSON instead of ' | |
| 145 'HTML.', action='store_true') | |
| 146 output_options.add_option('--view', help='Open resulting trace file in a ' | |
| 147 'browser.', action='store_true') | |
| 148 parser.add_option_group(output_options) | |
| 149 | 136 |
| 150 browsers = sorted(profiler.GetSupportedBrowsers().keys()) | 137 browsers = sorted(profiler.GetSupportedBrowsers().keys()) |
| 151 parser.add_option('-b', '--browser', help='Select among installed browsers. ' | 138 parser.add_option('-b', '--browser', help='Select among installed browsers. ' |
| 152 'One of ' + ', '.join(browsers) + ', "stable" is used by ' | 139 'One of ' + ', '.join(browsers) + ', "stable" is used by ' |
| 153 'default.', type='choice', choices=browsers, | 140 'default.', type='choice', choices=browsers, |
| 154 default='stable') | 141 default='stable') |
| 155 parser.add_option('-v', '--verbose', help='Verbose logging.', | 142 parser.add_option('-v', '--verbose', help='Verbose logging.', |
| 156 action='store_true') | 143 action='store_true') |
| 157 parser.add_option('-z', '--compress', help='Compress the resulting trace ' | 144 parser.add_option('-z', '--compress', help='Compress the resulting trace ' |
| 158 'with gzip. ', action='store_true') | 145 'with gzip. ', action='store_true') |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 223 'Chrome tracing results in duplicate trace events.') | 210 'Chrome tracing results in duplicate trace events.') |
| 224 | 211 |
| 225 enabled_controllers = [] | 212 enabled_controllers = [] |
| 226 if chrome_categories: | 213 if chrome_categories: |
| 227 enabled_controllers.append( | 214 enabled_controllers.append( |
| 228 chrome_controller.ChromeTracingController(device, | 215 chrome_controller.ChromeTracingController(device, |
| 229 package_info, | 216 package_info, |
| 230 chrome_categories, | 217 chrome_categories, |
| 231 options.ring_buffer, | 218 options.ring_buffer, |
| 232 options.trace_memory)) | 219 options.trace_memory)) |
| 233 if systrace_categories: | 220 if systrace_categories: |
|
pasko
2015/01/27 17:00:24
wouldn't it still be useful to put systrace earlie
Benoit L
2015/01/27 18:41:41
Maybe, but this would be another CL.
pasko
2015/01/28 12:26:03
I assumed it is only about swapping a few lines he
| |
| 234 enabled_controllers.append( | 221 enabled_controllers.append( |
| 235 systrace_controller.SystraceController(device, | 222 systrace_controller.SystraceController(device, |
| 236 systrace_categories, | 223 systrace_categories, |
| 237 options.ring_buffer)) | 224 options.ring_buffer)) |
| 238 | 225 |
| 239 if perf_categories: | 226 if perf_categories: |
| 240 enabled_controllers.append( | 227 enabled_controllers.append( |
| 241 perf_controller.PerfProfilerController(device, | 228 perf_controller.PerfProfilerController(device, |
| 242 perf_categories)) | 229 perf_categories)) |
| 243 | 230 |
| 244 if not enabled_controllers: | 231 if not enabled_controllers: |
| 245 ui.PrintMessage('No trace categories enabled.') | 232 ui.PrintMessage('No trace categories enabled.') |
| 246 return 1 | 233 return 1 |
| 247 | 234 |
| 248 if options.output: | 235 if options.output: |
| 249 options.output = os.path.expanduser(options.output) | 236 options.output = os.path.expanduser(options.output) |
| 250 result = profiler.CaptureProfile( | 237 result = profiler.CaptureProfile( |
| 251 enabled_controllers, | 238 enabled_controllers, |
| 252 options.time if not options.continuous else 0, | 239 options.time if not options.continuous else 0, |
| 253 output=options.output, | 240 output=options.output, |
| 254 compress=options.compress, | 241 compress=options.compress, |
| 255 write_json=options.json) | 242 write_json=options.json) |
| 256 if options.view: | 243 if options.view: |
| 257 if sys.platform == 'darwin': | 244 if sys.platform == 'darwin': |
| 258 os.system('/usr/bin/open %s' % os.path.abspath(result)) | 245 os.system('/usr/bin/open %s' % os.path.abspath(result)) |
| 259 else: | 246 else: |
| 260 webbrowser.open(result) | 247 webbrowser.open(result) |
| OLD | NEW |