104 lines
2.6 KiB
Python
104 lines
2.6 KiB
Python
"""Display-performance session: stream PERF lines from Main CTRL to a log
|
|
while you provoke symptoms on the touchscreen (wiki open question #13).
|
|
|
|
Opens the port WITHOUT resetting the board (DTR/RTS low), turns on `perf on 1`,
|
|
then logs everything to wiki/raw/perf-<timestamp>.log until Ctrl+C. PERF lines
|
|
are echoed to the terminal. Anything you type is sent to the console, except
|
|
lines starting with '#', which are written into the log as markers - use them
|
|
to timestamp what you did on the screen:
|
|
|
|
# opened wifi page, scan running - dots visible
|
|
# tuning save
|
|
# ota install started
|
|
|
|
Usage: python tools/perf_session.py COM14 [period_seconds]
|
|
"""
|
|
import os
|
|
import sys
|
|
import threading
|
|
import time
|
|
from datetime import datetime
|
|
|
|
import serial
|
|
|
|
port = sys.argv[1] if len(sys.argv) > 1 else "COM14"
|
|
period = sys.argv[2] if len(sys.argv) > 2 else "1"
|
|
|
|
out_dir = os.path.join("wiki", "raw")
|
|
os.makedirs(out_dir, exist_ok=True)
|
|
path = os.path.join(out_dir, f"perf-{datetime.now():%Y%m%d-%H%M%S}.log")
|
|
|
|
s = serial.Serial()
|
|
s.port = port
|
|
s.baudrate = 115200
|
|
s.timeout = 0.2
|
|
s.dtr = False
|
|
s.rts = False
|
|
s.open()
|
|
|
|
stop = threading.Event()
|
|
lock = threading.Lock()
|
|
log = open(path, "w", encoding="utf-8", newline="\n")
|
|
|
|
|
|
def stamp():
|
|
return datetime.now().strftime("%H:%M:%S.%f")[:-3]
|
|
|
|
|
|
def write_log(line):
|
|
with lock:
|
|
log.write(f"{stamp()} {line}\n")
|
|
log.flush()
|
|
|
|
|
|
def reader():
|
|
while not stop.is_set():
|
|
raw = s.readline()
|
|
if not raw:
|
|
continue
|
|
line = raw.decode("utf-8", "replace").rstrip("\r\n")
|
|
write_log(line)
|
|
if line.startswith("PERF,") or "[perf]" in line or "[ota]" in line or "[wifi]" in line:
|
|
print(line)
|
|
|
|
|
|
def send(cmd):
|
|
write_log(f">>> {cmd}")
|
|
s.write((cmd + "\n").encode())
|
|
s.flush()
|
|
|
|
|
|
t = threading.Thread(target=reader, daemon=True)
|
|
t.start()
|
|
time.sleep(0.5)
|
|
send(f"perf on {period}")
|
|
print(f"logging to {path} (type console commands, '# note' for a marker, Ctrl+C to stop)")
|
|
print("columns: ts,fps,avg_ms,max_ms,kpx/frame,flush_ms/s,lvgl_idle%,idle0%,idle1%,int_free,int_largest,psram_free")
|
|
|
|
try:
|
|
while True:
|
|
line = sys.stdin.readline()
|
|
if not line:
|
|
time.sleep(0.2)
|
|
continue
|
|
line = line.rstrip("\r\n")
|
|
if not line:
|
|
continue
|
|
if line.startswith("#"):
|
|
write_log(f"### {line[1:].strip()}")
|
|
print(f"marker: {line[1:].strip()}")
|
|
else:
|
|
send(line)
|
|
except KeyboardInterrupt:
|
|
pass
|
|
finally:
|
|
try:
|
|
send("perf off")
|
|
time.sleep(0.3)
|
|
except Exception:
|
|
pass
|
|
stop.set()
|
|
s.close()
|
|
log.close()
|
|
print(f"\nsaved {path}")
|