From 0a94d175b0f337f5a21e7d5ee5747695a31dd1e8 Mon Sep 17 00:00:00 2001 From: Adeeb Shihadeh Date: Sun, 14 May 2023 11:24:48 -0700 Subject: [PATCH] count_events.py: show alerts old-commit-hash: ec53fad3c4f9bac5605e635a653d842402ccbf5d --- selfdrive/debug/count_events.py | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/selfdrive/debug/count_events.py b/selfdrive/debug/count_events.py index 93dd5bdc47..42b671e5e3 100755 --- a/selfdrive/debug/count_events.py +++ b/selfdrive/debug/count_events.py @@ -5,7 +5,7 @@ import datetime from collections import Counter from pprint import pprint from tqdm import tqdm -from typing import cast +from typing import List, Tuple, cast from cereal.services import service_list from tools.lib.route import Route @@ -20,6 +20,7 @@ if __name__ == "__main__": cams = [s for s in service_list if s.endswith('CameraState')] cnt_cameras = dict.fromkeys(cams, 0) + alerts: List[Tuple[float, str]] = [] start_time = math.inf end_time = -math.inf for q in tqdm(r.qlog_paths()): @@ -27,18 +28,22 @@ if __name__ == "__main__": continue lr = list(LogReader(q)) for msg in lr: + end_time = max(end_time, msg.logMonoTime) + start_time = min(start_time, msg.logMonoTime) + if msg.which() == 'carEvents': for e in msg.carEvents: cnt_events[e.name] += 1 + elif msg.which() == 'controlsState': + if len(alerts) == 0 or alerts[-1][1] != msg.controlsState.alertType: + t = (msg.logMonoTime - start_time) / 1e9 + alerts.append((t, msg.controlsState.alertType)) elif msg.which() in cams: cnt_cameras[msg.which()] += 1 if not msg.valid: cnt_valid[msg.which()] += 1 - end_time = max(end_time, msg.logMonoTime) - start_time = min(start_time, msg.logMonoTime) - duration = (end_time - start_time) / 1e9 print("Events") @@ -55,5 +60,10 @@ if __name__ == "__main__": expected_frames = int(s.frequency * duration / cast(float, s.decimation)) print(" ", k.ljust(20), f"{v}, {v/expected_frames:.1%} of expected") + print("\n") + print("Alerts") + for t, a in alerts: + print(f"{t:8.2f} {a}") + print("\n") print("Route duration", datetime.timedelta(seconds=duration))