Chromium Code Reviews| 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 | |
|
Sami
2016/08/26 15:53:43
Not something for this patch, but we should consid
washingtonp
2016/08/26 18:50:54
I agree with this. The subcommand support, better
| |
| 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 | |
|
Sami
2016/08/26 15:53:43
nit: two blank lines around top level entries plea
washingtonp
2016/08/26 18:50:54
Done.
| |
| 123 class AtraceConfig(tracing_agents.TracingConfig): | |
| 124 def __init__(self, atrace_categories): | |
| 125 tracing_agents.TracingConfig.__init__(self) | |
| 126 self.atrace_categories = atrace_categories | |
| 127 | |
| 128 def add_options(parser): | |
| 129 atrace_opts = optparse.OptionGroup(parser, 'Atrace tracing options') | |
| 130 atrace_opts.add_option('-s', '--systrace', help='Capture a systrace with ' | |
| 131 'the chosen comma-delimited systrace categories. You' | |
| 132 ' can also capture a combined Chrome + systrace by ' | |
| 133 'enabling both types of categories. Use "list" to ' | |
| 134 'see the available categories. Systrace is disabled' | |
| 135 ' by default. Note that in this case, Systrace is ' | |
| 136 'synonymous with Atrace.', | |
| 137 metavar='ATRACE_CATEGORIES', | |
| 138 dest='atrace_categories', default='') | |
| 139 return atrace_opts | |
| 140 | |
| 141 def get_config(options): | |
| 142 return AtraceConfig(options.atrace_categories) | |
| 143 | |
| 144 def _ComputeAtraceCategories(options): | |
| 145 if not options.atrace_categories: | |
| 146 return [] | |
| 147 return options.atrace_categories.split(',') | |
| OLD | NEW |