Index: systrace/systrace/tracing_controller.py |
diff --git a/systrace/systrace/tracing_controller.py b/systrace/systrace/tracing_controller.py |
index 708bdf12e176ef738e7a59001695d8ee1cb06f01..8f7b32d6e027d1710beda39f3b01ffa2f821b5f9 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 |
Zhen Wang
2016/09/07 16:37:11
Can you keep this private and create a property fu
washingtonp
2016/09/07 18:36:08
Done.
|
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 |
Zhen Wang
2016/09/07 16:37:11
Change this back to use private member |self._chil
washingtonp
2016/09/07 18:36:08
Done.
|
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,14 @@ 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.""" |
+ sorted_agents = sorted(map(str, self.child_agents)) |
+ return ' + '.join(sorted_agents) |
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 +232,63 @@ 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) |
+ |
+def GetStartupControllerConfig(options): |
Zhen Wang
2016/09/07 16:37:11
s/GetStartupControllerConfig/GetChromeStartupContr
washingtonp
2016/09/07 18:36:08
Done.
|
+ return TracingControllerConfig(None, options.trace_time, None, |
+ options.write_json, None, None, None, None, |
+ None, None) |