From c66dfee6b9f3a3d0514941240d9c87d3952c03d0 Mon Sep 17 00:00:00 2001 From: slush0 Date: Fri, 29 Apr 2016 16:34:29 +0200 Subject: [PATCH] last_sleep info replaced by ring buffer and delay_avg --- src/trezor/loop.py | 20 +++++++++++++++----- src/trezor/main.py | 18 +++++++++++++++--- 2 files changed, 30 insertions(+), 8 deletions(-) diff --git a/src/trezor/loop.py b/src/trezor/loop.py index 84286c4f43..ff779871ae 100644 --- a/src/trezor/loop.py +++ b/src/trezor/loop.py @@ -10,7 +10,14 @@ if __debug__: q = [] cnt = 0 -last_sleep = 0 # For performance stats + +# For performance stats +if __debug__: + # For performance stats + import array + log_delay_pos = 0 + log_delay_rb_len = const(10) + log_delay_rb = array.array('i', [0] * log_delay_rb_len) def call_soon(callback, *args): call_at(0, callback, *args) @@ -29,15 +36,18 @@ def call_at(time, callback, *args): cnt += 1 def wait(delay): - global last_sleep - if __debug__: - log.debug("Sleeping for: %s", delay) + # Adding delay to ring buffer for performance stats + global log_delay_pos + global log_delay_rb + global log_delay_rb_len + log_delay_rb[log_delay_pos] = delay + log_delay_pos = (log_delay_pos + 1) % log_delay_rb_len - last_sleep = delay m = msg.select(delay) if m: print('msg:', m) + utime.sleep_us(10000) return m def run_forever(): diff --git a/src/trezor/main.py b/src/trezor/main.py index 5cddbdce96..435e129e9b 100644 --- a/src/trezor/main.py +++ b/src/trezor/main.py @@ -10,18 +10,30 @@ if __debug__: import logging logging.basicConfig(level=logging.INFO) -def perf_info(): +def perf_info_debug(): while True: queue = [str(x[2]).split("'")[1] for x in loop.q] + + delay_avg = sum(loop.log_delay_rb) / loop.log_delay_rb_len + delay_last = loop.log_delay_rb[loop.log_delay_pos] + mem_alloc = gc.mem_alloc() gc.collect() - print("mem_alloc: %s/%s, last_sleep: %d, queue: %s" % \ - (mem_alloc, gc.mem_alloc(), loop.last_sleep, ', '.join(queue))) + print("mem_alloc: %s/%s, delay_avg: %d, delay_last: %d, queue: %s" % \ + (mem_alloc, gc.mem_alloc(), delay_avg, delay_last, ', '.join(queue))) yield loop.Sleep(1000000) +def perf_info(): + while True: + gc.collect() + print("mem_alloc: %d" % gc.mem_alloc()) + yield loop.Sleep(1000000) + def run(main_layout): if __debug__: + loop.call_soon(perf_info_debug()) + else: loop.call_soon(perf_info()) loop.call_soon(layout.set_main(main_layout))