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 optparse | 5 import optparse |
6 import py_utils | 6 import py_utils |
7 import threading | 7 import threading |
8 import zlib | 8 import zlib |
9 | 9 |
10 from devil.utils import cmd_helper | 10 from devil.utils import cmd_helper |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
45 | 45 |
46 @staticmethod | 46 @staticmethod |
47 def GetCategories(device): | 47 def GetCategories(device): |
48 return device.RunShellCommand('atrace --list_categories') | 48 return device.RunShellCommand('atrace --list_categories') |
49 | 49 |
50 @py_utils.Timeout(tracing_agents.START_STOP_TIMEOUT) | 50 @py_utils.Timeout(tracing_agents.START_STOP_TIMEOUT) |
51 def StartAgentTracing(self, config, timeout=None): | 51 def StartAgentTracing(self, config, timeout=None): |
52 self._categories = _ComputeAtraceCategories(config) | 52 self._categories = _ComputeAtraceCategories(config) |
53 self._thread = threading.Thread(target=self._CollectData) | 53 self._thread = threading.Thread(target=self._CollectData) |
54 self._thread.start() | 54 self._thread.start() |
| 55 return True |
55 | 56 |
56 @py_utils.Timeout(tracing_agents.START_STOP_TIMEOUT) | 57 @py_utils.Timeout(tracing_agents.START_STOP_TIMEOUT) |
57 def StopAgentTracing(self, timeout=None): | 58 def StopAgentTracing(self, timeout=None): |
58 self._done.set() | 59 self._done.set() |
| 60 return True |
59 | 61 |
60 @py_utils.Timeout(tracing_agents.GET_RESULTS_TIMEOUT) | 62 @py_utils.Timeout(tracing_agents.GET_RESULTS_TIMEOUT) |
61 def GetResults(self, timeout=None): | 63 def GetResults(self, timeout=None): |
62 self._thread.join() | 64 self._thread.join() |
63 self._thread = None | 65 self._thread = None |
64 return trace_result.TraceResult('systemTraceEvents', self._trace_data) | 66 return trace_result.TraceResult('systemTraceEvents', self._trace_data) |
65 | 67 |
66 def SupportsExplicitClockSync(self): | 68 def SupportsExplicitClockSync(self): |
67 return False | 69 return False |
68 | 70 |
69 def RecordClockSyncMarker(self, sync_id, did_record_sync_marker_callback): | 71 def RecordClockSyncMarker(self, sync_id, did_record_sync_marker_callback): |
| 72 # pylint: disable=unused-argument |
70 assert self.SupportsExplicitClockSync(), ('Clock sync marker cannot be ' | 73 assert self.SupportsExplicitClockSync(), ('Clock sync marker cannot be ' |
71 'recorded since explicit clock sync is not supported.') | 74 'recorded since explicit clock sync is not supported.') |
72 | 75 |
73 def IsTracingOn(self): | 76 def IsTracingOn(self): |
74 result = self._RunAdbShellCommand(['cat', _TRACING_ON_PATH]) | 77 result = self._RunAdbShellCommand(['cat', _TRACING_ON_PATH]) |
75 return result.strip() == '1' | 78 return result.strip() == '1' |
76 | 79 |
77 def _RunAdbShellCommand(self, command): | 80 def _RunAdbShellCommand(self, command): |
78 # We use a separate interface to adb because the one from AndroidCommands | 81 # We use a separate interface to adb because the one from AndroidCommands |
79 # isn't re-entrant. | 82 # isn't re-entrant. |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
119 | 122 |
120 # Collapse CRLFs that are added by adb shell. | 123 # Collapse CRLFs that are added by adb shell. |
121 if trace_data.startswith('\r\n'): | 124 if trace_data.startswith('\r\n'): |
122 trace_data = trace_data.replace('\r\n', '\n') | 125 trace_data = trace_data.replace('\r\n', '\n') |
123 | 126 |
124 # Skip the initial newline. | 127 # Skip the initial newline. |
125 return trace_data[1:] | 128 return trace_data[1:] |
126 | 129 |
127 | 130 |
128 class AtraceConfig(tracing_agents.TracingConfig): | 131 class AtraceConfig(tracing_agents.TracingConfig): |
129 def __init__(self, atrace_categories): | 132 def __init__(self, atrace_categories, device, ring_buffer): |
130 tracing_agents.TracingConfig.__init__(self) | 133 tracing_agents.TracingConfig.__init__(self) |
131 self.atrace_categories = atrace_categories | 134 self.atrace_categories = atrace_categories |
| 135 self.device = device |
| 136 self.ring_buffer = ring_buffer |
132 | 137 |
133 | 138 |
| 139 def try_create_agent(config): |
| 140 if config.atrace_categories: |
| 141 return AtraceAgent(config.device, config.ring_buffer) |
| 142 return None |
| 143 |
134 def add_options(parser): | 144 def add_options(parser): |
135 atrace_opts = optparse.OptionGroup(parser, 'Atrace tracing options') | 145 atrace_opts = optparse.OptionGroup(parser, 'Atrace tracing options') |
136 atrace_opts.add_option('-s', '--systrace', help='Capture a systrace with ' | 146 atrace_opts.add_option('-s', '--systrace', help='Capture a systrace with ' |
137 'the chosen comma-delimited systrace categories. You' | 147 'the chosen comma-delimited systrace categories. You' |
138 ' can also capture a combined Chrome + systrace by ' | 148 ' can also capture a combined Chrome + systrace by ' |
139 'enabling both types of categories. Use "list" to ' | 149 'enabling both types of categories. Use "list" to ' |
140 'see the available categories. Systrace is disabled' | 150 'see the available categories. Systrace is disabled' |
141 ' by default. Note that in this case, Systrace is ' | 151 ' by default. Note that in this case, Systrace is ' |
142 'synonymous with Atrace.', | 152 'synonymous with Atrace.', |
143 metavar='ATRACE_CATEGORIES', | 153 metavar='ATRACE_CATEGORIES', |
144 dest='atrace_categories', default='') | 154 dest='atrace_categories', default='') |
145 return atrace_opts | 155 return atrace_opts |
146 | 156 |
147 def get_config(options): | 157 def get_config(options): |
148 return AtraceConfig(options.atrace_categories) | 158 return AtraceConfig(options.atrace_categories, options.device, |
| 159 options.ring_buffer) |
149 | 160 |
150 def _ComputeAtraceCategories(config): | 161 def _ComputeAtraceCategories(config): |
151 if not config.atrace_categories: | 162 if not config.atrace_categories: |
152 return _DEFAULT_CATEGORIES | 163 return _DEFAULT_CATEGORIES |
153 return config.atrace_categories.split(',') | 164 return config.atrace_categories.split(',') |
OLD | NEW |