Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 DEFAULT_TIMEOUT = 10 # seconds | |
|
Benoit L
2016/02/22 14:11:26
I usually prefer to have the unit in the name, suc
| |
| 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 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 210 if domain != self.TRACING_DOMAIN: | 213 if domain != self.TRACING_DOMAIN: |
| 211 self.SyncRequestNoResponse('%s.enable' % domain) | 214 self.SyncRequestNoResponse('%s.enable' % domain) |
| 212 # Tracing setup must be done by the tracing track to control filtering | 215 # Tracing setup must be done by the tracing track to control filtering |
| 213 # and output. | 216 # and output. |
| 214 for scoped_state in self._scoped_states: | 217 for scoped_state in self._scoped_states: |
| 215 self.SyncRequestNoResponse(scoped_state, | 218 self.SyncRequestNoResponse(scoped_state, |
| 216 self._scoped_states[scoped_state][0]) | 219 self._scoped_states[scoped_state][0]) |
| 217 self._tearing_down_tracing = False | 220 self._tearing_down_tracing = False |
| 218 self._set_up = True | 221 self._set_up = True |
| 219 | 222 |
| 220 def StartMonitoring(self): | 223 def StartMonitoring(self, timeout=DEFAULT_TIMEOUT): |
| 221 """Starts monitoring. | 224 """Starts monitoring. |
| 222 | 225 |
| 223 DevToolsConnection.SetUpMonitoring() has to be called first. | 226 DevToolsConnection.SetUpMonitoring() has to be called first. |
| 224 """ | 227 """ |
| 225 assert self._set_up, 'DevToolsConnection.SetUpMonitoring not called.' | 228 assert self._set_up, 'DevToolsConnection.SetUpMonitoring not called.' |
| 226 self._Dispatch() | 229 self._Dispatch(timeout=timeout) |
| 227 self._TearDownMonitoring() | 230 self._TearDownMonitoring() |
| 228 | 231 |
| 229 def StopMonitoring(self): | 232 def StopMonitoring(self): |
| 230 """Stops the monitoring.""" | 233 """Stops the monitoring.""" |
| 231 self._please_stop = True | 234 self._please_stop = True |
| 232 | 235 |
| 233 def _Dispatch(self, kind='Monitoring', timeout=10): | 236 def _Dispatch(self, kind='Monitoring', |
| 237 timeout=DEFAULT_TIMEOUT): | |
| 234 self._please_stop = False | 238 self._please_stop = False |
| 235 while not self._please_stop: | 239 while not self._please_stop: |
| 236 try: | 240 try: |
| 237 self._ws.DispatchNotifications(timeout=timeout) | 241 self._ws.DispatchNotifications(timeout=timeout) |
| 238 except websocket.WebSocketTimeoutException: | 242 except websocket.WebSocketTimeoutException: |
| 239 break | 243 break |
| 240 if not self._please_stop: | 244 if not self._please_stop: |
| 241 logging.warning('%s stopped on a timeout.' % kind) | 245 logging.warning('%s stopped on a timeout.' % kind) |
| 242 | 246 |
| 243 def _TearDownMonitoring(self): | 247 def _TearDownMonitoring(self): |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 357 """Returns a Track instance constructed from data dumped by | 361 """Returns a Track instance constructed from data dumped by |
| 358 Track.ToJsonDict(). | 362 Track.ToJsonDict(). |
| 359 | 363 |
| 360 Args: | 364 Args: |
| 361 json_data: (dict) Parsed from a JSON file using the json module. | 365 json_data: (dict) Parsed from a JSON file using the json module. |
| 362 | 366 |
| 363 Returns: | 367 Returns: |
| 364 a Track instance. | 368 a Track instance. |
| 365 """ | 369 """ |
| 366 pass | 370 pass |
| OLD | NEW |