Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(12)

Side by Side Diff: systrace/profile_chrome/atrace_tracing_agent.py

Issue 2276263003: Pass in custom options to Systrace agents (Closed) Base URL: https://chromium.googlesource.com/external/github.com/catapult-project/catapult.git@master
Patch Set: Rebase Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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):
Zhen Wang 2016/08/26 20:39:41 Is the plan to use the AtraceConfig in Systrace af
washingtonp 2016/08/27 02:22:43 Yes, this is just a temporary config since the atr
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(options):
147 if not options.atrace_categories:
148 return []
149 return options.atrace_categories.split(',')
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698