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 py_utils | 6 import py_utils |
6 import threading | 7 import threading |
7 import zlib | 8 import zlib |
8 | 9 |
9 from devil.utils import cmd_helper | 10 from devil.utils import cmd_helper |
10 | 11 |
11 from systrace import trace_result | 12 from systrace import trace_result |
12 from systrace import tracing_agents | 13 from systrace import tracing_agents |
13 | 14 |
14 | 15 |
15 _ATRACE_OPTIONS = [ | 16 _ATRACE_OPTIONS = [ |
16 # Compress the trace before sending it over USB. | 17 # Compress the trace before sending it over USB. |
17 '-z', | 18 '-z', |
18 # Use a large trace buffer to increase the polling interval. | 19 # Use a large trace buffer to increase the polling interval. |
19 '-b', '16384' | 20 '-b', '16384' |
20 ] | 21 ] |
21 | 22 |
22 # Interval in seconds for sampling atrace data. | 23 # Interval in seconds for sampling atrace data. |
23 _ATRACE_INTERVAL = 15 | 24 _ATRACE_INTERVAL = 15 |
24 | 25 |
25 _TRACING_ON_PATH = '/sys/kernel/debug/tracing/tracing_on' | 26 _TRACING_ON_PATH = '/sys/kernel/debug/tracing/tracing_on' |
26 | 27 |
27 | 28 |
28 class AtraceAgent(tracing_agents.TracingAgent): | 29 class AtraceAgent(tracing_agents.TracingAgent): |
29 def __init__(self, device, categories, ring_buffer): | 30 def __init__(self, device, ring_buffer): |
30 tracing_agents.TracingAgent.__init__(self) | 31 tracing_agents.TracingAgent.__init__(self) |
31 self._device = device | 32 self._device = device |
32 self._categories = categories | |
33 self._ring_buffer = ring_buffer | 33 self._ring_buffer = ring_buffer |
34 self._done = threading.Event() | 34 self._done = threading.Event() |
35 self._thread = None | 35 self._thread = None |
36 self._trace_data = None | 36 self._trace_data = None |
37 self._categories = None | |
37 | 38 |
38 def __repr__(self): | 39 def __repr__(self): |
39 return 'atrace' | 40 return 'atrace' |
40 | 41 |
41 @staticmethod | 42 @staticmethod |
42 def GetCategories(device): | 43 def GetCategories(device): |
43 return device.RunShellCommand('atrace --list_categories') | 44 return device.RunShellCommand('atrace --list_categories') |
44 | 45 |
45 @py_utils.Timeout(tracing_agents.START_STOP_TIMEOUT) | 46 @py_utils.Timeout(tracing_agents.START_STOP_TIMEOUT) |
46 def StartAgentTracing(self, options, categories, timeout=None): | 47 def StartAgentTracing(self, config, timeout=None): |
48 self._categories = _ComputeAtraceCategories(config) | |
47 self._thread = threading.Thread(target=self._CollectData) | 49 self._thread = threading.Thread(target=self._CollectData) |
48 self._thread.start() | 50 self._thread.start() |
49 | 51 |
50 @py_utils.Timeout(tracing_agents.START_STOP_TIMEOUT) | 52 @py_utils.Timeout(tracing_agents.START_STOP_TIMEOUT) |
51 def StopAgentTracing(self, timeout=None): | 53 def StopAgentTracing(self, timeout=None): |
52 self._done.set() | 54 self._done.set() |
53 | 55 |
54 @py_utils.Timeout(tracing_agents.GET_RESULTS_TIMEOUT) | 56 @py_utils.Timeout(tracing_agents.GET_RESULTS_TIMEOUT) |
55 def GetResults(self, timeout=None): | 57 def GetResults(self, timeout=None): |
56 self._thread.join() | 58 self._thread.join() |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
110 except ValueError: | 112 except ValueError: |
111 raise RuntimeError('Atrace start marker not found') | 113 raise RuntimeError('Atrace start marker not found') |
112 trace_data = trace_data[trace_start + 6:] | 114 trace_data = trace_data[trace_start + 6:] |
113 | 115 |
114 # Collapse CRLFs that are added by adb shell. | 116 # Collapse CRLFs that are added by adb shell. |
115 if trace_data.startswith('\r\n'): | 117 if trace_data.startswith('\r\n'): |
116 trace_data = trace_data.replace('\r\n', '\n') | 118 trace_data = trace_data.replace('\r\n', '\n') |
117 | 119 |
118 # Skip the initial newline. | 120 # Skip the initial newline. |
119 return trace_data[1:] | 121 return trace_data[1:] |
122 | |
123 | |
124 class AtraceConfig(tracing_agents.TracingConfig): | |
125 def __init__(self, atrace_categories): | |
126 tracing_agents.TracingConfig.__init__(self) | |
127 self.atrace_categories = atrace_categories | |
128 | |
129 | |
130 def add_options(parser): | |
131 atrace_opts = optparse.OptionGroup(parser, 'Atrace tracing options') | |
132 atrace_opts.add_option('-s', '--systrace', help='Capture a systrace with ' | |
133 'the chosen comma-delimited systrace categories. You' | |
134 ' can also capture a combined Chrome + systrace by ' | |
135 'enabling both types of categories. Use "list" to ' | |
136 'see the available categories. Systrace is disabled' | |
137 ' by default. Note that in this case, Systrace is ' | |
138 'synonymous with Atrace.', | |
139 metavar='ATRACE_CATEGORIES', | |
140 dest='atrace_categories', default='') | |
141 return atrace_opts | |
142 | |
143 def get_config(options): | |
144 return AtraceConfig(options.atrace_categories) | |
145 | |
146 def _ComputeAtraceCategories(config): | |
147 if not config.atrace_categories: | |
148 return [] | |
Zhen Wang
2016/08/29 16:30:20
Are there default ones that we want to include? Yo
washingtonp
2016/08/29 20:00:41
Done.
| |
149 return config.atrace_categories.split(',') | |
OLD | NEW |