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

Unified Diff: tools/telemetry/telemetry/core/platform/tracing_controller_backend.py

Issue 853353005: [Telemetry] Add tracing_agent API. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix unittest breakage (bug in tracing_controller_backend) Created 5 years, 11 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 side-by-side diff with in-line comments
Download patch
Index: tools/telemetry/telemetry/core/platform/tracing_controller_backend.py
diff --git a/tools/telemetry/telemetry/core/platform/tracing_controller_backend.py b/tools/telemetry/telemetry/core/platform/tracing_controller_backend.py
index 3f5c18cb36d43d2c4ec803dbcf88d6abff689f03..980841f96fc9cde4048835508a16c41fad32b9e9 100644
--- a/tools/telemetry/telemetry/core/platform/tracing_controller_backend.py
+++ b/tools/telemetry/telemetry/core/platform/tracing_controller_backend.py
@@ -2,20 +2,37 @@
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
+import os
+
+from telemetry.core import discover
+from telemetry.core import util
from telemetry.core.platform import tracing_category_filter
from telemetry.core.platform import tracing_options
+from telemetry.core.platform import tracing_agent
+from telemetry.core.platform.tracing_agent import chrome_tracing_agent
+from telemetry.core.platform.tracing_agent import display_tracing_agent
from telemetry.timeline import trace_data as trace_data_module
+def _IterAllTracingAgentClasses():
+ tracing_agent_dir = os.path.dirname(os.path.join(
+ os.path.realpath(__file__), 'tracing_agent'))
+ return discover.DiscoverClasses(
+ tracing_agent_dir, util.GetTelemetryDir(),
+ tracing_agent.TracingAgent).itervalues()
+
+
class TracingControllerBackend(object):
def __init__(self, platform_backend):
self._platform_backend = platform_backend
self._current_trace_options = None
self._current_category_filter = None
- # A map from uniquely-identifying remote port (which may be the
- # same as local port) to DevToolsClientBackend. There is no
- # guarantee that the devtools agent is still alive.
- self._devtools_clients_map = {}
+ self._current_chrome_tracing_agent = None
+ self._current_display_tracing_agent = None
+ self._supported_agents_classes = [
+ agent_classes for agent_classes in _IterAllTracingAgentClasses() if
+ agent_classes.IsSupported(platform_backend)]
+ self._active_agents_instances = []
def Start(self, trace_options, category_filter, timeout):
if self.is_tracing_running:
@@ -25,62 +42,38 @@ class TracingControllerBackend(object):
tracing_category_filter.TracingCategoryFilter)
assert isinstance(trace_options,
tracing_options.TracingOptions)
+ assert len(self._active_agents_instances) == 0
self._current_trace_options = trace_options
self._current_category_filter = category_filter
-
- if trace_options.enable_chrome_trace:
- self._RemoveStaleDevToolsClient()
- for _, devtools_client in self._devtools_clients_map.iteritems():
- devtools_client.StartChromeTracing(
- trace_options, category_filter.filter_string, timeout)
-
- if trace_options.enable_platform_display_trace:
- self._platform_backend.StartDisplayTracing()
-
- def _RemoveStaleDevToolsClient(self):
- """Removes DevTools clients that are no longer connectable."""
- self._devtools_clients_map = {
- port: client
- for port, client in self._devtools_clients_map.iteritems()
- if client.IsAlive()
- }
+ # Hack: chrome tracing agent depends on the number of alive chrome devtools
+ # processes, rather platform, hence we add it to the list of supported
+ # agents here if it was not added.
+ if (chrome_tracing_agent.ChromeTracingAgent.IsSupported(
+ self._platform_backend) and
+ not chrome_tracing_agent.ChromeTracingAgent in
+ self._supported_agents_classes):
+ self._supported_agents_classes.append(
+ chrome_tracing_agent.ChromeTracingAgent)
+
+ for agent_class in self._supported_agents_classes:
+ agent = agent_class(self._platform_backend)
+ if agent.Start(trace_options, category_filter, timeout):
+ self._active_agents_instances.append(agent)
def Stop(self):
assert self.is_tracing_running, 'Can only stop tracing when tracing.'
-
trace_data_builder = trace_data_module.TraceDataBuilder()
- if self._current_trace_options.enable_chrome_trace:
- for _, devtools_client in self._devtools_clients_map.iteritems():
- # We do not check for stale DevTools client, so that we get an
- # exception if there is a stale client. This is because we
- # will potentially lose data if there is a stale client.
- devtools_client.StopChromeTracing(trace_data_builder)
-
- if self._current_trace_options.enable_platform_display_trace:
- surface_flinger_trace_data = self._platform_backend.StopDisplayTracing()
- trace_data_builder.AddEventsTo(
- trace_data_module.SURFACE_FLINGER_PART, surface_flinger_trace_data)
-
+ for agent in self._active_agents_instances:
+ agent.Stop(trace_data_builder)
+ self._active_agents_instances = []
self._current_trace_options = None
self._current_category_filter = None
return trace_data_builder.AsData()
- def RegisterDevToolsClient(self, devtools_client_backend):
- assert not self.is_tracing_running, (
- 'Cannot add new DevTools client when tracing is running.')
- remote_port = str(devtools_client_backend.remote_port)
- self._devtools_clients_map[remote_port] = devtools_client_backend
-
def IsChromeTracingSupported(self):
- self._RemoveStaleDevToolsClient()
- for _, devtools_client in self._devtools_clients_map.iteritems():
- if devtools_client.IsChromeTracingSupported():
- return True
- return False
-
- def IsDisplayTracingSupported(self):
- return self._platform_backend.IsDisplayTracingSupported()
+ return chrome_tracing_agent.ChromeTracingAgent.IsSupported(
+ self._platform_backend)
@property
def is_tracing_running(self):

Powered by Google App Engine
This is Rietveld 408576698