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

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
26 # If a custom list of categories is not specified, traces will include
27 # these categories (if available on the device).
28 _DEFAULT_CATEGORIES = 'sched gfx view dalvik webview input disk am wm'.split()
29
25 _TRACING_ON_PATH = '/sys/kernel/debug/tracing/tracing_on' 30 _TRACING_ON_PATH = '/sys/kernel/debug/tracing/tracing_on'
26 31
27 32
28 class AtraceAgent(tracing_agents.TracingAgent): 33 class AtraceAgent(tracing_agents.TracingAgent):
29 def __init__(self, device, categories, ring_buffer): 34 def __init__(self, device, ring_buffer):
30 tracing_agents.TracingAgent.__init__(self) 35 tracing_agents.TracingAgent.__init__(self)
31 self._device = device 36 self._device = device
32 self._categories = categories
33 self._ring_buffer = ring_buffer 37 self._ring_buffer = ring_buffer
34 self._done = threading.Event() 38 self._done = threading.Event()
35 self._thread = None 39 self._thread = None
36 self._trace_data = None 40 self._trace_data = None
41 self._categories = None
37 42
38 def __repr__(self): 43 def __repr__(self):
39 return 'atrace' 44 return 'atrace'
40 45
41 @staticmethod 46 @staticmethod
42 def GetCategories(device): 47 def GetCategories(device):
43 return device.RunShellCommand('atrace --list_categories') 48 return device.RunShellCommand('atrace --list_categories')
44 49
45 @py_utils.Timeout(tracing_agents.START_STOP_TIMEOUT) 50 @py_utils.Timeout(tracing_agents.START_STOP_TIMEOUT)
46 def StartAgentTracing(self, options, categories, timeout=None): 51 def StartAgentTracing(self, config, timeout=None):
52 self._categories = _ComputeAtraceCategories(config)
47 self._thread = threading.Thread(target=self._CollectData) 53 self._thread = threading.Thread(target=self._CollectData)
48 self._thread.start() 54 self._thread.start()
49 55
50 @py_utils.Timeout(tracing_agents.START_STOP_TIMEOUT) 56 @py_utils.Timeout(tracing_agents.START_STOP_TIMEOUT)
51 def StopAgentTracing(self, timeout=None): 57 def StopAgentTracing(self, timeout=None):
52 self._done.set() 58 self._done.set()
53 59
54 @py_utils.Timeout(tracing_agents.GET_RESULTS_TIMEOUT) 60 @py_utils.Timeout(tracing_agents.GET_RESULTS_TIMEOUT)
55 def GetResults(self, timeout=None): 61 def GetResults(self, timeout=None):
56 self._thread.join() 62 self._thread.join()
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
110 except ValueError: 116 except ValueError:
111 raise RuntimeError('Atrace start marker not found') 117 raise RuntimeError('Atrace start marker not found')
112 trace_data = trace_data[trace_start + 6:] 118 trace_data = trace_data[trace_start + 6:]
113 119
114 # Collapse CRLFs that are added by adb shell. 120 # Collapse CRLFs that are added by adb shell.
115 if trace_data.startswith('\r\n'): 121 if trace_data.startswith('\r\n'):
116 trace_data = trace_data.replace('\r\n', '\n') 122 trace_data = trace_data.replace('\r\n', '\n')
117 123
118 # Skip the initial newline. 124 # Skip the initial newline.
119 return trace_data[1:] 125 return trace_data[1:]
126
127
128 class AtraceConfig(tracing_agents.TracingConfig):
129 def __init__(self, atrace_categories):
130 tracing_agents.TracingConfig.__init__(self)
131 self.atrace_categories = atrace_categories
132
133
134 def add_options(parser):
135 atrace_opts = optparse.OptionGroup(parser, 'Atrace tracing options')
136 atrace_opts.add_option('-s', '--systrace', help='Capture a systrace with '
137 'the chosen comma-delimited systrace categories. You'
138 ' can also capture a combined Chrome + systrace by '
139 'enabling both types of categories. Use "list" to '
140 'see the available categories. Systrace is disabled'
141 ' by default. Note that in this case, Systrace is '
142 'synonymous with Atrace.',
143 metavar='ATRACE_CATEGORIES',
144 dest='atrace_categories', default='')
145 return atrace_opts
146
147 def get_config(options):
148 return AtraceConfig(options.atrace_categories)
149
150 def _ComputeAtraceCategories(config):
151 if not config.atrace_categories:
152 return _DEFAULT_CATEGORIES
153 return config.atrace_categories.split(',')
OLDNEW
« no previous file with comments | « systrace/bin/adb_profile_chrome_startup ('k') | systrace/profile_chrome/atrace_tracing_agent_unittest.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698