Skip to content

Commit

Permalink
Write mappings to a json file that will be picked up by the profiler …
Browse files Browse the repository at this point in the history
…script
  • Loading branch information
ayakayorihiro committed Jan 10, 2025
1 parent f8fa402 commit 629f4bd
Showing 1 changed file with 22 additions and 4 deletions.
26 changes: 22 additions & 4 deletions tools/profiler/poc-lift-flame-graph.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# a super simple script to show ADL level profiling proof of concept/experimentation
import json
import sys

class Component:
Expand Down Expand Up @@ -30,6 +31,16 @@ def __str__(self):
s += f"\t\t{group}: {self.groups[group]}\n"
return s

def gen_dict_for_json(self):
d = {"component" : self.name, "filename": self.position[0], "linenum": self.position[1], "cells": [], "groups": []}
for c in self.cells:
cell_dict = {"cell": c, "filename": self.cells[c][0], "linenum": self.cells[c][1]}
d["cells"].append(cell_dict)
for g in self.groups:
group_dict = {"group": g, "filename": self.groups[g][0], "linenum": self.groups[g][1]}
d["groups"].append(group_dict)
return d

def parse(calyx_file):
# a really hacky parser.
metadata = False
Expand Down Expand Up @@ -80,21 +91,28 @@ def parse(calyx_file):

return components, position_map

def main(calyx_file):
def main(calyx_file, out_file):
components, position_map = parse(calyx_file)
maps = []
for component_name in components:
component = components[component_name]
component.rewrite(position_map)
maps.append(component.gen_dict_for_json())
print(component)
print()

with open(out_file, "w", encoding="utf-8") as out:
out.write(json.dumps(maps, indent=4))

if __name__ == "__main__":
if len(sys.argv) > 1:
if len(sys.argv) > 2:
calyx_file = sys.argv[1]
main(calyx_file)
out_file = sys.argv[2]
main(calyx_file, out_file)
else:
args_desc = [
"CALYX_FILE"
"CALYX_FILE",
"OUT_JSON"
]
print(f"Usage: {sys.argv[0]} {' '.join(args_desc)}")
sys.exit(-1)

0 comments on commit 629f4bd

Please sign in to comment.