Chromium Code Reviews| Index: tools/telemetry/telemetry/core/chrome/system_info_backend.py |
| diff --git a/tools/telemetry/telemetry/core/chrome/system_info_backend.py b/tools/telemetry/telemetry/core/chrome/system_info_backend.py |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..141fe5c56bff96fdbdcc05c6fd7c96fb808dd014 |
| --- /dev/null |
| +++ b/tools/telemetry/telemetry/core/chrome/system_info_backend.py |
| @@ -0,0 +1,58 @@ |
| +# 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 |
| +import logging |
| +import socket |
| + |
| + |
| +from telemetry.core import system_info |
| +from telemetry.core.chrome import websocket |
| +from telemetry.core.chrome import camel_case_converter as camel_case |
| + |
| + |
| +class SystemInfoBackend(object): |
|
nduca
2013/08/14 19:53:36
hmm looks like most of this code is just to establ
Ken Russell (switch to Gerrit)
2013/08/14 22:47:57
The tracing backend requires its own websocket con
|
| + def __init__(self, devtools_port): |
| + debugger_url = 'ws://localhost:%i/devtools/browser' % devtools_port |
| + self._socket = websocket.create_connection(debugger_url) |
| + self._next_request_id = 0 |
| + self._cur_socket_timeout = 0 |
| + self._thread = None |
| + self._tracing_data = [] |
| + |
| + def GetSystemInfo(self, timeout=10): |
| + req = {'method': 'SystemInfo.getInfo'} |
| + self._SyncRequest(req, timeout) |
| + while self._socket: |
| + try: |
| + data = self._socket.recv() |
| + if not data: |
| + break |
| + res = json.loads(data) |
| + if 'error' in res: |
| + return None |
| + logging.debug('got [%s]', data) |
| + return system_info.SystemInfo.FromDict( |
| + camel_case.CamelCaseConverter.FromCamelCase(res['result'])) |
| + except (socket.error, websocket.WebSocketException): |
| + logging.warning('Timeout waiting for system info; this is unusual.') |
| + return None |
| + |
| + def Close(self): |
| + if self._socket: |
| + self._socket.close() |
| + self._socket = None |
| + |
| + def _SyncRequest(self, req, timeout=10): |
| + self._SetTimeout(timeout) |
| + req['id'] = self._next_request_id |
| + self._next_request_id += 1 |
| + data = json.dumps(req) |
| + logging.debug('will send [%s]', data) |
| + self._socket.send(data) |
| + |
| + def _SetTimeout(self, timeout): |
| + if self._cur_socket_timeout != timeout: |
| + self._socket.settimeout(timeout) |
| + self._cur_socket_timeout = timeout |