Chromium Code Reviews| Index: systrace/systrace/tracing_controller.py |
| diff --git a/systrace/systrace/tracing_controller.py b/systrace/systrace/tracing_controller.py |
| index 708bdf12e176ef738e7a59001695d8ee1cb06f01..1c2cdb517c1a4614c62de596a634c46fd59a09cf 100644 |
| --- a/systrace/systrace/tracing_controller.py |
| +++ b/systrace/systrace/tracing_controller.py |
| @@ -104,12 +104,12 @@ class TracingController(object): |
| corresponding tracing configuration objects. |
| controller_config: Configuration options for the tracing controller. |
| """ |
| - self._child_agents = None |
| self._child_agents_with_config = agents_with_config |
| self._controller_agent = TracingControllerAgent() |
| self._controller_config = controller_config |
| self._trace_in_progress = False |
| self.all_results = None |
| + self.child_agents = None |
| def StartTracing(self): |
| """Start tracing for all tracing agents. |
| @@ -149,7 +149,7 @@ class TracingController(object): |
| ns = len(succ_agents) |
| if ns < na: |
| print 'Warning: Only %d of %d tracing agents started.' % (ns, na) |
| - self._child_agents = succ_agents |
| + self.child_agents = succ_agents |
| return True |
| def StopTracing(self): |
| @@ -169,7 +169,7 @@ class TracingController(object): |
| # Issue the clock sync marker and stop the child tracing agents. |
| self._IssueClockSyncMarker() |
| succ_agents = [] |
| - for agent in self._child_agents: |
| + for agent in self.child_agents: |
| if agent.StopAgentTracing(timeout=self._controller_config.timeout): |
| succ_agents.append(agent) |
| else: |
| @@ -183,15 +183,15 @@ class TracingController(object): |
| return False |
| # Print warning if all agents not stopped. |
| - na = len(self._child_agents) |
| + na = len(self.child_agents) |
| ns = len(succ_agents) |
| if ns < na: |
| print 'Warning: Only %d of %d tracing agents stopped.' % (ns, na) |
| - self._child_agents = succ_agents |
| + self.child_agents = succ_agents |
| # Collect the results from all the stopped tracing agents. |
| all_results = [] |
| - for agent in self._child_agents + [self._controller_agent]: |
| + for agent in self.child_agents + [self._controller_agent]: |
| try: |
| result = agent.GetResults( |
| timeout=self._controller_config.collection_timeout) |
| @@ -213,10 +213,13 @@ class TracingController(object): |
| self.all_results = all_results |
| return all_results |
| + def GetTraceType(self): |
| + """Return a string representing the child agents that are being traced.""" |
| + return ' + '.join(map(str, self.child_agents)) |
|
Chris Craik
2016/09/01 17:24:05
should this sort the agents too, for consistency?
washingtonp
2016/09/01 17:44:41
Done.
|
| def _IssueClockSyncMarker(self): |
| """Issue clock sync markers to all the child tracing agents.""" |
| - for agent in self._child_agents: |
| + for agent in self.child_agents: |
| if agent.SupportsExplicitClockSync(): |
| sync_id = GetUniqueSyncID() |
| agent.RecordClockSyncMarker(sync_id, ControllerAgentClockSync) |
| @@ -228,3 +231,58 @@ def GetUniqueSyncID(): |
| (since UUIDs are not JSON serializable) |
| """ |
| return str(uuid.uuid4()) |
| + |
| + |
| +class AgentWithConfig(object): |
| + def __init__(self, agent, config): |
| + self.agent = agent |
| + self.config = config |
| + |
| + |
| +def CreateAgentsWithConfig(options, modules): |
| + """Create tracing agents. |
| + |
| + This function will determine which tracing agents are valid given the |
| + options and create those agents along with their corresponding configuration |
| + object. |
| + Args: |
| + options: The command-line options. |
| + modules: The modules for either Systrace or profile_chrome. |
| + TODO(washingtonp): After all profile_chrome agents are in |
| + Systrace, this parameter will no longer be valid. |
| + Returns: |
| + A list of AgentWithConfig options containing agents and their corresponding |
| + configuration object. |
| + """ |
| + result = [] |
| + for module in modules: |
| + config = module.get_config(options) |
| + agent = module.try_create_agent(config) |
| + if agent and config: |
| + result.append(AgentWithConfig(agent, config)) |
| + return [x for x in result if x and x.agent] |
| + |
| + |
| +class TracingControllerConfig(tracing_agents.TracingConfig): |
| + def __init__(self, output_file, trace_time, list_categories, write_json, |
| + link_assets, asset_dir, timeout, collection_timeout, |
| + device_serial_number, target): |
| + tracing_agents.TracingConfig.__init__(self) |
| + self.output_file = output_file |
| + self.trace_time = trace_time |
| + self.list_categories = list_categories |
| + self.write_json = write_json |
| + self.link_assets = link_assets |
| + self.asset_dir = asset_dir |
| + self.timeout = timeout |
| + self.collection_timeout = collection_timeout |
| + self.device_serial_number = device_serial_number |
| + self.target = target |
| + |
| + |
| +def GetControllerConfig(options): |
| + return TracingControllerConfig(options.output_file, options.trace_time, |
| + options.list_categories, options.write_json, |
| + options.link_assets, options.asset_dir, |
| + options.timeout, options.collection_timeout, |
| + options.device_serial_number, options.target) |