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

Unified Diff: tools/telemetry/telemetry/core/chrome/inspector_memory.py

Issue 12800004: [Telemetry] Add tab API function GetJavascriptStats(). (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Addressed second round of review comments. Created 7 years, 9 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/chrome/inspector_memory.py
diff --git a/tools/telemetry/telemetry/core/chrome/inspector_memory.py b/tools/telemetry/telemetry/core/chrome/inspector_memory.py
new file mode 100644
index 0000000000000000000000000000000000000000..931cb6e3ead46c0e60a3cf68b5127f379a547d03
--- /dev/null
+++ b/tools/telemetry/telemetry/core/chrome/inspector_memory.py
@@ -0,0 +1,50 @@
+# Copyright (c) 2013 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.
+import json
+
+class InspectorMemoryException(Exception):
+ pass
+
+class InspectorMemory(object):
+ """Communicates with the remote inspector's Memory domain."""
+
+ def __init__(self, inspector_backend):
+ self._inspector_backend = inspector_backend
+ self._inspector_backend.RegisterDomain(
+ 'Memory',
+ self._OnNotification,
+ self._OnClose)
+
+ def _OnNotification(self, msg):
+ pass
+
+ def _OnClose(self):
+ pass
+
+ def GetDOMCounters(self, timeout):
+ """Retrieves DOM element counts.
+
+ Args:
+ timeout: The number of seconds to wait for the inspector backend to
+ service the request before timing out.
+
+ Returns:
+ A dictionary containing the counts associated with "nodes", "documents",
+ and "jsEventListeners".
+ """
+ res = self._inspector_backend.SyncRequest({
+ 'method': 'Memory.getDOMCounters'
+ }, timeout)
+ if ('result' not in res or
+ 'nodes' not in res['result'] or
+ 'documents' not in res['result'] or
+ 'jsEventListeners' not in res['result']):
+ raise InspectorMemoryException(
+ 'Inspector returned unexpected result for Memory.getDOMCounters:\n' +
+ json.dumps(res, indent=2))
+ return {
+ 'nodes': res['result']['nodes'],
+ 'documents': res['result']['documents'],
+ 'jsEventListeners': res['result']['jsEventListeners']
+ }

Powered by Google App Engine
This is Rietveld 408576698