OLD | NEW |
---|---|
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 | 2 |
3 # Copyright 2016 The Chromium Authors. All rights reserved. | 3 # Copyright 2016 The Chromium Authors. All rights reserved. |
4 # Use of this source code is governed by a BSD-style license that can be | 4 # Use of this source code is governed by a BSD-style license that can be |
5 # found in the LICENSE file. | 5 # found in the LICENSE file. |
6 | 6 |
7 '''Tracing controller class. This class manages | 7 '''Tracing controller class. This class manages |
8 multiple tracing agents and collects data from all of them. It also | 8 multiple tracing agents and collects data from all of them. It also |
9 manages the clock sync process. | 9 manages the clock sync process. |
10 ''' | 10 ''' |
11 | 11 |
12 import ast | 12 import ast |
13 import json | 13 import json |
14 import sys | 14 import sys |
15 import py_utils | 15 import py_utils |
16 import tempfile | 16 import tempfile |
17 import uuid | 17 import uuid |
18 | 18 |
19 from systrace import trace_result | 19 from systrace import trace_result |
20 from systrace import tracing_agents | 20 from systrace import tracing_agents |
21 from systrace.tracing_agents import monsoon_agent | |
21 from py_trace_event import trace_event | 22 from py_trace_event import trace_event |
22 | 23 |
23 | 24 |
24 TRACE_DATA_CONTROLLER_NAME = 'systraceController' | 25 TRACE_DATA_CONTROLLER_NAME = 'systraceController' |
25 | 26 |
26 | 27 |
27 def ControllerAgentClockSync(issue_ts, name): | 28 def ControllerAgentClockSync(issue_ts, name): |
28 """Record the clock sync marker for controller tracing agent. | 29 """Record the clock sync marker for controller tracing agent. |
29 | 30 |
30 Unlike with the other tracing agents, the tracing controller should not | 31 Unlike with the other tracing agents, the tracing controller should not |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
110 | 111 |
111 Args: | 112 Args: |
112 agents_with_config: List of tracing agents for this controller with the | 113 agents_with_config: List of tracing agents for this controller with the |
113 corresponding tracing configuration objects. | 114 corresponding tracing configuration objects. |
114 controller_config: Configuration options for the tracing controller. | 115 controller_config: Configuration options for the tracing controller. |
115 """ | 116 """ |
116 self._child_agents = None | 117 self._child_agents = None |
117 self._child_agents_with_config = agents_with_config | 118 self._child_agents_with_config = agents_with_config |
118 self._controller_agent = TracingControllerAgent() | 119 self._controller_agent = TracingControllerAgent() |
119 self._controller_config = controller_config | 120 self._controller_config = controller_config |
121 self._monsoon_agent = None | |
120 self._trace_in_progress = False | 122 self._trace_in_progress = False |
121 self.all_results = None | 123 self.all_results = None |
122 | 124 |
125 # If we have a monsoon power monitor controller in the group, make an | |
Chris Craik
2017/09/19 18:47:02
I'm not especially happy with this, but I don't ha
Zhen Wang
2017/09/19 23:53:50
I see --usbpassthrough is set to off for monsoon.
| |
126 # explicit reference to it. We need to collect data from it before any | |
127 # other collectors as it re-enables USB for the subsequent collectors to | |
128 # collect their data. | |
129 # In addition, move this agent to the end of the list so it is the last | |
130 # to start (it disables USB). | |
131 monsoon_agent_with_config = None | |
132 sorted_agents_with_config = [] | |
133 for agent_with_config in self._child_agents_with_config: | |
134 if isinstance(agent_with_config.agent, monsoon_agent.MonsoonTracingAgent): | |
135 monsoon_agent_with_config = agent_with_config | |
136 else: | |
137 sorted_agents_with_config.append(agent_with_config) | |
138 if monsoon_agent_with_config: | |
139 sorted_agents_with_config.append(monsoon_agent_with_config) | |
140 self._monsoon_agent = monsoon_agent_with_config.agent | |
141 self._child_agents_with_config = sorted_agents_with_config | |
142 | |
123 @property | 143 @property |
124 def get_child_agents(self): | 144 def get_child_agents(self): |
125 return self._child_agents | 145 return self._child_agents |
126 | 146 |
127 def StartTracing(self): | 147 def StartTracing(self): |
128 """Start tracing for all tracing agents. | 148 """Start tracing for all tracing agents. |
129 | 149 |
130 This function starts tracing for both the controller tracing agent | 150 This function starts tracing for both the controller tracing agent |
131 and the child tracing agents. | 151 and the child tracing agents. |
132 | 152 |
(...skipping 23 matching lines...) Expand all Loading... | |
156 succ_agents.append(agent) | 176 succ_agents.append(agent) |
157 else: | 177 else: |
158 print 'Agent %s not started.' % str(agent) | 178 print 'Agent %s not started.' % str(agent) |
159 | 179 |
160 # Print warning if all agents not started. | 180 # Print warning if all agents not started. |
161 na = len(self._child_agents_with_config) | 181 na = len(self._child_agents_with_config) |
162 ns = len(succ_agents) | 182 ns = len(succ_agents) |
163 if ns < na: | 183 if ns < na: |
164 print 'Warning: Only %d of %d tracing agents started.' % (ns, na) | 184 print 'Warning: Only %d of %d tracing agents started.' % (ns, na) |
165 self._child_agents = succ_agents | 185 self._child_agents = succ_agents |
186 | |
166 return True | 187 return True |
167 | 188 |
168 def StopTracing(self): | 189 def StopTracing(self): |
169 """Issue clock sync marker and stop tracing for all tracing agents. | 190 """Issue clock sync marker and stop tracing for all tracing agents. |
170 | 191 |
171 This function stops both the controller tracing agent | 192 This function stops both the controller tracing agent |
172 and the child tracing agents. It issues a clock sync marker prior | 193 and the child tracing agents. It issues a clock sync marker prior |
173 to stopping tracing. | 194 to stopping tracing. |
174 | 195 |
175 Returns: | 196 Returns: |
176 Boolean indicating whether or not the stop tracing succeeded | 197 Boolean indicating whether or not the stop tracing succeeded |
177 for all agents. | 198 for all agents. |
178 """ | 199 """ |
179 assert self._trace_in_progress, 'No trace in progress.' | 200 assert self._trace_in_progress, 'No trace in progress.' |
180 self._trace_in_progress = False | 201 self._trace_in_progress = False |
181 | 202 |
203 # Explicity stop Monsoon tracing first, as it re-enables USB. | |
204 if self._monsoon_agent: | |
205 sync_id = GetUniqueSyncID() | |
206 if not self._monsoon_agent.StopCollectionWithClockSync(sync_id, | |
207 ControllerAgentClockSync): | |
208 print 'Monsoon agent failed to stop collection.' | |
209 | |
182 # Issue the clock sync marker and stop the child tracing agents. | 210 # Issue the clock sync marker and stop the child tracing agents. |
183 self._IssueClockSyncMarker() | 211 self._IssueClockSyncMarker() |
184 succ_agents = [] | 212 succ_agents = [] |
185 for agent in self._child_agents: | 213 for agent in self._child_agents: |
186 if agent.StopAgentTracing(timeout=self._controller_config.timeout): | 214 if agent.StopAgentTracing(timeout=self._controller_config.timeout): |
187 succ_agents.append(agent) | 215 succ_agents.append(agent) |
188 else: | 216 else: |
189 print 'Agent %s not stopped.' % str(agent) | 217 print 'Agent %s not stopped.' % str(agent) |
190 | 218 |
191 # Stop the controller tracing agent. Controller tracing agent | 219 # Stop the controller tracing agent. Controller tracing agent |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
297 return TracingControllerConfig(options.output_file, options.trace_time, | 325 return TracingControllerConfig(options.output_file, options.trace_time, |
298 options.write_json, | 326 options.write_json, |
299 options.link_assets, options.asset_dir, | 327 options.link_assets, options.asset_dir, |
300 options.timeout, options.collection_timeout, | 328 options.timeout, options.collection_timeout, |
301 options.device_serial_number, options.target) | 329 options.device_serial_number, options.target) |
302 | 330 |
303 def GetChromeStartupControllerConfig(options): | 331 def GetChromeStartupControllerConfig(options): |
304 return TracingControllerConfig(None, options.trace_time, | 332 return TracingControllerConfig(None, options.trace_time, |
305 options.write_json, None, None, None, None, | 333 options.write_json, None, None, None, None, |
306 None, None) | 334 None, None) |
OLD | NEW |