From fecaac8edaa954a2ef9d93bde8c836f36617e859 Mon Sep 17 00:00:00 2001 From: Lukas Petersson Date: Thu, 7 Apr 2022 13:18:26 -0700 Subject: [PATCH] latencylogger graph design (#24165) * latencylogger graph design * Update tools/latencylogger/latency_logger.py Co-authored-by: Adeeb Shihadeh * quotes Co-authored-by: Adeeb Shihadeh --- tools/latencylogger/README.md | 9 +++++---- tools/latencylogger/latency_logger.py | 29 ++++++++++++++++----------- 2 files changed, 22 insertions(+), 16 deletions(-) diff --git a/tools/latencylogger/README.md b/tools/latencylogger/README.md index 3e4b8bffef..20de8212a1 100644 --- a/tools/latencylogger/README.md +++ b/tools/latencylogger/README.md @@ -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. diff --git a/tools/latencylogger/latency_logger.py b/tools/latencylogger/latency_logger.py index d4d1950756..e1c89ffbda 100644 --- a/tools/latencylogger/latency_logger.py +++ b/tools/latencylogger/latency_logger.py @@ -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",