Index: tools/telemetry/telemetry/core/backends/chrome/tracing_backend.py |
diff --git a/tools/telemetry/telemetry/core/backends/chrome/tracing_backend.py b/tools/telemetry/telemetry/core/backends/chrome/tracing_backend.py |
index 4d0c68a8a3edb617314407f60d0a8624407e4a14..d0c696c2aeaf693cdd934959084df6bee1608f39 100644 |
--- a/tools/telemetry/telemetry/core/backends/chrome/tracing_backend.py |
+++ b/tools/telemetry/telemetry/core/backends/chrome/tracing_backend.py |
@@ -8,7 +8,6 @@ import logging |
import socket |
import threading |
- |
from telemetry.core.backends.chrome import trace_result |
from telemetry.core.backends.chrome import websocket |
from telemetry.core.backends.chrome import websocket_browser_connection |
@@ -70,9 +69,19 @@ class TracingBackend(object): |
self._conn = websocket_browser_connection.WebSocketBrowserConnection( |
devtools_port) |
self._thread = None |
+ self._nesting = 0 |
self._tracing_data = [] |
- def BeginTracing(self, custom_categories=None, timeout=10): |
+ def _IsTracing(self): |
+ return self._thread != None |
+ |
+ def StartTracing(self, custom_categories=None, timeout=10): |
+ """ Starts tracing on the first nested call and returns True. Returns False |
+ and does nothing on subsequent nested calls. |
+ """ |
+ self._nesting += 1 |
+ if self._IsTracing(): |
+ return False |
self._CheckNotificationSupported() |
req = {'method': 'Tracing.start'} |
if custom_categories: |
@@ -82,22 +91,37 @@ class TracingBackend(object): |
# data, until Tracing.end is called. |
self._thread = threading.Thread(target=self._TracingReader) |
self._thread.start() |
+ return True |
+ |
+ def StopTracing(self): |
+ """ Stops tracing on the innermost (!) nested call, because we cannot get |
+ results otherwise. Resets _tracing_data on the outermost nested call. |
+ Returns the result of the trace, as TraceResult object. |
+ """ |
+ self._nesting -= 1 |
tonyg
2013/09/12 00:49:55
Let's assert that _nesting doesn't go negative
ernstm
2013/09/12 18:06:07
Done.
|
+ if self._IsTracing(): |
+ req = {'method': 'Tracing.end'} |
+ self._conn.SendRequest(req) |
+ self._thread.join() |
+ self._thread = None |
+ if self._nesting == 0: |
+ return self._GetTraceResultAndReset() |
+ else: |
+ return self._GetTraceResult() |
- def EndTracing(self): |
- req = {'method': 'Tracing.end'} |
- self._conn.SendRequest(req) |
- self._thread.join() |
- self._thread = None |
- |
- def GetTraceResultAndReset(self): |
- assert not self._thread |
+ def _GetTraceResult(self): |
+ assert not self._IsTracing() |
if self._tracing_data and type(self._tracing_data[0]) in [str, unicode]: |
result_impl = TraceResultImpl(self._tracing_data) |
else: |
result_impl = RawTraceResultImpl(self._tracing_data) |
- self._tracing_data = [] |
return trace_result.TraceResult(result_impl) |
+ def _GetTraceResultAndReset(self): |
+ result = self._GetTraceResult() |
+ self._tracing_data = [] |
+ return result |
+ |
def _TracingReader(self): |
while self._conn.socket: |
try: |