carrot/selfdrive/debug/internal/measure_modeld_packet_drop.py
FrogAi 659adb6457 openpilot v0.9.7 release
date: 2024-03-17T10:14:38
master commit: 7e9a909e0e57ecb31df4c87c5b9a06b1204fd034
2024-05-24 17:43:27 -07:00

34 lines
764 B
Python

#!/usr/bin/env python3
import cereal.messaging as messaging
if __name__ == "__main__":
modeld_sock = messaging.sub_sock("modelV2")
last_frame_id = None
start_t: int | None = None
frame_cnt = 0
dropped = 0
while True:
m = messaging.recv_one(modeld_sock)
if m is None:
continue
frame_id = m.modelV2.frameId
t = m.logMonoTime / 1e9
frame_cnt += 1
if start_t is None:
start_t = t
last_frame_id = frame_id
continue
d_frame = frame_id - last_frame_id
dropped += d_frame - 1
expected_num_frames = int((t - start_t) * 20)
frame_drop = 100 * (1 - (expected_num_frames / frame_cnt))
print(f"Num dropped {dropped}, Drop compared to 20Hz: {frame_drop:.2f}%")
last_frame_id = frame_id