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 logging | 5 import logging |
6 import optparse | 6 import optparse |
7 import os | 7 import os |
8 import py_utils | 8 import py_utils |
9 import signal | 9 import signal |
10 import subprocess | 10 import subprocess |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
120 def GetCategories(cls, device): | 120 def GetCategories(cls, device): |
121 perf_binary = cls._PrepareDevice(device) | 121 perf_binary = cls._PrepareDevice(device) |
122 return device.RunShellCommand('%s list' % perf_binary) | 122 return device.RunShellCommand('%s list' % perf_binary) |
123 | 123 |
124 @py_utils.Timeout(tracing_agents.START_STOP_TIMEOUT) | 124 @py_utils.Timeout(tracing_agents.START_STOP_TIMEOUT) |
125 def StartAgentTracing(self, config, timeout=None): | 125 def StartAgentTracing(self, config, timeout=None): |
126 self._categories = _ComputePerfCategories(config) | 126 self._categories = _ComputePerfCategories(config) |
127 self._perf_instance = _PerfProfiler(self._device, | 127 self._perf_instance = _PerfProfiler(self._device, |
128 self._perf_binary, | 128 self._perf_binary, |
129 self._categories) | 129 self._categories) |
| 130 return True |
130 | 131 |
131 @py_utils.Timeout(tracing_agents.START_STOP_TIMEOUT) | 132 @py_utils.Timeout(tracing_agents.START_STOP_TIMEOUT) |
132 def StopAgentTracing(self, timeout=None): | 133 def StopAgentTracing(self, timeout=None): |
133 if not self._perf_instance: | 134 if not self._perf_instance: |
134 return | 135 return |
135 self._perf_instance.SignalAndWait() | 136 self._perf_instance.SignalAndWait() |
| 137 return True |
136 | 138 |
137 @py_utils.Timeout(tracing_agents.GET_RESULTS_TIMEOUT) | 139 @py_utils.Timeout(tracing_agents.GET_RESULTS_TIMEOUT) |
138 def GetResults(self, timeout=None): | 140 def GetResults(self, timeout=None): |
139 with open(self._PullTrace(), 'r') as f: | 141 with open(self._PullTrace(), 'r') as f: |
140 trace_data = f.read() | 142 trace_data = f.read() |
141 return trace_result.TraceResult('perf', trace_data) | 143 return trace_result.TraceResult('perf', trace_data) |
142 | 144 |
143 @staticmethod | 145 @staticmethod |
144 def _GetInteractivePerfCommand(perfhost_path, perf_profile, symfs_dir, | 146 def _GetInteractivePerfCommand(perfhost_path, perf_profile, symfs_dir, |
145 required_libs, kallsyms): | 147 required_libs, kallsyms): |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
197 'not contain any perf samples. You can still view the ' | 199 'not contain any perf samples. You can still view the ' |
198 'perf data manually as shown above.') | 200 'perf data manually as shown above.') |
199 return None | 201 return None |
200 | 202 |
201 return json_file_name | 203 return json_file_name |
202 | 204 |
203 def SupportsExplicitClockSync(self): | 205 def SupportsExplicitClockSync(self): |
204 return False | 206 return False |
205 | 207 |
206 def RecordClockSyncMarker(self, sync_id, did_record_sync_marker_callback): | 208 def RecordClockSyncMarker(self, sync_id, did_record_sync_marker_callback): |
| 209 # pylint: disable=unused-argument |
207 assert self.SupportsExplicitClockSync(), ('Clock sync marker cannot be ' | 210 assert self.SupportsExplicitClockSync(), ('Clock sync marker cannot be ' |
208 'recorded since explicit clock sync is not supported.') | 211 'recorded since explicit clock sync is not supported.') |
209 | 212 |
210 def _OptionalValueCallback(default_value): | 213 def _OptionalValueCallback(default_value): |
211 def callback(option, _, __, parser): # pylint: disable=unused-argument | 214 def callback(option, _, __, parser): # pylint: disable=unused-argument |
212 value = default_value | 215 value = default_value |
213 if parser.rargs and not parser.rargs[0].startswith('-'): | 216 if parser.rargs and not parser.rargs[0].startswith('-'): |
214 value = parser.rargs.pop(0) | 217 value = parser.rargs.pop(0) |
215 setattr(parser.values, option.dest, value) | 218 setattr(parser.values, option.dest, value) |
216 return callback | 219 return callback |
217 | 220 |
218 | 221 |
219 class PerfConfig(tracing_agents.TracingConfig): | 222 class PerfConfig(tracing_agents.TracingConfig): |
220 def __init__(self, perf_categories): | 223 def __init__(self, perf_categories, device): |
221 tracing_agents.TracingConfig.__init__(self) | 224 tracing_agents.TracingConfig.__init__(self) |
222 self.perf_categories = perf_categories | 225 self.perf_categories = perf_categories |
| 226 self.device = device |
223 | 227 |
224 | 228 |
| 229 def try_create_agent(config): |
| 230 if config.perf_categories: |
| 231 return PerfProfilerAgent(config.device) |
| 232 return None |
| 233 |
225 def add_options(parser): | 234 def add_options(parser): |
226 options = optparse.OptionGroup(parser, 'Perf profiling options') | 235 options = optparse.OptionGroup(parser, 'Perf profiling options') |
227 options.add_option('-p', '--perf', help='Capture a perf profile with ' | 236 options.add_option('-p', '--perf', help='Capture a perf profile with ' |
228 'the chosen comma-delimited event categories. ' | 237 'the chosen comma-delimited event categories. ' |
229 'Samples CPU cycles by default. Use "list" to see ' | 238 'Samples CPU cycles by default. Use "list" to see ' |
230 'the available sample types.', action='callback', | 239 'the available sample types.', action='callback', |
231 default='', callback=_OptionalValueCallback('cycles'), | 240 default='', callback=_OptionalValueCallback('cycles'), |
232 metavar='PERF_CATEGORIES', dest='perf_categories') | 241 metavar='PERF_CATEGORIES', dest='perf_categories') |
233 parser.add_option_group(options) | 242 parser.add_option_group(options) |
234 return options | 243 return options |
235 | 244 |
236 def get_config(options): | 245 def get_config(options): |
237 return PerfConfig(options.perf_categories) | 246 return PerfConfig(options.perf_categories, options.device) |
238 | 247 |
239 def _ComputePerfCategories(config): | 248 def _ComputePerfCategories(config): |
240 if not PerfProfilerAgent.IsSupported(): | 249 if not PerfProfilerAgent.IsSupported(): |
241 return [] | 250 return [] |
242 if not config.perf_categories: | 251 if not config.perf_categories: |
243 return [] | 252 return [] |
244 return config.perf_categories.split(',') | 253 return config.perf_categories.split(',') |
OLD | NEW |