Chromium Code Reviews| 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 ''' |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 110 | 110 |
| 111 Args: | 111 Args: |
| 112 agents_with_config: List of tracing agents for this controller with the | 112 agents_with_config: List of tracing agents for this controller with the |
| 113 corresponding tracing configuration objects. | 113 corresponding tracing configuration objects. |
| 114 controller_config: Configuration options for the tracing controller. | 114 controller_config: Configuration options for the tracing controller. |
| 115 """ | 115 """ |
| 116 self._child_agents = None | 116 self._child_agents = None |
| 117 self._child_agents_with_config = agents_with_config | 117 self._child_agents_with_config = agents_with_config |
| 118 self._controller_agent = TracingControllerAgent() | 118 self._controller_agent = TracingControllerAgent() |
| 119 self._controller_config = controller_config | 119 self._controller_config = controller_config |
| 120 self._connection_owner = None | |
| 120 self._trace_in_progress = False | 121 self._trace_in_progress = False |
| 121 self.all_results = None | 122 self.all_results = None |
| 122 | 123 |
| 124 # If we have a connection owner in the group, make an explicit reference to | |
| 125 # it. We need to collect data from it before any other collectors as it may | |
| 126 # re-enable USB for the subsequent collectors to collect their data. | |
| 127 # In addition, move this agent to the end of the list so it is the last | |
| 128 # to start (it could disable USB). | |
| 129 connection_owner_with_config = None | |
| 130 sorted_agents_with_config = [] | |
| 131 | |
| 132 for agent_with_config in self._child_agents_with_config: | |
| 133 if agent_with_config.agent.IsConnectionOwner(): | |
| 134 if connection_owner_with_config is not None: | |
| 135 raise Exception("Multiple connection owners found.") | |
| 136 connection_owner_with_config = agent_with_config | |
| 137 else: | |
| 138 sorted_agents_with_config.append(agent_with_config) | |
| 139 | |
| 140 if connection_owner_with_config: | |
| 141 sorted_agents_with_config.append(connection_owner_with_config) | |
| 142 self._connection_owner = connection_owner_with_config.agent | |
| 143 self._child_agents_with_config = sorted_agents_with_config | |
| 144 | |
| 123 @property | 145 @property |
| 124 def get_child_agents(self): | 146 def get_child_agents(self): |
| 125 return self._child_agents | 147 return self._child_agents |
| 126 | 148 |
| 127 def StartTracing(self): | 149 def StartTracing(self): |
| 128 """Start tracing for all tracing agents. | 150 """Start tracing for all tracing agents. |
| 129 | 151 |
| 130 This function starts tracing for both the controller tracing agent | 152 This function starts tracing for both the controller tracing agent |
| 131 and the child tracing agents. | 153 and the child tracing agents. |
| 132 | 154 |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 156 succ_agents.append(agent) | 178 succ_agents.append(agent) |
| 157 else: | 179 else: |
| 158 print 'Agent %s not started.' % str(agent) | 180 print 'Agent %s not started.' % str(agent) |
| 159 | 181 |
| 160 # Print warning if all agents not started. | 182 # Print warning if all agents not started. |
| 161 na = len(self._child_agents_with_config) | 183 na = len(self._child_agents_with_config) |
| 162 ns = len(succ_agents) | 184 ns = len(succ_agents) |
| 163 if ns < na: | 185 if ns < na: |
| 164 print 'Warning: Only %d of %d tracing agents started.' % (ns, na) | 186 print 'Warning: Only %d of %d tracing agents started.' % (ns, na) |
| 165 self._child_agents = succ_agents | 187 self._child_agents = succ_agents |
| 188 | |
| 166 return True | 189 return True |
| 167 | 190 |
| 168 def StopTracing(self): | 191 def StopTracing(self): |
| 169 """Issue clock sync marker and stop tracing for all tracing agents. | 192 """Issue clock sync marker and stop tracing for all tracing agents. |
| 170 | 193 |
| 171 This function stops both the controller tracing agent | 194 This function stops both the controller tracing agent |
| 172 and the child tracing agents. It issues a clock sync marker prior | 195 and the child tracing agents. It issues a clock sync marker prior |
| 173 to stopping tracing. | 196 to stopping tracing. |
| 174 | 197 |
| 175 Returns: | 198 Returns: |
| 176 Boolean indicating whether or not the stop tracing succeeded | 199 Boolean indicating whether or not the stop tracing succeeded |
| 177 for all agents. | 200 for all agents. |
| 178 """ | 201 """ |
| 179 assert self._trace_in_progress, 'No trace in progress.' | 202 assert self._trace_in_progress, 'No trace in progress.' |
| 180 self._trace_in_progress = False | 203 self._trace_in_progress = False |
| 181 | 204 |
| 205 # Explicity stop the connection owner (if any) tracing first, as it may | |
| 206 # re-enable USB. | |
| 207 if self._connection_owner: | |
| 208 sync_id = GetUniqueSyncID() | |
| 209 if not self._connection_owner.StopCollectionWithClockSync(sync_id, | |
|
Zhen Wang
2017/09/28 01:58:48
Do we still need this |StopCollectionWithClockSync
| |
| 210 ControllerAgentClockSync): | |
| 211 print 'Connection owner failed to stop collection.' | |
| 212 | |
| 182 # Issue the clock sync marker and stop the child tracing agents. | 213 # Issue the clock sync marker and stop the child tracing agents. |
| 183 self._IssueClockSyncMarker() | 214 self._IssueClockSyncMarker() |
| 184 succ_agents = [] | 215 succ_agents = [] |
| 185 for agent in self._child_agents: | 216 for agent in self._child_agents: |
| 186 if agent.StopAgentTracing(timeout=self._controller_config.timeout): | 217 if agent.StopAgentTracing(timeout=self._controller_config.timeout): |
| 187 succ_agents.append(agent) | 218 succ_agents.append(agent) |
| 188 else: | 219 else: |
| 189 print 'Agent %s not stopped.' % str(agent) | 220 print 'Agent %s not stopped.' % str(agent) |
| 190 | 221 |
| 191 # Stop the controller tracing agent. Controller tracing agent | 222 # 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, | 328 return TracingControllerConfig(options.output_file, options.trace_time, |
| 298 options.write_json, | 329 options.write_json, |
| 299 options.link_assets, options.asset_dir, | 330 options.link_assets, options.asset_dir, |
| 300 options.timeout, options.collection_timeout, | 331 options.timeout, options.collection_timeout, |
| 301 options.device_serial_number, options.target) | 332 options.device_serial_number, options.target) |
| 302 | 333 |
| 303 def GetChromeStartupControllerConfig(options): | 334 def GetChromeStartupControllerConfig(options): |
| 304 return TracingControllerConfig(None, options.trace_time, | 335 return TracingControllerConfig(None, options.trace_time, |
| 305 options.write_json, None, None, None, None, | 336 options.write_json, None, None, None, None, |
| 306 None, None) | 337 None, None) |
| OLD | NEW |