Update sdk/platform-tools to version 26.0.0.
[android_tools.git] / sdk / platform-tools / systrace / catapult / telemetry / telemetry / internal / backends / chrome_inspector / inspector_memory.py
blobcd4ddf01a7faa13d8f50f751dbd53a07db206894
1 # Copyright 2013 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file.
4 import json
6 from telemetry.core import exceptions
9 class InspectorMemoryException(exceptions.Error):
10 pass
13 class InspectorMemory(object):
14 """Communicates with the remote inspector's Memory domain."""
16 def __init__(self, inspector_websocket):
17 self._inspector_websocket = inspector_websocket
18 self._inspector_websocket.RegisterDomain('Memory', self._OnNotification)
20 def _OnNotification(self, msg):
21 pass
23 def GetDOMCounters(self, timeout):
24 """Retrieves DOM element counts.
26 Args:
27 timeout: The number of seconds to wait for the inspector backend to
28 service the request before timing out.
30 Returns:
31 A dictionary containing the counts associated with "nodes", "documents",
32 and "jsEventListeners".
33 Raises:
34 InspectorMemoryException
35 websocket.WebSocketException
36 socket.error
37 exceptions.WebSocketDisconnected
38 """
39 res = self._inspector_websocket.SyncRequest({
40 'method': 'Memory.getDOMCounters'
41 }, timeout)
42 if ('result' not in res or
43 'nodes' not in res['result'] or
44 'documents' not in res['result'] or
45 'jsEventListeners' not in res['result']):
46 raise InspectorMemoryException(
47 'Inspector returned unexpected result for Memory.getDOMCounters:\n' +
48 json.dumps(res, indent=2))
49 return {
50 'nodes': res['result']['nodes'],
51 'documents': res['result']['documents'],
52 'jsEventListeners': res['result']['jsEventListeners']