latencylogger graph design (#24165)

* latencylogger graph design

* Update tools/latencylogger/latency_logger.py

Co-authored-by: Adeeb Shihadeh <adeebshihadeh@gmail.com>

* quotes

Co-authored-by: Adeeb Shihadeh <adeebshihadeh@gmail.com>
pull/24082/head^2
Lukas Petersson 3 years ago committed by GitHub
parent 634f7cebef
commit fecaac8eda
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 9
      tools/latencylogger/README.md
  2. 29
      tools/latencylogger/latency_logger.py

@ -22,10 +22,11 @@ optional arguments:
```
## Examples
Plotting with relative starts each process at time=0 and gives a nice overview.
![relself](https://user-images.githubusercontent.com/42323981/161629832-c6f28874-4b0b-437a-961e-d80adbf8dd97.png)
Plotting without relative provides info about the frames relative time.
![relfirst](https://user-images.githubusercontent.com/42323981/161629886-3283e7c8-1bb0-4f3c-bede-4ceac1d2e140.png)
Plotting with relative starts each process at time=0 and gives a nice overview. Timestamps are visualized as diamonds. The opacity allows for visualization of overlapping services.
![relplot-1](https://user-images.githubusercontent.com/42323981/162108651-e0beee14-56e4-466d-8af1-cb37129fd94a.png)
Plotting without relative provides info about the frames relative time.
![plot-1](https://user-images.githubusercontent.com/42323981/162108694-fbfe907b-a1ee-4cc7-bc8b-162a7d9305d4.png)
Printed timestamps of a frame with internal durations.

@ -1,13 +1,14 @@
import argparse
import json
import matplotlib.patches as mpatches
import matplotlib.pyplot as plt
import mpld3
import sys
from collections import defaultdict
import matplotlib.pyplot as plt
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']
# Retrive controlsd frameId from lateralPlan, mismatch with longitudinalPlan will be ignored
@ -144,6 +145,10 @@ def graph_timestamps(timestamps, relative):
fig, ax = plt.subplots()
ax.set_xlim(0, 150 if relative else 750)
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": []}
for frame_id, services in timestamps.items():
@ -154,17 +159,17 @@ def graph_timestamps(timestamps, relative):
start, end = get_interval(frame_id, service,timestamps)
service_bars.append(((start-t0)/1e6,(end-start)/1e6))
for event in events:
points["x"].append((event[1]-t0)/1e6)
points["y"].append(frame_id+0.45)
points["labels"].append(event[0])
ax.broken_barh(service_bars, (frame_id, 0.9), facecolors=(["blue", 'green', 'red', 'yellow', 'purple']))
scatter = ax.scatter(points['x'], points['y'], marker="d", edgecolor='black')
tooltip = mpld3.plugins.PointLabelTooltip(scatter, labels=points["labels"])
ax.legend()
points['x'].append((event[1]-t0)/1e6)
points['y'].append(frame_id)
points['labels'].append(event[0])
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')
tooltip = mpld3.plugins.PointLabelTooltip(scatter, labels=points['labels'])
mpld3.plugins.connect(fig, tooltip)
#mpld3.save_html(fig, 'test.html')
mpld3.show()
plt.legend(handles=[mpatches.Patch(color=colors[i], label=SERVICES[i]) for i in range(len(SERVICES))])
#mpld3.save_html(fig, 'latencylogger_plot.html')
mpld3.show(fig)
if __name__ == "__main__":
parser = argparse.ArgumentParser(description="A tool for analyzing openpilot's end-to-end latency",

Loading…
Cancel
Save