| 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..b8bb17716704b551e437079aa1ed970de84e8c7d
|
| --- /dev/null
|
| +++ b/tools/telemetry/telemetry/core/chrome/system_info_backend.py
|
| @@ -0,0 +1,56 @@
|
| +# 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 gpu_info
|
| +from telemetry.core.chrome import websocket
|
| +
|
| +
|
| +class SystemInfoBackend(object):
|
| + 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 GetGPUInfo(self, timeout=10):
|
| + req = {'method': 'SystemInfo.getGPUInfo'}
|
| + 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 gpu_info.GPUInfo.FromDict(res['result'])
|
| + except (socket.error, websocket.WebSocketException):
|
| + logging.warning('Timeout waiting for GPU info, 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
|
|
|