OLD | NEW |
1 # Copyright 2014 The Chromium Authors. All rights reserved. | 1 # Copyright 2014 The Chromium Authors. All rights reserved. |
2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
4 | 4 |
5 import json | 5 import json |
6 import optparse | 6 import optparse |
7 import os | 7 import os |
8 import py_utils | 8 import py_utils |
9 import re | 9 import re |
10 | 10 |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
84 # | 84 # |
85 # The first one is printed when tracing starts and the second one indicates | 85 # The first one is printed when tracing starts and the second one indicates |
86 # that the trace file is ready to be pulled. | 86 # that the trace file is ready to be pulled. |
87 try: | 87 try: |
88 self._logcat_monitor.WaitFor(self._trace_start_re, timeout=5) | 88 self._logcat_monitor.WaitFor(self._trace_start_re, timeout=5) |
89 self._is_tracing = True | 89 self._is_tracing = True |
90 except device_errors.CommandTimeoutError: | 90 except device_errors.CommandTimeoutError: |
91 raise RuntimeError( | 91 raise RuntimeError( |
92 'Trace start marker not found. Possible causes: 1) Is the correct ' | 92 'Trace start marker not found. Possible causes: 1) Is the correct ' |
93 'version of the browser running? 2) Is the browser already launched?') | 93 'version of the browser running? 2) Is the browser already launched?') |
| 94 return True |
94 | 95 |
95 @py_utils.Timeout(tracing_agents.START_STOP_TIMEOUT) | 96 @py_utils.Timeout(tracing_agents.START_STOP_TIMEOUT) |
96 def StopAgentTracing(self, timeout=None): | 97 def StopAgentTracing(self, timeout=None): |
97 if self._is_tracing: | 98 if self._is_tracing: |
98 self._device.BroadcastIntent(intent.Intent( | 99 self._device.BroadcastIntent(intent.Intent( |
99 action='%s.GPU_PROFILER_STOP' % self._package_info.package)) | 100 action='%s.GPU_PROFILER_STOP' % self._package_info.package)) |
100 self._trace_file = self._logcat_monitor.WaitFor( | 101 self._trace_file = self._logcat_monitor.WaitFor( |
101 self._trace_finish_re, timeout=120).group(1) | 102 self._trace_finish_re, timeout=120).group(1) |
102 self._is_tracing = False | 103 self._is_tracing = False |
103 if self._trace_memory: | 104 if self._trace_memory: |
104 self._device.SetProp(_HEAP_PROFILE_MMAP_PROPERTY, 0) | 105 self._device.SetProp(_HEAP_PROFILE_MMAP_PROPERTY, 0) |
| 106 return True |
105 | 107 |
106 @py_utils.Timeout(tracing_agents.GET_RESULTS_TIMEOUT) | 108 @py_utils.Timeout(tracing_agents.GET_RESULTS_TIMEOUT) |
107 def GetResults(self, timeout=None): | 109 def GetResults(self, timeout=None): |
108 with open(self._PullTrace(), 'r') as f: | 110 with open(self._PullTrace(), 'r') as f: |
109 trace_data = f.read() | 111 trace_data = f.read() |
110 return trace_result.TraceResult('traceEvents', trace_data) | 112 return trace_result.TraceResult('traceEvents', trace_data) |
111 | 113 |
112 def _PullTrace(self): | 114 def _PullTrace(self): |
113 trace_file = self._trace_file.replace('/storage/emulated/0/', '/sdcard/') | 115 trace_file = self._trace_file.replace('/storage/emulated/0/', '/sdcard/') |
114 host_file = os.path.join(os.path.curdir, os.path.basename(trace_file)) | 116 host_file = os.path.join(os.path.curdir, os.path.basename(trace_file)) |
115 try: | 117 try: |
116 self._device.PullFile(trace_file, host_file) | 118 self._device.PullFile(trace_file, host_file) |
117 except device_errors.AdbCommandFailedError: | 119 except device_errors.AdbCommandFailedError: |
118 raise RuntimeError( | 120 raise RuntimeError( |
119 'Cannot pull the trace file. Have you granted Storage permission to ' | 121 'Cannot pull the trace file. Have you granted Storage permission to ' |
120 'the browser? (Android Settings -> Apps -> [the browser app] -> ' | 122 'the browser? (Android Settings -> Apps -> [the browser app] -> ' |
121 'Permissions -> Storage)') | 123 'Permissions -> Storage)') |
122 return host_file | 124 return host_file |
123 | 125 |
124 def SupportsExplicitClockSync(self): | 126 def SupportsExplicitClockSync(self): |
125 return False | 127 return False |
126 | 128 |
127 def RecordClockSyncMarker(self, sync_id, did_record_sync_marker_callback): | 129 def RecordClockSyncMarker(self, sync_id, did_record_sync_marker_callback): |
| 130 # pylint: disable=unused-argument |
128 assert self.SupportsExplicitClockSync(), ('Clock sync marker cannot be ' | 131 assert self.SupportsExplicitClockSync(), ('Clock sync marker cannot be ' |
129 'recorded since explicit clock sync is not supported.') | 132 'recorded since explicit clock sync is not supported.') |
130 | 133 |
131 | 134 |
132 class ChromeConfig(tracing_agents.TracingConfig): | 135 class ChromeConfig(tracing_agents.TracingConfig): |
133 def __init__(self, chrome_categories, trace_cc, trace_frame_viewer, | 136 def __init__(self, chrome_categories, trace_cc, trace_frame_viewer, |
134 trace_ubercompositor, trace_gpu, trace_flow, trace_memory, | 137 trace_ubercompositor, trace_gpu, trace_flow, trace_memory, |
135 trace_scheduler): | 138 trace_scheduler, ring_buffer, device, package_info): |
136 tracing_agents.TracingConfig.__init__(self) | 139 tracing_agents.TracingConfig.__init__(self) |
137 self.chrome_categories = chrome_categories | 140 self.chrome_categories = chrome_categories |
138 self.trace_cc = trace_cc | 141 self.trace_cc = trace_cc |
139 self.trace_frame_viewer = trace_frame_viewer | 142 self.trace_frame_viewer = trace_frame_viewer |
140 self.trace_ubercompositor = trace_ubercompositor | 143 self.trace_ubercompositor = trace_ubercompositor |
141 self.trace_gpu = trace_gpu | 144 self.trace_gpu = trace_gpu |
142 self.trace_flow = trace_flow | 145 self.trace_flow = trace_flow |
143 self.trace_memory = trace_memory | 146 self.trace_memory = trace_memory |
144 self.trace_scheduler = trace_scheduler | 147 self.trace_scheduler = trace_scheduler |
| 148 self.ring_buffer = ring_buffer |
| 149 self.device = device |
| 150 self.package_info = package_info |
145 | 151 |
146 | 152 |
| 153 def try_create_agent(config): |
| 154 if config.chrome_categories: |
| 155 return ChromeTracingAgent(config.device, config.package_info, |
| 156 config.ring_buffer, config.trace_memory) |
| 157 return None |
| 158 |
147 def add_options(parser): | 159 def add_options(parser): |
148 chrome_opts = optparse.OptionGroup(parser, 'Chrome tracing options') | 160 chrome_opts = optparse.OptionGroup(parser, 'Chrome tracing options') |
149 chrome_opts.add_option('-c', '--categories', help='Select Chrome tracing ' | 161 chrome_opts.add_option('-c', '--categories', help='Select Chrome tracing ' |
150 'categories with comma-delimited wildcards, ' | 162 'categories with comma-delimited wildcards, ' |
151 'e.g., "*", "cat1*,-cat1a". Omit this option to trace ' | 163 'e.g., "*", "cat1*,-cat1a". Omit this option to trace ' |
152 'Chrome\'s default categories. Chrome tracing can be ' | 164 'Chrome\'s default categories. Chrome tracing can be ' |
153 'disabled with "--categories=\'\'". Use "list" to ' | 165 'disabled with "--categories=\'\'". Use "list" to ' |
154 'see the available categories.', | 166 'see the available categories.', |
155 metavar='CHROME_CATEGORIES', dest='chrome_categories', | 167 metavar='CHROME_CATEGORIES', dest='chrome_categories', |
156 default=_DEFAULT_CHROME_CATEGORIES) | 168 default=_DEFAULT_CHROME_CATEGORIES) |
(...skipping 15 matching lines...) Expand all Loading... |
172 action='store_true') | 184 action='store_true') |
173 chrome_opts.add_option('--trace-scheduler', help='Enable extra trace ' | 185 chrome_opts.add_option('--trace-scheduler', help='Enable extra trace ' |
174 'categories for scheduler state', | 186 'categories for scheduler state', |
175 action='store_true') | 187 action='store_true') |
176 return chrome_opts | 188 return chrome_opts |
177 | 189 |
178 def get_config(options): | 190 def get_config(options): |
179 return ChromeConfig(options.chrome_categories, options.trace_cc, | 191 return ChromeConfig(options.chrome_categories, options.trace_cc, |
180 options.trace_frame_viewer, options.trace_ubercompositor, | 192 options.trace_frame_viewer, options.trace_ubercompositor, |
181 options.trace_gpu, options.trace_flow, | 193 options.trace_gpu, options.trace_flow, |
182 options.trace_memory, options.trace_scheduler) | 194 options.trace_memory, options.trace_scheduler, |
| 195 options.ring_buffer, options.device, |
| 196 options.package_info) |
183 | 197 |
184 def _ComputeChromeCategories(config): | 198 def _ComputeChromeCategories(config): |
185 categories = [] | 199 categories = [] |
186 if config.trace_frame_viewer: | 200 if config.trace_frame_viewer: |
187 categories.append('disabled-by-default-cc.debug') | 201 categories.append('disabled-by-default-cc.debug') |
188 if config.trace_ubercompositor: | 202 if config.trace_ubercompositor: |
189 categories.append('disabled-by-default-cc.debug*') | 203 categories.append('disabled-by-default-cc.debug*') |
190 if config.trace_gpu: | 204 if config.trace_gpu: |
191 categories.append('disabled-by-default-gpu.debug*') | 205 categories.append('disabled-by-default-gpu.debug*') |
192 if config.trace_flow: | 206 if config.trace_flow: |
193 categories.append('disabled-by-default-toplevel.flow') | 207 categories.append('disabled-by-default-toplevel.flow') |
194 if config.trace_memory: | 208 if config.trace_memory: |
195 categories.append('disabled-by-default-memory') | 209 categories.append('disabled-by-default-memory') |
196 if config.trace_scheduler: | 210 if config.trace_scheduler: |
197 categories.append('disabled-by-default-blink.scheduler') | 211 categories.append('disabled-by-default-blink.scheduler') |
198 categories.append('disabled-by-default-cc.debug.scheduler') | 212 categories.append('disabled-by-default-cc.debug.scheduler') |
199 categories.append('disabled-by-default-renderer.scheduler') | 213 categories.append('disabled-by-default-renderer.scheduler') |
200 if config.chrome_categories: | 214 if config.chrome_categories: |
201 categories += config.chrome_categories.split(',') | 215 categories += config.chrome_categories.split(',') |
202 return categories | 216 return categories |
OLD | NEW |