Skip to content

Commit

Permalink
added hatchet literal support for timers
Browse files Browse the repository at this point in the history
  • Loading branch information
Mahua Singh committed Nov 3, 2024
1 parent b7f7886 commit 72b3819
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions axonn/timers.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,27 @@ 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(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 72b3819

Please sign in to comment.