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

Unified Diff: tools/telemetry/telemetry/internal/backends/chrome_inspector/tracing_backend.py

Issue 1224083015: [telemetry] Add support for requesting memory dumps via DevTools API (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Final adjustments Created 5 years, 5 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/internal/backends/chrome_inspector/tracing_backend.py
diff --git a/tools/telemetry/telemetry/internal/backends/chrome_inspector/tracing_backend.py b/tools/telemetry/telemetry/internal/backends/chrome_inspector/tracing_backend.py
index eb976e8395931ae804de5eb030aeeabb171bde79..6a16a0bd69bebbdeadd0705c58083f827848516a 100644
--- a/tools/telemetry/telemetry/internal/backends/chrome_inspector/tracing_backend.py
+++ b/tools/telemetry/telemetry/internal/backends/chrome_inspector/tracing_backend.py
@@ -2,6 +2,7 @@
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
+import json
import logging
import socket
import time
@@ -28,6 +29,10 @@ class TracingHasNotRunException(Exception):
pass
+class TracingUnexpectedResponseException(Exception):
+ pass
+
+
class TracingBackend(object):
def __init__(self, devtools_port):
self._inspector_websocket = inspector_websocket.InspectorWebsocket()
@@ -90,6 +95,41 @@ class TracingBackend(object):
trace_data_builder.AddEventsTo(
trace_data_module.CHROME_TRACE_PART, self._trace_events)
+ def DumpMemory(self, timeout=30):
+ """Dumps memory.
+
+ Returns:
+ GUID of the generated dump if successful, None otherwise.
+
+ Raises:
+ TracingTimeoutException: If more than |timeout| seconds has passed
+ since the last time any data is received.
+ TracingUnrecoverableException: If there is a websocket error.
+ TracingUnexpectedResponseException: If the response contains an error
+ or does not contain the expected result.
+ """
+ request = {
+ 'method': 'Tracing.requestMemoryDump'
+ }
+ try:
+ response = self._inspector_websocket.SyncRequest(request, timeout)
+ except websocket.WebSocketTimeoutException:
+ raise TracingTimeoutException
+ except (socket.error, websocket.WebSocketException,
+ inspector_websocket.WebSocketDisconnected):
+ raise TracingUnrecoverableException
+
+ if ('error' in response or
+ 'result' not in response or
+ 'success' not in response['result'] or
+ 'dumpGuid' not in response['result']):
+ raise TracingUnexpectedResponseException(
+ 'Inspector returned unexpected response for '
+ 'Tracing.requestMemoryDump:\n' + json.dumps(response, indent=2))
+
+ result = response['result']
+ return result['dumpGuid'] if result['success'] else None
+
def _CollectTracingData(self, timeout):
"""Collects tracing data. Assumes that Tracing.end has already been sent.

Powered by Google App Engine
This is Rietveld 408576698