Skip to content

Commit

Permalink
feat(autoware_debug_tools): processing time total processing tree (#92)
Browse files Browse the repository at this point in the history
* feat: add total processing time tree to processing time visualizer

Signed-off-by: Taekjin LEE <[email protected]>

* feat: add percentage of processing time

Signed-off-by: Taekjin LEE <[email protected]>

* feat: add rest of the measured timekeepers

Signed-off-by: Taekjin LEE <[email protected]>

* style(pre-commit): autofix

* feat:  print average first and the worst case next

Signed-off-by: Taekjin LEE <[email protected]>

* style(pre-commit): autofix

* feat: refactor processing time tree sum method to summarize_tree

Signed-off-by: Taekjin LEE <[email protected]>

---------

Signed-off-by: Taekjin LEE <[email protected]>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
  • Loading branch information
technolojin and pre-commit-ci[bot] authored Aug 8, 2024
1 parent 8c281ae commit 1250986
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,10 @@ def __init__(self):
self.quit_option = None
self.trees: Dict[str, ProcessingTimeTree] = {}
self.worst_case_tree: Dict[str, ProcessingTimeTree] = {}
self.total_tree: Dict[str, ProcessingTimeTree] = {}
self.stdcscr = init_curses()

Check warning on line 28 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)

Check warning on line 28 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)

Check warning on line 28 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)

Check warning on line 28 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)

Check warning on line 28 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)

Check warning on line 28 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)

Check warning on line 28 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)
self.show_comment = False
self.summarize_output = False
self.summarize_output = True
print_trees("🌲 Processing Time Tree 🌲", self.topic_name, self.trees, self.stdcscr)

Check warning on line 31 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)

Check warning on line 31 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)

Check warning on line 31 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)

Check warning on line 31 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)

Check warning on line 31 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)

Check warning on line 31 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)

Check warning on line 31 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)

self.create_timer(0.1, self.update_screen)
Expand Down Expand Up @@ -89,6 +90,7 @@ def update_screen(self):
def callback(self, msg: ProcessingTimeTreeMsg):
tree = ProcessingTimeTree.from_msg(msg, self.summarize_output)
self.trees[tree.name] = tree
# worst case tree
if tree.name not in self.worst_case_tree:
self.worst_case_tree[tree.name] = tree
else:
Expand All @@ -97,6 +99,11 @@ def callback(self, msg: ProcessingTimeTreeMsg):
if tree.processing_time > self.worst_case_tree[tree.name].processing_time
else self.worst_case_tree[tree.name]
)
# total tree
if tree.name not in self.total_tree:
self.total_tree[tree.name] = tree
else:
self.total_tree[tree.name].summarize_tree(tree)


def main(args=None):
Expand All @@ -115,6 +122,14 @@ def main(args=None):
pyperclip.copy(json.dumps([v.__dict__() for v in node.worst_case_tree.values()]))
if len(node.worst_case_tree) == 0:
exit(1)

print("🌲 Total Processing Time Tree 🌲")
for tree in node.total_tree.values():
tree_str = "".join(
[line + "\n" for line in tree.to_lines(summarize=node.summarize_output)]
)
print(tree_str, end=None)

print("⏰ Worst Case Execution Time ⏰")
for tree in node.worst_case_tree.values():
tree_str = "".join(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,15 +107,29 @@ def construct_string(
prefix: str,
is_last: bool,
is_root: bool,
) -> None:
) -> float:
# If not the root, append the prefix and the node information
line = ""
has_children = len(node.children) > 0
is_last = is_last and not has_children
if not is_root:
line += prefix + ("└── " if is_last else "├── ")

# average processing time
average_processing_time = (
node.processing_time / node.run_count if node.run_count > 0 else 0
)
# percentage of processing time
percentage = (
f"{(node.processing_time / self.processing_time * 100):.2f}%"
if self.processing_time > 0
else "0.00%"
)
line += (
(
f"{node.name}: total {node.processing_time:.2f} [ms], "
f"avg. {node.processing_time / node.run_count:.2f} [ms], "
f"{percentage} {node.name}: "
f"total {node.processing_time:.2f} [ms], "
f"avg. {average_processing_time:.2f} [ms], "
f"run count: {node.run_count}"
)
if summarize
Expand All @@ -124,20 +138,53 @@ def construct_string(
line += f": {node.comment}" if show_comment and node.comment else ""
lines.append(line)
# Recur for each child node
children_processing_time = 0.0
for i, child in enumerate(node.children):
construct_string(
children_processing_time += construct_string(
child,
lines,
prefix + (" " if is_last else "│ "),
i == len(node.children) - 1,
prefix + (" " if (is_last or is_root) else "│ "),
False,
False,
)
# if it has children, add the rest of the processing time
if has_children:
rest_processing_time = node.processing_time - children_processing_time
rest_percentage = (
f"{(rest_processing_time / self.processing_time * 100):.2f}%"
if self.processing_time > 0
else "0.00%"
)
last_line = prefix
last_line += " └── " if is_root else "│ └── "
last_line += f"{rest_percentage} rest: " f"{rest_processing_time:.2f} [ms]"
lines.append(last_line)

return node.processing_time

lines = []
# Start the recursive string construction with the root node
construct_string(self, lines, "", True, True)

return lines

# sum up the processing tree time
# if the incoming tree has new nodes, add them to the current tree
# count the number of times the tree has been updated
def summarize_tree(self, other: "ProcessingTimeTree") -> None:
self.processing_time += other.processing_time
self.run_count += other.run_count

for other_child in other.children:
found = False
for child in self.children:
if child == other_child:
child.summarize_tree(other_child)
found = True
break
if not found:
self.children.append(other_child)

def __dict__(self) -> dict:
return {
"name": self.name,
Expand Down

0 comments on commit 1250986

Please sign in to comment.