mirror of
https://github.com/lowobservable/oec.git
synced 2026-01-11 23:53:04 +00:00
very very hacky timing logs
This commit is contained in:
parent
f863ec1261
commit
12c94019eb
@ -17,6 +17,35 @@ from .device import address_commands, format_address, UnsupportedDeviceError
|
|||||||
from .keyboard import Key
|
from .keyboard import Key
|
||||||
from .session import SessionDisconnectedError
|
from .session import SessionDisconnectedError
|
||||||
|
|
||||||
|
class Timer:
|
||||||
|
def __init__(self, measurements):
|
||||||
|
self.measurements = measurements
|
||||||
|
|
||||||
|
def __enter__(self):
|
||||||
|
self.start_time = time.perf_counter()
|
||||||
|
|
||||||
|
def __exit__(self, type, value, traceback):
|
||||||
|
duration = time.perf_counter() - self.start_time
|
||||||
|
|
||||||
|
self.measurements.append(duration)
|
||||||
|
|
||||||
|
PERF_LOGS = open('timing.csv', 'w')
|
||||||
|
PERF_LOGS.write('update_sessions,delay,poll_attached,poll_detatched\n')
|
||||||
|
|
||||||
|
def dump_stats(a, b, c, d):
|
||||||
|
if len(a) < 100:
|
||||||
|
return
|
||||||
|
|
||||||
|
for (l, m, n, o) in zip(a, b, c, d):
|
||||||
|
PERF_LOGS.write(f'{l},{m},{n},{o}\n')
|
||||||
|
|
||||||
|
PERF_LOGS.flush()
|
||||||
|
|
||||||
|
a.clear()
|
||||||
|
b.clear()
|
||||||
|
c.clear()
|
||||||
|
d.clear()
|
||||||
|
|
||||||
class SessionState(Enum):
|
class SessionState(Enum):
|
||||||
"""Session state."""
|
"""Session state."""
|
||||||
|
|
||||||
@ -58,6 +87,11 @@ class Controller:
|
|||||||
self.last_attached_poll_time = None
|
self.last_attached_poll_time = None
|
||||||
self.last_detatched_poll_time = None
|
self.last_detatched_poll_time = None
|
||||||
|
|
||||||
|
self.a = []
|
||||||
|
self.b = []
|
||||||
|
self.c = []
|
||||||
|
self.d = []
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
"""Run the controller."""
|
"""Run the controller."""
|
||||||
self.running = True
|
self.running = True
|
||||||
@ -98,17 +132,26 @@ class Controller:
|
|||||||
# If POLLing is delayed, handle the host output, otherwise just sleep.
|
# If POLLing is delayed, handle the host output, otherwise just sleep.
|
||||||
start_time = time.perf_counter()
|
start_time = time.perf_counter()
|
||||||
|
|
||||||
if poll_delay > 0:
|
with Timer(self.a):
|
||||||
self._update_sessions(poll_delay)
|
if poll_delay > 0:
|
||||||
|
self._update_sessions(poll_delay)
|
||||||
|
|
||||||
poll_delay -= (time.perf_counter() - start_time)
|
poll_delay -= (time.perf_counter() - start_time)
|
||||||
|
|
||||||
if poll_delay > 0:
|
if poll_delay > 0:
|
||||||
|
self.b.append(poll_delay)
|
||||||
time.sleep(poll_delay)
|
time.sleep(poll_delay)
|
||||||
|
else:
|
||||||
|
self.b.append(0)
|
||||||
|
|
||||||
# POLL devices.
|
# POLL devices.
|
||||||
self._poll_attached_devices()
|
with Timer(self.c):
|
||||||
self._poll_next_detatched_device()
|
self._poll_attached_devices()
|
||||||
|
|
||||||
|
with Timer(self.d):
|
||||||
|
self._poll_next_detatched_device()
|
||||||
|
|
||||||
|
dump_stats(self.a, self.b, self.c, self.d)
|
||||||
|
|
||||||
def _update_sessions(self, duration):
|
def _update_sessions(self, duration):
|
||||||
start_time = time.perf_counter()
|
start_time = time.perf_counter()
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user