nopenpilot/tools/latency_logging/read_cloudlog.py

50 lines
1.6 KiB
Python
Raw Normal View History

2022-03-21 15:50:11 -06:00
from selfdrive.swaglog import cloudlog
from tools.lib.route import Route
from tools.lib.logreader import LogReader
2022-03-21 18:04:28 -06:00
import json
2022-03-21 21:30:50 -06:00
from collections import defaultdict
2022-03-21 18:04:28 -06:00
2022-03-21 21:30:50 -06:00
2022-03-22 16:58:03 -06:00
timestamps = defaultdict(lambda: defaultdict(lambda: defaultdict(list)))
2022-03-23 14:19:43 -06:00
translationdict = {}
2022-03-21 21:30:50 -06:00
2022-03-25 12:56:31 -06:00
#r = Route("9f583b1d93915c31|2022-03-23--14-47-10") clean commit
#r = Route("9f583b1d93915c31|2022-03-24--19-31-10") current (no pub tlogs) update()
2022-03-25 14:06:43 -06:00
#r = Route("9f583b1d93915c31|2022-03-24--20-10-09") # current update(0)
2022-03-25 14:32:14 -06:00
r = Route("9f583b1d93915c31|2022-03-25--13-09-51") # rec and pub
2022-03-21 15:50:11 -06:00
lr = LogReader(r.log_paths()[0])
2022-03-23 10:12:18 -06:00
for msg in lr:
2022-03-23 14:19:43 -06:00
if msg.which() == "logMessage" and "translation" in msg.logMessage:
msg = msg.logMessage.replace("'", '"').replace('"{', "{").replace('}"', "}")
jmsg = json.loads(msg)
logMonoTime = jmsg['msg']['logMonoTime']
frame_id = jmsg['msg']['frameId']
translationdict[logMonoTime] = frame_id
2022-03-25 12:56:31 -06:00
i = 0
2022-03-21 15:50:11 -06:00
for msg in lr:
2022-03-23 14:19:43 -06:00
if msg.which() == "logMessage" and "timestamp" in msg.logMessage:
2022-03-21 21:30:50 -06:00
msg = msg.logMessage.replace("'", '"').replace('"{', "{").replace('}"', "}")
2022-03-23 14:19:43 -06:00
jmsg = json.loads(msg)
service = jmsg['ctx']['daemon']
event = jmsg['msg']['timestamp']['event']
time = jmsg['msg']['timestamp']['time']
frame_id = jmsg['msg']['timestamp']['frameId']
if jmsg['msg']['timestamp']['translate']:
2022-03-25 12:56:31 -06:00
try:
frame_id = translationdict[frame_id]
except:
i+=1
2022-03-23 14:19:43 -06:00
timestamps[frame_id][service][event].append(time)
2022-03-22 16:58:03 -06:00
2022-03-25 12:56:31 -06:00
print("Num failed translations:",i)
2022-03-22 16:58:03 -06:00
del timestamps[0]
2022-03-21 21:30:50 -06:00
with open('timestamps.json', 'w') as outfile:
2022-03-23 14:19:43 -06:00
json.dump(timestamps, outfile)