diff --git a/axonn/timers.py b/axonn/timers.py index 5339b4e..c581564 100644 --- a/axonn/timers.py +++ b/axonn/timers.py @@ -44,3 +44,33 @@ def get_times(self): total_events[key] = self.curr_index[key] self.curr_index[key] = 0 return total_times, total_events + + def create_hatchet_literal_cct(self): + def insert_node(key, time, root): + if len(key) == 1: + root[key] = { + "frame": {"name": key[0]}, + "metrics": {"time (inc)": time}, + "children": [], + } + return root[key[0]] + else: + top_node = key[0] + child = insert_node( + key[1:], + time, + { + child["frame"]["name"]: child + for child in root[top_node]["children"] + }, + ) + if child not in root[top_node]["children"]: + root[top_node]["children"].append(child) + return root[top_node] + + sorted_timers = dict(sorted(self.timers.items(), key=lambda item: len(item[0]))) + root = {} + for key, time in sorted_timers.items(): + insert_node(key, time, root) + hatchet_format = list(root.values()) + return hatchet_format