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

Side by Side Diff: tools/android/loading/devtools_monitor.py

Issue 1707363002: sandwich: Implements network condition on WPR server and browser. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@i00
Patch Set: Created 4 years, 10 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 unified diff | Download patch
OLDNEW
1 # Copyright (c) 2016 The Chromium Authors. All rights reserved. 1 # Copyright (c) 2016 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be 2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file. 3 # found in the LICENSE file.
4 4
5 """Library handling DevTools websocket interaction. 5 """Library handling DevTools websocket interaction.
6 """ 6 """
7 7
8 import httplib 8 import httplib
9 import json 9 import json
10 import logging 10 import logging
11 import os 11 import os
12 import sys 12 import sys
13 13
14 file_dir = os.path.dirname(__file__) 14 file_dir = os.path.dirname(__file__)
15 sys.path.append(os.path.join(file_dir, '..', '..', 'perf')) 15 sys.path.append(os.path.join(file_dir, '..', '..', 'perf'))
16 from chrome_telemetry_build import chromium_config 16 from chrome_telemetry_build import chromium_config
17 sys.path.append(chromium_config.GetTelemetryDir()) 17 sys.path.append(chromium_config.GetTelemetryDir())
18 18
19 from telemetry.internal.backends.chrome_inspector import inspector_websocket 19 from telemetry.internal.backends.chrome_inspector import inspector_websocket
20 from telemetry.internal.backends.chrome_inspector import websocket 20 from telemetry.internal.backends.chrome_inspector import websocket
21 21
22 22
23 WEBSOCKET_TIMEOUT = 10 # seconds
Benoit L 2016/02/18 13:01:25 This is not really a websocket timeout. It's rathe
gabadie 2016/02/18 13:21:58 Done.
24
25
23 class DevToolsConnectionException(Exception): 26 class DevToolsConnectionException(Exception):
24 def __init__(self, message): 27 def __init__(self, message):
25 super(DevToolsConnectionException, self).__init__(message) 28 super(DevToolsConnectionException, self).__init__(message)
26 logging.warning("DevToolsConnectionException: " + message) 29 logging.warning("DevToolsConnectionException: " + message)
27 30
28 31
29 # Taken from telemetry.internal.backends.chrome_inspector.tracing_backend. 32 # Taken from telemetry.internal.backends.chrome_inspector.tracing_backend.
30 # TODO(mattcary): combine this with the above and export? 33 # TODO(mattcary): combine this with the above and export?
31 class _StreamReader(object): 34 class _StreamReader(object):
32 def __init__(self, inspector, stream_handle): 35 def __init__(self, inspector, stream_handle):
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after
182 def SetUpMonitoring(self): 185 def SetUpMonitoring(self):
183 for domain in self._domains_to_enable: 186 for domain in self._domains_to_enable:
184 self._ws.RegisterDomain(domain, self._OnDataReceived) 187 self._ws.RegisterDomain(domain, self._OnDataReceived)
185 if domain != self.TRACING_DOMAIN: 188 if domain != self.TRACING_DOMAIN:
186 self.SyncRequestNoResponse('%s.enable' % domain) 189 self.SyncRequestNoResponse('%s.enable' % domain)
187 # Tracing setup must be done by the tracing track to control filtering 190 # Tracing setup must be done by the tracing track to control filtering
188 # and output. 191 # and output.
189 self._tearing_down_tracing = False 192 self._tearing_down_tracing = False
190 self._set_up = True 193 self._set_up = True
191 194
192 def StartMonitoring(self): 195 def StartMonitoring(self, timeout=WEBSOCKET_TIMEOUT):
193 """Starts monitoring. 196 """Starts monitoring.
194 197
195 DevToolsConnection.SetUpMonitoring() has to be called first. 198 DevToolsConnection.SetUpMonitoring() has to be called first.
196 """ 199 """
197 assert self._set_up, 'DevToolsConnection.SetUpMonitoring not called.' 200 assert self._set_up, 'DevToolsConnection.SetUpMonitoring not called.'
198 self._Dispatch() 201 self._Dispatch(timeout=timeout)
199 self._TearDownMonitoring() 202 self._TearDownMonitoring()
200 203
201 def StopMonitoring(self): 204 def StopMonitoring(self):
202 """Stops the monitoring.""" 205 """Stops the monitoring."""
203 self._please_stop = True 206 self._please_stop = True
204 207
205 def _Dispatch(self, kind='Monitoring', timeout=10): 208 def _Dispatch(self, kind='Monitoring',
209 timeout=WEBSOCKET_TIMEOUT):
206 self._please_stop = False 210 self._please_stop = False
207 while not self._please_stop: 211 while not self._please_stop:
208 try: 212 try:
209 self._ws.DispatchNotifications(timeout=timeout) 213 self._ws.DispatchNotifications(timeout=timeout)
210 except websocket.WebSocketTimeoutException: 214 except websocket.WebSocketTimeoutException:
211 break 215 break
212 if not self._please_stop: 216 if not self._please_stop:
213 logging.warning('%s stopped on a timeout.' % kind) 217 logging.warning('%s stopped on a timeout.' % kind)
214 218
215 def _TearDownMonitoring(self): 219 def _TearDownMonitoring(self):
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
325 """Returns a Track instance constructed from data dumped by 329 """Returns a Track instance constructed from data dumped by
326 Track.ToJsonDict(). 330 Track.ToJsonDict().
327 331
328 Args: 332 Args:
329 json_data: (dict) Parsed from a JSON file using the json module. 333 json_data: (dict) Parsed from a JSON file using the json module.
330 334
331 Returns: 335 Returns:
332 a Track instance. 336 a Track instance.
333 """ 337 """
334 pass 338 pass
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698