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

Unified Diff: tools/telemetry/telemetry/internal/platform/tracing_agent/chrome_tracing_devtools_manager.py

Issue 1338033002: [Telemetry] Refactor Chrome devtools tracing (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: review fix Created 5 years, 3 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
« no previous file with comments | « tools/telemetry/telemetry/internal/platform/tracing_agent/chrome_tracing_agent_unittest.py ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tools/telemetry/telemetry/internal/platform/tracing_agent/chrome_tracing_devtools_manager.py
diff --git a/tools/telemetry/telemetry/internal/platform/tracing_agent/chrome_tracing_devtools_manager.py b/tools/telemetry/telemetry/internal/platform/tracing_agent/chrome_tracing_devtools_manager.py
new file mode 100644
index 0000000000000000000000000000000000000000..de51ea6a1ae4a61fa01dc5a6ae2766be706c8835
--- /dev/null
+++ b/tools/telemetry/telemetry/internal/platform/tracing_agent/chrome_tracing_devtools_manager.py
@@ -0,0 +1,67 @@
+# Copyright 2015 The Chromium Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+class RegisterDevToolsClientError(Exception):
+ pass
+
+
+# A singleton map from platform backends to maps of 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.
+_platform_backends_to_devtools_clients_maps = {}
+
+
+def _RemoveStaleDevToolsClient(platform_backend):
+ """Removes DevTools clients that are no longer connectable."""
+ devtools_clients_map = _platform_backends_to_devtools_clients_maps.get(
+ platform_backend, {})
+ devtools_clients_map = {
+ port: client
+ for port, client in devtools_clients_map.iteritems()
+ if client.IsAlive()
+ }
+ _platform_backends_to_devtools_clients_maps[platform_backend] = (
+ devtools_clients_map)
+
+
+def RegisterDevToolsClient(devtools_client_backend, platform_backend):
+ """Register DevTools client
+
+ This should only be called from DevToolsClientBackend when it is initialized.
+ """
+ if platform_backend.tracing_controller_backend.is_tracing_running:
+ raise RegisterDevToolsClientError(
+ 'Cannot add new DevTools client when tracing is running on '
+ 'platform backend %s.' % platform_backend)
+
+ remote_port = str(devtools_client_backend.remote_port)
+ if platform_backend not in _platform_backends_to_devtools_clients_maps:
+ _platform_backends_to_devtools_clients_maps[platform_backend] = {}
+ devtools_clients_map = (
+ _platform_backends_to_devtools_clients_maps[platform_backend])
+ devtools_clients_map[remote_port] = devtools_client_backend
+
+
+def IsSupported(platform_backend):
+ _RemoveStaleDevToolsClient(platform_backend)
+ devtools_clients_map = _platform_backends_to_devtools_clients_maps.get(
+ platform_backend, {})
+ for _, devtools_client in devtools_clients_map.iteritems():
+ if devtools_client.IsChromeTracingSupported():
+ return True
+ return False
+
+
+def GetDevToolsClients(platform_backend):
+ """Get DevTools clients including the ones that are no longer connectable."""
+ devtools_clients_map = _platform_backends_to_devtools_clients_maps.get(
+ platform_backend, {})
+ if not devtools_clients_map:
+ return []
+ return devtools_clients_map.values()
+
+def GetActiveDevToolsClients(platform_backend):
+ """Get DevTools clients that are still connectable."""
+ _RemoveStaleDevToolsClient(platform_backend)
+ return GetDevToolsClients(platform_backend)
« no previous file with comments | « tools/telemetry/telemetry/internal/platform/tracing_agent/chrome_tracing_agent_unittest.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698