OLD | NEW |
(Empty) | |
| 1 # Copyright 2017 The Chromium Authors. All rights reserved. |
| 2 # Use of this source code is governed by a BSD-style license that can be |
| 3 # found in the LICENSE file. |
| 4 |
| 5 import logging |
| 6 import subprocess |
| 7 import threading |
| 8 |
| 9 class MotophoThread(threading.Thread): |
| 10 """Handles the running of the Motopho script and extracting results.""" |
| 11 def __init__(self): |
| 12 threading.Thread.__init__(self) |
| 13 self._latency = None |
| 14 self._max_correlation = None |
| 15 |
| 16 def run(self): |
| 17 motopho_output = "" |
| 18 try: |
| 19 motopho_output = subprocess.check_output(["./motophopro_nograph"], |
| 20 stderr=subprocess.STDOUT) |
| 21 except subprocess.CalledProcessError as e: |
| 22 logging.error('Failed to run Motopho script: %s', e.output) |
| 23 raise e |
| 24 |
| 25 if "FAIL" in motopho_output: |
| 26 logging.error('Failed to get latency, logging raw output: %s', |
| 27 motopho_output) |
| 28 raise RuntimeError('Failed to get latency - correlation likely too low') |
| 29 |
| 30 self._latency = None |
| 31 self._max_correlation = None |
| 32 for line in motopho_output.split("\n"): |
| 33 if 'Motion-to-photon latency:' in line: |
| 34 self._latency = float(line.split(" ")[-2]) |
| 35 if 'Max correlation is' in line: |
| 36 self._max_correlation = float(line.split(' ')[-1]) |
| 37 if self._latency and self._max_correlation: |
| 38 break; |
| 39 |
| 40 @property |
| 41 def latency(self): |
| 42 return self._latency |
| 43 |
| 44 @property |
| 45 def max_correlation(self): |
| 46 return self._max_correlation |
OLD | NEW |