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

Unified Diff: tools/telemetry/telemetry/core/backends/chrome/inspector_backend.py

Issue 22923013: Add JS heap snapshotting infrastructure to Telemetry (part 1) (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 7 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 | « no previous file | tools/telemetry/telemetry/core/jsheap/__init__.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tools/telemetry/telemetry/core/backends/chrome/inspector_backend.py
diff --git a/tools/telemetry/telemetry/core/backends/chrome/inspector_backend.py b/tools/telemetry/telemetry/core/backends/chrome/inspector_backend.py
index f702ae2430381938b60afa28dd0f6e376e575874..9e9e13be30710627cd62403c2423199aad53b702 100644
--- a/tools/telemetry/telemetry/core/backends/chrome/inspector_backend.py
+++ b/tools/telemetry/telemetry/core/backends/chrome/inspector_backend.py
@@ -16,6 +16,7 @@ from telemetry.core.backends.chrome import inspector_page
from telemetry.core.backends.chrome import inspector_runtime
from telemetry.core.backends.chrome import inspector_timeline
from telemetry.core.backends.chrome import websocket
+from telemetry.core.jsheap import model
class InspectorException(Exception):
pass
@@ -294,7 +295,7 @@ class InspectorBackend(object):
self._HandleNotification(res)
continue
- if res['id'] != req['id']:
+ if 'id' not in res or res['id'] != req['id']:
logging.debug('Dropped reply: %s', json.dumps(res))
continue
return res
@@ -324,3 +325,34 @@ class InspectorBackend(object):
def CollectGarbage(self):
self._page.CollectGarbage()
+
+ def TakeJSHeapSnapshot(self, timeout=120):
+ # This is a hack to make the nested function be able to modify the
+ # variables.
+ snapshot_uid = [0]
+ snapshot = [[]]
+
+ def OnNotification(res):
+ if res['method'] == 'HeapProfiler.addProfileHeader':
+ snapshot_uid[0] = res['params']['header']['uid']
+ elif res['method'] == 'HeapProfiler.addHeapSnapshotChunk':
+ snapshot[0].append(res['params']['chunk'])
+ elif res['method'] == 'HeapProfiler.finishHeapSnapshot':
+ snapshot[0] = ''.join(snapshot[0])
+
+ def OnClose():
+ pass
+
+ self.RegisterDomain('HeapProfiler', OnNotification, OnClose)
+
+ self.SyncRequest({'method': 'Page.getResourceTree'}, timeout)
+ self.SyncRequest({'method': 'Debugger.enable'}, timeout)
+ self.SyncRequest({'method': 'HeapProfiler.clearProfiles'}, timeout)
+ self.SyncRequest({'method': 'HeapProfiler.takeHeapSnapshot',
+ 'params': {'detailed': True}}, timeout)
+ self.SyncRequest({'method': 'HeapProfiler.getHeapSnapshot',
+ 'params': {'uid': snapshot_uid[0]}}, timeout)
+
+ self.UnregisterDomain('HeapProfiler')
+
+ return model.JsHeapSnapshotModel(snapshot[0])
« no previous file with comments | « no previous file | tools/telemetry/telemetry/core/jsheap/__init__.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698