Skip to content

Commit

Permalink
add hatchet literal support for timers (#105)
Browse files Browse the repository at this point in the history
  • Loading branch information
S-Mahua authored Nov 3, 2024
1 parent b7f7886 commit 4dae813
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions axonn/timers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 4dae813

Please sign in to comment.