Skip to content

Commit

Permalink
Add typing
Browse files Browse the repository at this point in the history
  • Loading branch information
JosseVanDelm committed Jan 24, 2025
1 parent d8056e2 commit 87a8183
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions util/tracing/merge_json.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@

def merge_json(file_list: Sequence[str], output_file: str):
prefix = ""
traces = defaultdict(lambda: defaultdict(list))
traces: defaultdict[
int, defaultdict[int, list[dict[str, int | float | str | None]]]
] = defaultdict(lambda: defaultdict(list))
for filename in file_list:
match = re.match(r"(.*)_trace_chip_(\d{2})_hart_(\d{5})_perf\.json", filename)
if match:
Expand All @@ -29,7 +31,7 @@ def merge_json(file_list: Sequence[str], output_file: str):
# Convert the defaultdict to a nested list structure
result = [
[chip_harts[hart_id] for hart_id in sorted(chip_harts)]
for chip_id, chip_harts in sorted(traces.items())
for _, chip_harts in sorted(traces.items())
]

# Use prefix for output file if not explicitly provided
Expand All @@ -48,18 +50,17 @@ def merge_json(file_list: Sequence[str], output_file: str):
"files",
metavar="FILE",
nargs="+",
help=(
"List of JSON files to merge.",
"Filenames must match the format",
"'<prefix>_trace_chip_<chip_id>_hart_<hart_id>_perf.json'.",
),
help="List of JSON files to merge."
"Filenames must match the format"
"'<prefix>_trace_chip_<chip_id>_hart_<hart_id>_perf.json'.",
)
parser.add_argument(
"-o",
"--output",
metavar="OUTPUT_FILE",
default=None,
help="Name of the output JSON file. Defaults to '<prefix>_aggregated.json' based on input filenames.",
help="Name of the output JSON file."
"Defaults to '<prefix>_aggregated.json' based on input filenames.",
)

args = parser.parse_args()
Expand Down

0 comments on commit 87a8183

Please sign in to comment.