Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(autoware_dubug_tools): add function to report worst time when r is pressed at the end #86

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import curses
import json
import time
from typing import Dict
import uuid
Expand All @@ -20,6 +21,7 @@ class ProcessingTimeVisualizer(Node):
def __init__(self):
super().__init__("processing_time_visualizer" + str(uuid.uuid4()).replace("-", "_"))
self.subscriber = self.subscribe_processing_time_tree()
self.quit_option = None
self.trees: Dict[str, ProcessingTimeTree] = {}
self.worst_case_tree: Dict[str, ProcessingTimeTree] = {}
self.stdcscr = init_curses()
Expand Down Expand Up @@ -73,6 +75,10 @@ def update_screen(self):
if key == ord("y"):
pyperclip.copy(logs)
if key == ord("q"):
self.quit_option = "q"
raise KeyboardInterrupt
if key == ord("r"):
self.quit_option = "r"
raise KeyboardInterrupt

def callback(self, msg: ProcessingTimeTreeMsg):
Expand Down Expand Up @@ -100,6 +106,8 @@ def main(args=None):
except (KeyboardInterrupt, rclpy.executors.ExternalShutdownException):
node.destroy_node()
exit_curses()
if node.quit_option == "r":
pyperclip.copy(json.dumps([v.__dict__() for v in node.worst_case_tree.values()]))
if len(node.worst_case_tree) == 0:
exit(1)
print("⏰ Worst Case Execution Time ⏰")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,13 @@ def print_trees(
tree_lines = wrap_lines(tree_lines, width, height - 2)
for i, line in enumerate(tree_lines):
stdscr.addstr(i + 2, 1, line)
stdscr.addstr(height - 1, 0, "'q' => quit. 'c' => show comment. 'y' => copy."[: width - 2])
stdscr.addstr(
height - 1,
0,
"'q' => quit. 'r' => quit & output json report to clipboard. 'c' => show comment. 'y' => copy."[
: width - 2
],
)
stdscr.refresh()

return "".join([line + "\n" for line in tree_lines])
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,14 @@ def construct_string(
construct_string(self, lines, "", True, True)
return lines

def __dict__(self) -> dict:
return {
"name": self.name,
"processing_time": self.processing_time,
"comment": self.comment,
"children": [child.__dict__() for child in self.children],
}

def __str__(self) -> str:
return "".join([line + "\n" for line in self.to_lines()])

Expand Down
Loading