OLD | NEW |
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # Copyright 2017 The Chromium Authors. All rights reserved. | 2 # Copyright 2017 The Chromium Authors. All rights reserved. |
3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
5 | 5 |
6 # This is intended to be a very trimmed down, single-file, hackable, and easy | 6 # This is intended to be a very trimmed down, single-file, hackable, and easy |
7 # to understand version of Telemetry. It's able to run simple user stories on | 7 # to understand version of Telemetry. It's able to run simple user stories on |
8 # Android, grab traces, and extract metrics from them. May be useful to | 8 # Android, grab traces, and extract metrics from them. May be useful to |
9 # diagnose issues with Chrome, reproduce regressions or prototype new user | 9 # diagnose issues with Chrome, reproduce regressions or prototype new user |
10 # stories. | 10 # stories. |
(...skipping 308 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
319 def __enter__(self): | 319 def __enter__(self): |
320 self.Open() | 320 self.Open() |
321 return self | 321 return self |
322 | 322 |
323 def __exit__(self, *args, **kwargs): | 323 def __exit__(self, *args, **kwargs): |
324 self.Close() | 324 self.Close() |
325 | 325 |
326 @RetryOn(socket.error) | 326 @RetryOn(socket.error) |
327 def Open(self): | 327 def Open(self): |
328 assert self._socket is None | 328 assert self._socket is None |
329 # pylint: disable=no-member | 329 self._socket = websocket.create_connection(self._url) |
330 self._socket = websocket.CreateConnection(self._url) | |
331 | 330 |
332 def Close(self): | 331 def Close(self): |
333 if self._socket is not None: | 332 if self._socket is not None: |
334 self._socket.close() | 333 self._socket.close() |
335 self._socket = None | 334 self._socket = None |
336 | 335 |
337 def Send(self, method, **kwargs): | 336 def Send(self, method, **kwargs): |
338 logging.info( | 337 logging.info( |
339 '%s: %s(%s)', self._url, method, | 338 '%s: %s(%s)', self._url, method, |
340 ', '.join('%s=%r' % (k, v) for k, v in sorted(kwargs.iteritems()))) | 339 ', '.join('%s=%r' % (k, v) for k, v in sorted(kwargs.iteritems()))) |
(...skipping 303 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
644 status = '[ OK ]' | 643 status = '[ OK ]' |
645 start = time.time() | 644 start = time.time() |
646 try: | 645 try: |
647 story_cls(browser).Run(trace_file) | 646 story_cls(browser).Run(trace_file) |
648 except Exception: # pylint: disable=broad-except | 647 except Exception: # pylint: disable=broad-except |
649 logging.exception('Exception raised while running story') | 648 logging.exception('Exception raised while running story') |
650 status = '[ FAILED ]' | 649 status = '[ FAILED ]' |
651 finally: | 650 finally: |
652 elapsed = '(%.1f secs)' % (time.time() - start) | 651 elapsed = '(%.1f secs)' % (time.time() - start) |
653 print status, story_cls.NAME, elapsed | 652 print status, story_cls.NAME, elapsed |
OLD | NEW |