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 17 matching lines...) Expand all Loading... | |
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). | |
Sami
2016/09/01 12:15:59
I assume this is temporary? Could you add a TODO a
washingtonp
2016/09/01 17:44:41
Done. This reminds me - are you okay with adding t
Sami
2016/09/02 12:57:42
Yeah, that would be great.
washingtonp
2016/09/02 20:10:27
Great! This will be done in the CL that makes prof
| |
97 options.list_categories = None | |
98 options.link_assets = None | |
99 options.asset_dir = None | |
100 options.timeout = None | |
101 options.collection_timeout = None | |
102 options.target = None | |
103 | |
91 if options.chrome_categories in ['list', 'help']: | 104 if options.chrome_categories in ['list', 'help']: |
92 ui.PrintMessage('Collecting record categories list...', eol='') | 105 ui.PrintMessage('Collecting record categories list...', eol='') |
93 record_categories = [] | 106 record_categories = [] |
94 disabled_by_default_categories = [] | 107 disabled_by_default_categories = [] |
95 record_categories, disabled_by_default_categories = \ | 108 record_categories, disabled_by_default_categories = \ |
96 chrome_tracing_agent.ChromeTracingAgent.GetCategories( | 109 chrome_tracing_agent.ChromeTracingAgent.GetCategories( |
97 device, package_info) | 110 device, package_info) |
98 | 111 |
99 ui.PrintMessage('done') | 112 ui.PrintMessage('done') |
100 ui.PrintMessage('Record Categories:') | 113 ui.PrintMessage('Record Categories:') |
(...skipping 10 matching lines...) Expand all Loading... | |
111 ui.PrintMessage('\n'.join( | 124 ui.PrintMessage('\n'.join( |
112 atrace_tracing_agent.AtraceAgent.GetCategories(device))) | 125 atrace_tracing_agent.AtraceAgent.GetCategories(device))) |
113 return 0 | 126 return 0 |
114 | 127 |
115 if (perf_tracing_agent.PerfProfilerAgent.IsSupported() and | 128 if (perf_tracing_agent.PerfProfilerAgent.IsSupported() and |
116 options.perf_categories in ['list', 'help']): | 129 options.perf_categories in ['list', 'help']): |
117 ui.PrintMessage('\n'.join( | 130 ui.PrintMessage('\n'.join( |
118 perf_tracing_agent.PerfProfilerAgent.GetCategories(device))) | 131 perf_tracing_agent.PerfProfilerAgent.GetCategories(device))) |
119 return 0 | 132 return 0 |
120 | 133 |
121 if not options.time and not options.continuous: | 134 if not options.trace_time and not options.continuous: |
122 ui.PrintMessage('Time interval or continuous tracing should be specified.') | 135 ui.PrintMessage('Time interval or continuous tracing should be specified.') |
123 return 1 | 136 return 1 |
124 | 137 |
125 if options.chrome_categories and 'webview' in options.atrace_categories: | 138 if options.chrome_categories and 'webview' in options.atrace_categories: |
126 logging.warning('Using the "webview" category in atrace together with ' | 139 logging.warning('Using the "webview" category in atrace together with ' |
127 'Chrome tracing results in duplicate trace events.') | 140 'Chrome tracing results in duplicate trace events.') |
128 | 141 |
129 enabled_agents = [] | 142 if options.output_file: |
130 if options.chrome_categories: | 143 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( | 144 result = profiler.CaptureProfile( |
157 options, | 145 options, |
158 enabled_agents, | 146 options.trace_time if not options.continuous else 0, |
159 options.time if not options.continuous else 0, | 147 output=options.output_file, |
160 output=options.output, | |
161 compress=options.compress, | 148 compress=options.compress, |
162 write_json=options.json) | 149 write_json=options.write_json) |
163 if options.view: | 150 if options.view: |
164 if sys.platform == 'darwin': | 151 if sys.platform == 'darwin': |
165 os.system('/usr/bin/open %s' % os.path.abspath(result)) | 152 os.system('/usr/bin/open %s' % os.path.abspath(result)) |
166 else: | 153 else: |
167 webbrowser.open(result) | 154 webbrowser.open(result) |
OLD | NEW |