Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(416)

Side by Side Diff: systrace/profile_chrome/main.py

Issue 2276263003: Pass in custom options to Systrace agents (Closed) Base URL: https://chromium.googlesource.com/external/github.com/catapult-project/catapult.git@master
Patch Set: Set categories based on target devices and revised comments Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 _DEFAULT_CHROME_CATEGORIES = '_DEFAULT_CHROME_CATEGORIES' 24 PROFILE_CHROME_AGENT_MODULES = [chrome_tracing_agent, ddms_tracing_agent,
25 25 perf_tracing_agent, atrace_tracing_agent]
26
27 def _ComputeChromeCategories(options):
28 categories = []
29 if options.trace_frame_viewer:
30 categories.append('disabled-by-default-cc.debug')
31 if options.trace_ubercompositor:
32 categories.append('disabled-by-default-cc.debug*')
33 if options.trace_gpu:
34 categories.append('disabled-by-default-gpu.debug*')
35 if options.trace_flow:
36 categories.append('disabled-by-default-toplevel.flow')
37 if options.trace_memory:
38 categories.append('disabled-by-default-memory')
39 if options.trace_scheduler:
40 categories.append('disabled-by-default-blink.scheduler')
41 categories.append('disabled-by-default-cc.debug.scheduler')
42 categories.append('disabled-by-default-renderer.scheduler')
43 if options.chrome_categories:
44 categories += options.chrome_categories.split(',')
45 return categories
46
47
48 def _ComputeAtraceCategories(options):
49 if not options.atrace_categories:
50 return []
51 return options.atrace_categories.split(',')
52
53
54 def _ComputePerfCategories(options):
55 if not perf_tracing_agent.PerfProfilerAgent.IsSupported():
56 return []
57 if not options.perf_categories:
58 return []
59 return options.perf_categories.split(',')
60
61
62 def _OptionalValueCallback(default_value):
63 def callback(option, _, __, parser): # pylint: disable=unused-argument
64 value = default_value
65 if parser.rargs and not parser.rargs[0].startswith('-'):
66 value = parser.rargs.pop(0)
67 setattr(parser.values, option.dest, value)
68 return callback
69 26
70 27
71 def _CreateOptionParser(): 28 def _CreateOptionParser():
72 parser = optparse.OptionParser(description='Record about://tracing profiles ' 29 parser = optparse.OptionParser(description='Record about://tracing profiles '
73 'from Android browsers. See http://dev.' 30 'from Android browsers. See http://dev.'
74 'chromium.org/developers/how-tos/trace-event-' 31 'chromium.org/developers/how-tos/trace-event-'
75 'profiling-tool for detailed instructions for ' 32 'profiling-tool for detailed instructions for '
76 'profiling.') 33 'profiling.')
77 34
78 timed_options = optparse.OptionGroup(parser, 'Timed tracing') 35 timed_options = optparse.OptionGroup(parser, 'Timed tracing')
79 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 '
80 'download the resulting trace.', metavar='N', 37 'download the resulting trace.', metavar='N',
81 type='float') 38 type='float')
82 parser.add_option_group(timed_options) 39 parser.add_option_group(timed_options)
83 40
84 cont_options = optparse.OptionGroup(parser, 'Continuous tracing') 41 cont_options = optparse.OptionGroup(parser, 'Continuous tracing')
85 cont_options.add_option('--continuous', help='Profile continuously until ' 42 cont_options.add_option('--continuous', help='Profile continuously until '
86 'stopped.', action='store_true') 43 'stopped.', action='store_true')
87 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 '
88 'ring buffer and save its contents when stopping ' 45 'ring buffer and save its contents when stopping '
89 'instead of appending events into one long trace.', 46 'instead of appending events into one long trace.',
90 action='store_true') 47 action='store_true')
91 parser.add_option_group(cont_options) 48 parser.add_option_group(cont_options)
92 49
93 chrome_opts = optparse.OptionGroup(parser, 'Chrome tracing options')
94 chrome_opts.add_option('-c', '--categories', help='Select Chrome tracing '
95 'categories with comma-delimited wildcards, '
96 'e.g., "*", "cat1*,-cat1a". Omit this option to trace '
97 'Chrome\'s default categories. Chrome tracing can be '
98 'disabled with "--categories=\'\'". Use "list" to '
99 'see the available categories.',
100 metavar='CHROME_CATEGORIES', dest='chrome_categories',
101 default=_DEFAULT_CHROME_CATEGORIES)
102 chrome_opts.add_option('--trace-cc',
103 help='Deprecated, use --trace-frame-viewer.',
104 action='store_true')
105 chrome_opts.add_option('--trace-frame-viewer',
106 help='Enable enough trace categories for '
107 'compositor frame viewing.', action='store_true')
108 chrome_opts.add_option('--trace-ubercompositor',
109 help='Enable enough trace categories for '
110 'ubercompositor frame data.', action='store_true')
111 chrome_opts.add_option('--trace-gpu', help='Enable extra trace categories '
112 'for GPU data.', action='store_true')
113 chrome_opts.add_option('--trace-flow', help='Enable extra trace categories '
114 'for IPC message flows.', action='store_true')
115 chrome_opts.add_option('--trace-memory', help='Enable extra trace categories '
116 'for memory profile. (tcmalloc required)',
117 action='store_true')
118 chrome_opts.add_option('--trace-scheduler', help='Enable extra trace '
119 'categories for scheduler state',
120 action='store_true')
121 parser.add_option_group(chrome_opts)
122
123 parser.add_option_group(flags.AtraceOptions(parser))
124
125 if perf_tracing_agent.PerfProfilerAgent.IsSupported():
126 perf_opts = optparse.OptionGroup(parser, 'Perf profiling options')
127 perf_opts.add_option('-p', '--perf', help='Capture a perf profile with '
128 'the chosen comma-delimited event categories. '
129 'Samples CPU cycles by default. Use "list" to see '
130 'the available sample types.', action='callback',
131 default='', callback=_OptionalValueCallback('cycles'),
132 metavar='PERF_CATEGORIES', dest='perf_categories')
133 parser.add_option_group(perf_opts)
134
135 ddms_options = optparse.OptionGroup(parser, 'Java tracing')
136 ddms_options.add_option('--ddms', help='Trace Java execution using DDMS '
137 'sampling.', action='store_true')
138 parser.add_option_group(ddms_options)
139
140 parser.add_option_group(flags.OutputOptions(parser)) 50 parser.add_option_group(flags.OutputOptions(parser))
141 51
142 browsers = sorted(profiler.GetSupportedBrowsers().keys()) 52 browsers = sorted(profiler.GetSupportedBrowsers().keys())
143 parser.add_option('-b', '--browser', help='Select among installed browsers. ' 53 parser.add_option('-b', '--browser', help='Select among installed browsers. '
Zhen Wang 2016/08/29 16:30:20 This is only related to chrome.
washingtonp 2016/08/29 20:00:41 options.browser is only used to generate package_i
Zhen Wang 2016/08/29 21:00:26 I see. Let's keep it here for now.
144 'One of ' + ', '.join(browsers) + ', "stable" is used by ' 54 'One of ' + ', '.join(browsers) + ', "stable" is used by '
145 'default.', type='choice', choices=browsers, 55 'default.', type='choice', choices=browsers,
146 default='stable') 56 default='stable')
147 parser.add_option('-v', '--verbose', help='Verbose logging.', 57 parser.add_option('-v', '--verbose', help='Verbose logging.',
148 action='store_true') 58 action='store_true')
149 parser.add_option('-z', '--compress', help='Compress the resulting trace ' 59 parser.add_option('-z', '--compress', help='Compress the resulting trace '
150 'with gzip. ', action='store_true') 60 'with gzip. ', action='store_true')
151 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, '
152 'defaults to the value of ANDROID_SERIAL environment ' 62 'defaults to the value of ANDROID_SERIAL environment '
153 'variable. If not specified, only 0 or 1 connected ' 63 'variable. If not specified, only 0 or 1 connected '
154 'devices are supported.') 64 'devices are supported.')
65
66 # Add options from profile_chrome agents.
67 for module in PROFILE_CHROME_AGENT_MODULES:
68 parser.add_option_group(module.add_options(parser))
69
155 return parser 70 return parser
156 71
157 72
158 def main(): 73 def main():
159 parser = _CreateOptionParser() 74 parser = _CreateOptionParser()
160 options, _args = parser.parse_args() # pylint: disable=unused-variable 75 options, _args = parser.parse_args() # pylint: disable=unused-variable
161 if options.trace_cc: 76 if options.trace_cc:
162 parser.error("""--trace-cc is deprecated. 77 parser.error("""--trace-cc is deprecated.
163 78
164 For basic jank busting uses, use --trace-frame-viewer 79 For basic jank busting uses, use --trace-frame-viewer
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
200 if (perf_tracing_agent.PerfProfilerAgent.IsSupported() and 115 if (perf_tracing_agent.PerfProfilerAgent.IsSupported() and
201 options.perf_categories in ['list', 'help']): 116 options.perf_categories in ['list', 'help']):
202 ui.PrintMessage('\n'.join( 117 ui.PrintMessage('\n'.join(
203 perf_tracing_agent.PerfProfilerAgent.GetCategories(device))) 118 perf_tracing_agent.PerfProfilerAgent.GetCategories(device)))
204 return 0 119 return 0
205 120
206 if not options.time and not options.continuous: 121 if not options.time and not options.continuous:
207 ui.PrintMessage('Time interval or continuous tracing should be specified.') 122 ui.PrintMessage('Time interval or continuous tracing should be specified.')
208 return 1 123 return 1
209 124
210 chrome_categories = _ComputeChromeCategories(options) 125 if options.chrome_categories and 'webview' in options.atrace_categories:
211 atrace_categories = _ComputeAtraceCategories(options)
212 perf_categories = _ComputePerfCategories(options)
213
214 if chrome_categories and 'webview' in atrace_categories:
215 logging.warning('Using the "webview" category in atrace together with ' 126 logging.warning('Using the "webview" category in atrace together with '
216 'Chrome tracing results in duplicate trace events.') 127 'Chrome tracing results in duplicate trace events.')
217 128
218 enabled_agents = [] 129 enabled_agents = []
219 if chrome_categories: 130 if options.chrome_categories:
220 enabled_agents.append( 131 enabled_agents.append(
221 chrome_tracing_agent.ChromeTracingAgent(device, 132 chrome_tracing_agent.ChromeTracingAgent(device,
222 package_info, 133 package_info,
223 chrome_categories,
224 options.ring_buffer, 134 options.ring_buffer,
225 options.trace_memory)) 135 options.trace_memory))
226 if atrace_categories: 136 if options.atrace_categories:
227 enabled_agents.append( 137 enabled_agents.append(
228 atrace_tracing_agent.AtraceAgent(device, 138 atrace_tracing_agent.AtraceAgent(device,
229 atrace_categories,
230 options.ring_buffer)) 139 options.ring_buffer))
231 140
232 if perf_categories: 141 if options.perf_categories:
233 enabled_agents.append( 142 enabled_agents.append(
234 perf_tracing_agent.PerfProfilerAgent(device, 143 perf_tracing_agent.PerfProfilerAgent(device))
235 perf_categories))
236 144
237 if options.ddms: 145 if options.ddms:
238 enabled_agents.append( 146 enabled_agents.append(
239 ddms_tracing_agent.DdmsAgent(device, 147 ddms_tracing_agent.DdmsAgent(device,
240 package_info)) 148 package_info))
241 149
242 if not enabled_agents: 150 if not enabled_agents:
243 ui.PrintMessage('No trace categories enabled.') 151 ui.PrintMessage('No trace categories enabled.')
244 return 1 152 return 1
245 153
246 if options.output: 154 if options.output:
247 options.output = os.path.expanduser(options.output) 155 options.output = os.path.expanduser(options.output)
248 result = profiler.CaptureProfile( 156 result = profiler.CaptureProfile(
157 options,
249 enabled_agents, 158 enabled_agents,
250 options.time if not options.continuous else 0, 159 options.time if not options.continuous else 0,
251 output=options.output, 160 output=options.output,
252 compress=options.compress, 161 compress=options.compress,
253 write_json=options.json) 162 write_json=options.json)
254 if options.view: 163 if options.view:
255 if sys.platform == 'darwin': 164 if sys.platform == 'darwin':
256 os.system('/usr/bin/open %s' % os.path.abspath(result)) 165 os.system('/usr/bin/open %s' % os.path.abspath(result))
257 else: 166 else:
258 webbrowser.open(result) 167 webbrowser.open(result)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698