new logging
This commit is contained in:
@ -38,6 +38,7 @@ from rfg_adc_plotter.state import RingBuffer, RuntimeState
|
||||
from rfg_adc_plotter.types import SweepAuxCurves, SweepInfo, SweepPacket
|
||||
|
||||
RAW_PLOT_MAX_POINTS = 4096
|
||||
DEBUG_FRAME_LOG_EVERY = 10
|
||||
|
||||
|
||||
def _visible_levels_pyqtgraph(data: np.ndarray, plot_item) -> Optional[Tuple[float, float]]:
|
||||
@ -1240,6 +1241,8 @@ def run_pyqtgraph(args) -> None:
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
processed_frames = 0
|
||||
|
||||
def refresh_current_fft_cache(sweep_for_fft: np.ndarray, bins: int) -> None:
|
||||
runtime.current_fft_complex = compute_fft_complex_row(
|
||||
sweep_for_fft,
|
||||
@ -1251,6 +1254,7 @@ def run_pyqtgraph(args) -> None:
|
||||
runtime.current_fft_db = fft_mag_to_db(runtime.current_fft_mag)
|
||||
|
||||
def drain_queue() -> int:
|
||||
nonlocal processed_frames
|
||||
drained = 0
|
||||
while True:
|
||||
try:
|
||||
@ -1301,6 +1305,22 @@ def run_pyqtgraph(args) -> None:
|
||||
runtime.full_current_aux_curves = None
|
||||
runtime.current_info = info
|
||||
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:
|
||||
update_physical_axes()
|
||||
return drained
|
||||
|
||||
@ -22,6 +22,7 @@ from rfg_adc_plotter.types import ParserEvent, PointEvent, SweepPacket
|
||||
_PARSER_16_BIT_X2_PROBE_BYTES = 64 * 1024
|
||||
_LEGACY_STREAM_MIN_RECORDS = 32
|
||||
_LEGACY_STREAM_MIN_MATCH_RATIO = 0.95
|
||||
_DEBUG_FRAME_LOG_EVERY = 10
|
||||
|
||||
|
||||
def _u16le_at(data: bytes, offset: int) -> int:
|
||||
@ -98,6 +99,8 @@ class SweepReader(threading.Thread):
|
||||
self._parser_test = bool(parser_test)
|
||||
self._parser_complex_ascii = bool(parser_complex_ascii)
|
||||
self._src: SerialLineSource | None = None
|
||||
self._frames_read = 0
|
||||
self._frames_dropped = 0
|
||||
|
||||
def _build_parser(self):
|
||||
if self._parser_complex_ascii:
|
||||
@ -149,17 +152,42 @@ class SweepReader(threading.Thread):
|
||||
return parser, assembler, []
|
||||
|
||||
def _enqueue(self, packet: SweepPacket) -> None:
|
||||
dropped = False
|
||||
try:
|
||||
self._queue.put_nowait(packet)
|
||||
except Full:
|
||||
try:
|
||||
_ = self._queue.get_nowait()
|
||||
dropped = True
|
||||
except Exception:
|
||||
pass
|
||||
try:
|
||||
self._queue.put_nowait(packet)
|
||||
except Exception:
|
||||
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:
|
||||
try:
|
||||
|
||||
Reference in New Issue
Block a user