new logging

This commit is contained in:
awe
2026-04-09 19:47:30 +03:00
parent bc48b9d432
commit 08823404c0
2 changed files with 48 additions and 0 deletions

View File

@ -38,6 +38,7 @@ from rfg_adc_plotter.state import RingBuffer, RuntimeState
from rfg_adc_plotter.types import SweepAuxCurves, SweepInfo, SweepPacket from rfg_adc_plotter.types import SweepAuxCurves, SweepInfo, SweepPacket
RAW_PLOT_MAX_POINTS = 4096 RAW_PLOT_MAX_POINTS = 4096
DEBUG_FRAME_LOG_EVERY = 10
def _visible_levels_pyqtgraph(data: np.ndarray, plot_item) -> Optional[Tuple[float, float]]: def _visible_levels_pyqtgraph(data: np.ndarray, plot_item) -> Optional[Tuple[float, float]]:
@ -1240,6 +1241,8 @@ def run_pyqtgraph(args) -> None:
except Exception: except Exception:
pass pass
processed_frames = 0
def refresh_current_fft_cache(sweep_for_fft: np.ndarray, bins: int) -> None: def refresh_current_fft_cache(sweep_for_fft: np.ndarray, bins: int) -> None:
runtime.current_fft_complex = compute_fft_complex_row( runtime.current_fft_complex = compute_fft_complex_row(
sweep_for_fft, sweep_for_fft,
@ -1251,6 +1254,7 @@ def run_pyqtgraph(args) -> None:
runtime.current_fft_db = fft_mag_to_db(runtime.current_fft_mag) runtime.current_fft_db = fft_mag_to_db(runtime.current_fft_mag)
def drain_queue() -> int: def drain_queue() -> int:
nonlocal processed_frames
drained = 0 drained = 0
while True: while True:
try: try:
@ -1301,6 +1305,22 @@ def run_pyqtgraph(args) -> None:
runtime.full_current_aux_curves = None runtime.full_current_aux_curves = None
runtime.current_info = info runtime.current_info = info
refresh_current_window(push_to_ring=True) refresh_current_window(push_to_ring=True)
processed_frames += 1
if processed_frames % DEBUG_FRAME_LOG_EVERY == 0:
try:
queue_size = queue.qsize()
except Exception:
queue_size = -1
sys.stderr.write(
"[debug] ui frames:%d last_sweep:%s ch:%s width:%d queue:%d\n"
% (
processed_frames,
str(info.get("sweep") if isinstance(info, dict) else None),
str(info.get("ch") if isinstance(info, dict) else None),
int(getattr(sweep, "size", 0)),
int(queue_size),
)
)
if drained > 0: if drained > 0:
update_physical_axes() update_physical_axes()
return drained return drained

View File

@ -22,6 +22,7 @@ from rfg_adc_plotter.types import ParserEvent, PointEvent, SweepPacket
_PARSER_16_BIT_X2_PROBE_BYTES = 64 * 1024 _PARSER_16_BIT_X2_PROBE_BYTES = 64 * 1024
_LEGACY_STREAM_MIN_RECORDS = 32 _LEGACY_STREAM_MIN_RECORDS = 32
_LEGACY_STREAM_MIN_MATCH_RATIO = 0.95 _LEGACY_STREAM_MIN_MATCH_RATIO = 0.95
_DEBUG_FRAME_LOG_EVERY = 10
def _u16le_at(data: bytes, offset: int) -> int: def _u16le_at(data: bytes, offset: int) -> int:
@ -98,6 +99,8 @@ class SweepReader(threading.Thread):
self._parser_test = bool(parser_test) self._parser_test = bool(parser_test)
self._parser_complex_ascii = bool(parser_complex_ascii) self._parser_complex_ascii = bool(parser_complex_ascii)
self._src: SerialLineSource | None = None self._src: SerialLineSource | None = None
self._frames_read = 0
self._frames_dropped = 0
def _build_parser(self): def _build_parser(self):
if self._parser_complex_ascii: if self._parser_complex_ascii:
@ -149,17 +152,42 @@ class SweepReader(threading.Thread):
return parser, assembler, [] return parser, assembler, []
def _enqueue(self, packet: SweepPacket) -> None: def _enqueue(self, packet: SweepPacket) -> None:
dropped = False
try: try:
self._queue.put_nowait(packet) self._queue.put_nowait(packet)
except Full: except Full:
try: try:
_ = self._queue.get_nowait() _ = self._queue.get_nowait()
dropped = True
except Exception: except Exception:
pass pass
try: try:
self._queue.put_nowait(packet) self._queue.put_nowait(packet)
except Exception: except Exception:
pass pass
if dropped:
self._frames_dropped += 1
self._frames_read += 1
if self._frames_read % _DEBUG_FRAME_LOG_EVERY == 0:
sweep, info, _aux = packet
try:
queue_size = self._queue.qsize()
except Exception:
queue_size = -1
sweep_idx = info.get("sweep") if isinstance(info, dict) else None
channel = info.get("ch") if isinstance(info, dict) else None
sys.stderr.write(
"[debug] reader frames:%d last_sweep:%s ch:%s width:%d queue:%d dropped:%d\n"
% (
self._frames_read,
str(sweep_idx),
str(channel),
int(getattr(sweep, "size", 0)),
int(queue_size),
self._frames_dropped,
)
)
def run(self) -> None: def run(self) -> None:
try: try: