mirror of
https://github.com/trezor/trezor-firmware.git
synced 2025-01-08 22:40:59 +00:00
last_sleep info replaced by ring buffer and delay_avg
This commit is contained in:
parent
8bc3b9e160
commit
c66dfee6b9
@ -10,7 +10,14 @@ if __debug__:
|
|||||||
|
|
||||||
q = []
|
q = []
|
||||||
cnt = 0
|
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):
|
def call_soon(callback, *args):
|
||||||
call_at(0, callback, *args)
|
call_at(0, callback, *args)
|
||||||
@ -29,15 +36,18 @@ def call_at(time, callback, *args):
|
|||||||
cnt += 1
|
cnt += 1
|
||||||
|
|
||||||
def wait(delay):
|
def wait(delay):
|
||||||
global last_sleep
|
|
||||||
|
|
||||||
if __debug__:
|
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)
|
m = msg.select(delay)
|
||||||
if m:
|
if m:
|
||||||
print('msg:', m)
|
print('msg:', m)
|
||||||
|
utime.sleep_us(10000)
|
||||||
return m
|
return m
|
||||||
|
|
||||||
def run_forever():
|
def run_forever():
|
||||||
|
@ -10,18 +10,30 @@ if __debug__:
|
|||||||
import logging
|
import logging
|
||||||
logging.basicConfig(level=logging.INFO)
|
logging.basicConfig(level=logging.INFO)
|
||||||
|
|
||||||
def perf_info():
|
def perf_info_debug():
|
||||||
while True:
|
while True:
|
||||||
queue = [str(x[2]).split("'")[1] for x in loop.q]
|
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()
|
mem_alloc = gc.mem_alloc()
|
||||||
gc.collect()
|
gc.collect()
|
||||||
print("mem_alloc: %s/%s, last_sleep: %d, queue: %s" % \
|
print("mem_alloc: %s/%s, delay_avg: %d, delay_last: %d, queue: %s" % \
|
||||||
(mem_alloc, gc.mem_alloc(), loop.last_sleep, ', '.join(queue)))
|
(mem_alloc, gc.mem_alloc(), delay_avg, delay_last, ', '.join(queue)))
|
||||||
|
|
||||||
yield loop.Sleep(1000000)
|
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):
|
def run(main_layout):
|
||||||
if __debug__:
|
if __debug__:
|
||||||
|
loop.call_soon(perf_info_debug())
|
||||||
|
else:
|
||||||
loop.call_soon(perf_info())
|
loop.call_soon(perf_info())
|
||||||
|
|
||||||
loop.call_soon(layout.set_main(main_layout))
|
loop.call_soon(layout.set_main(main_layout))
|
||||||
|
Loading…
Reference in New Issue
Block a user