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.
6 from telemetry
.core
import exceptions
9 class InspectorMemoryException(exceptions
.Error
):
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
):
23 def GetDOMCounters(self
, timeout
):
24 """Retrieves DOM element counts.
27 timeout: The number of seconds to wait for the inspector backend to
28 service the request before timing out.
31 A dictionary containing the counts associated with "nodes", "documents",
32 and "jsEventListeners".
34 InspectorMemoryException
35 websocket.WebSocketException
37 exceptions.WebSocketDisconnected
39 res
= self
._inspector
_websocket
.SyncRequest({
40 'method': 'Memory.getDOMCounters'
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))
50 'nodes': res
['result']['nodes'],
51 'documents': res
['result']['documents'],
52 'jsEventListeners': res
['result']['jsEventListeners']