Skip to content

Commit

Permalink
feat(autoware_dubug_tools): add function to report worst time when r …
Browse files Browse the repository at this point in the history
…is pressed at the end (#86)

Signed-off-by: Y.Hisaki <[email protected]>
  • Loading branch information
yhisaki authored Jul 29, 2024
1 parent d2ac93d commit bb0c993
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 1 deletion.
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()

Check warning on line 27 in common/autoware_debug_tools/autoware_debug_tools/processing_time_visualizer/node.py

View workflow job for this annotation

GitHub Actions / spell-check-all

Unknown word (stdcscr)
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

0 comments on commit bb0c993

Please sign in to comment.