@ -1,13 +1,14 @@
import argparse
import argparse
import json
import json
import matplotlib . patches as mpatches
import matplotlib . pyplot as plt
import mpld3
import mpld3
import sys
import sys
from collections import defaultdict
from collections import defaultdict
import matplotlib . pyplot as plt
from tools . lib . logreader import logreader_from_route_or_segment
from tools . lib . logreader import logreader_from_route_or_segment
DEMO_ROUTE = " 9f583b1d93915c31|2022-04-01--17-51-29 "
DEMO_ROUTE = " 9f583b1d93915c31|2022-04-06--11-34-03 "
SERVICES = [ ' camerad ' , ' modeld ' , ' plannerd ' , ' controlsd ' , ' boardd ' ]
SERVICES = [ ' camerad ' , ' modeld ' , ' plannerd ' , ' controlsd ' , ' boardd ' ]
# Retrive controlsd frameId from lateralPlan, mismatch with longitudinalPlan will be ignored
# Retrive controlsd frameId from lateralPlan, mismatch with longitudinalPlan will be ignored
@ -144,6 +145,10 @@ def graph_timestamps(timestamps, relative):
fig , ax = plt . subplots ( )
fig , ax = plt . subplots ( )
ax . set_xlim ( 0 , 150 if relative else 750 )
ax . set_xlim ( 0 , 150 if relative else 750 )
ax . set_ylim ( 0 , 15 )
ax . set_ylim ( 0 , 15 )
ax . set_xlabel ( ' milliseconds ' )
ax . set_ylabel ( ' Frame ID ' )
colors = [ ' blue ' , ' green ' , ' red ' , ' yellow ' , ' purple ' ]
assert len ( colors ) == len ( SERVICES ) , ' Each service needs a color '
points = { " x " : [ ] , " y " : [ ] , " labels " : [ ] }
points = { " x " : [ ] , " y " : [ ] , " labels " : [ ] }
for frame_id , services in timestamps . items ( ) :
for frame_id , services in timestamps . items ( ) :
@ -154,17 +159,17 @@ def graph_timestamps(timestamps, relative):
start , end = get_interval ( frame_id , service , timestamps )
start , end = get_interval ( frame_id , service , timestamps )
service_bars . append ( ( ( start - t0 ) / 1e6 , ( end - start ) / 1e6 ) )
service_bars . append ( ( ( start - t0 ) / 1e6 , ( end - start ) / 1e6 ) )
for event in events :
for event in events :
points [ " x " ] . append ( ( event [ 1 ] - t0 ) / 1e6 )
points [ ' x ' ] . append ( ( event [ 1 ] - t0 ) / 1e6 )
points [ " y " ] . append ( frame_id + 0.45 )
points [ ' y ' ] . append ( frame_id )
points [ " labels " ] . append ( event [ 0 ] )
points [ ' labels ' ] . append ( event [ 0 ] )
ax . broken_barh ( service_bars , ( frame_id , 0.9 ) , facecolors = ( [ " blue " , ' green ' , ' red ' , ' yellow ' , ' purple ' ] ) )
ax . broken_barh ( service_bars , ( frame_id - 0.45 , 0.9 ) , facecolors = ( colors ) , alpha = 0.5 )
scatter = ax . scatter ( points [ ' x ' ] , points [ ' y ' ] , marker = " d " , edgecolor = ' black ' )
scatter = ax . scatter ( points [ ' x ' ] , points [ ' y ' ] , marker = ' d ' , edgecolor = ' black ' )
tooltip = mpld3 . plugins . PointLabelTooltip ( scatter , labels = points [ " labels " ] )
tooltip = mpld3 . plugins . PointLabelTooltip ( scatter , labels = points [ ' labels ' ] )
ax . legend ( )
mpld3 . plugins . connect ( fig , tooltip )
mpld3 . plugins . connect ( fig , tooltip )
#mpld3.save_html(fig, 'test.html')
plt . legend ( handles = [ mpatches . Patch ( color = colors [ i ] , label = SERVICES [ i ] ) for i in range ( len ( SERVICES ) ) ] )
mpld3 . show ( )
#mpld3.save_html(fig, 'latencylogger_plot.html')
mpld3 . show ( fig )
if __name__ == " __main__ " :
if __name__ == " __main__ " :
parser = argparse . ArgumentParser ( description = " A tool for analyzing openpilot ' s end-to-end latency " ,
parser = argparse . ArgumentParser ( description = " A tool for analyzing openpilot ' s end-to-end latency " ,