qlog_size: decimate rlog option (#33011)

* decimate option

* clean up

* check exists
old-commit-hash: f31ad97e924af579ec60961bc7cc3c170525fcef
This commit is contained in:
Shane Smiskol
2024-07-17 21:57:36 -07:00
committed by GitHub
parent 75c33e7a1c
commit 85b77e0387

View File

@@ -5,6 +5,7 @@ from collections import defaultdict
import matplotlib.pyplot as plt
from cereal.services import SERVICE_LIST
from openpilot.tools.lib.logreader import LogReader
from tqdm import tqdm
@@ -48,9 +49,29 @@ def make_pie(msgs, typ):
if __name__ == "__main__":
parser = argparse.ArgumentParser(description='View log size breakdown by message type')
parser.add_argument('route', help='route to use')
parser.add_argument('--as-qlog', action='store_true', help='decimate rlog using latest decimation factors')
args = parser.parse_args()
msgs = list(LogReader(args.route))
if args.as_qlog:
new_msgs = []
msg_cnts: dict[str, int] = defaultdict(int)
for msg in msgs:
msg_which = msg.which()
if msg.which() in ("initData", "sentinel"):
new_msgs.append(msg)
continue
if msg_which not in SERVICE_LIST:
continue
decimation = SERVICE_LIST[msg_which].decimation
if decimation is not None and msg_cnts[msg_which] % decimation == 0:
new_msgs.append(msg)
msg_cnts[msg_which] += 1
msgs = new_msgs
make_pie(msgs, 'qlog')
plt.show()