last_sleep info replaced by ring buffer and delay_avg

This commit is contained in:
slush0 2016-04-29 16:34:29 +02:00 committed by Pavol Rusnak
parent 8bc3b9e160
commit c66dfee6b9
No known key found for this signature in database
GPG Key ID: 91F3B339B9A02A3D
2 changed files with 30 additions and 8 deletions

View File

@ -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():

View File

@ -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))