2121import sys
2222from collections import defaultdict
2323from datetime import datetime
24- from pathlib import Path
2524
2625try :
2726 from jinja2 import Environment , FileSystemLoader
@@ -38,7 +37,9 @@ def parse_arguments():
3837 print (
3938 "Usage: analyze_build_trace.py <trace_files_or_dir> <output_file> <target> <granularity> <build_time> <template_dir>"
4039 )
41- print (" trace_files_or_dir: Comma-separated list of trace files OR directory containing .json files" )
40+ print (
41+ " trace_files_or_dir: Comma-separated list of trace files OR directory containing .json files"
42+ )
4243 sys .exit (1 )
4344
4445 return {
@@ -61,12 +62,12 @@ def find_trace_files(trace_input):
6162 for root , dirs , files in os .walk (trace_input ):
6263 for file in files :
6364 # Include .cpp.json and .hip.json, exclude compile_commands.json and CMake files
64- if file .endswith ((' .cpp.json' , ' .hip.json' )) and ' CMakeFiles' in root :
65+ if file .endswith ((" .cpp.json" , " .hip.json" )) and " CMakeFiles" in root :
6566 trace_files .append (os .path .join (root , file ))
6667 trace_files .sort ()
6768 # Check if it's a comma-separated list
68- elif ',' in trace_input :
69- trace_files = [f .strip () for f in trace_input .split (',' )]
69+ elif "," in trace_input :
70+ trace_files = [f .strip () for f in trace_input .split ("," )]
7071 # Single file
7172 else :
7273 trace_files = [trace_input ]
@@ -93,11 +94,7 @@ def load_trace_data(trace_files):
9394 data = json .load (f )
9495 # Get file basename for tracking
9596 file_name = os .path .basename (trace_file )
96- all_data .append ({
97- 'file' : file_name ,
98- 'path' : trace_file ,
99- 'data' : data
100- })
97+ all_data .append ({"file" : file_name , "path" : trace_file , "data" : data })
10198 except Exception as e :
10299 print (f" Warning: Failed to load { trace_file } : { e } " , file = sys .stderr )
103100
@@ -115,8 +112,8 @@ def process_events(all_trace_data):
115112 total_events = 0
116113
117114 for trace_info in all_trace_data :
118- file_name = trace_info [' file' ]
119- data = trace_info [' data' ]
115+ file_name = trace_info [" file" ]
116+ data = trace_info [" data" ]
120117 events = data .get ("traceEvents" , [])
121118
122119 file_template_time = 0
@@ -134,12 +131,9 @@ def process_events(all_trace_data):
134131
135132 if name in ["InstantiateFunction" , "InstantiateClass" ]:
136133 detail = event .get ("args" , {}).get ("detail" , "" )
137- top_individual .append ({
138- "detail" : detail ,
139- "dur" : dur ,
140- "type" : name ,
141- "file" : file_name
142- })
134+ top_individual .append (
135+ {"detail" : detail , "dur" : dur , "type" : name , "file" : file_name }
136+ )
143137
144138 file_template_time += dur
145139
@@ -154,11 +148,13 @@ def process_events(all_trace_data):
154148 template_stats [template_name ]["count" ] += 1
155149 template_stats [template_name ]["total_dur" ] += dur
156150
157- file_stats .append ({
158- 'name' : file_name ,
159- 'events' : file_event_count ,
160- 'template_time' : file_template_time
161- })
151+ file_stats .append (
152+ {
153+ "name" : file_name ,
154+ "events" : file_event_count ,
155+ "template_time" : file_template_time ,
156+ }
157+ )
162158
163159 return template_stats , phase_stats , top_individual , file_stats , total_events
164160
@@ -323,10 +319,14 @@ def main():
323319 all_trace_data = load_trace_data (trace_files )
324320
325321 # Process events from all files
326- template_stats , phase_stats , top_individual , file_stats , total_events = process_events (all_trace_data )
322+ template_stats , phase_stats , top_individual , file_stats , total_events = (
323+ process_events (all_trace_data )
324+ )
327325
328326 # Prepare template data
329- data = prepare_template_data (template_stats , phase_stats , top_individual , file_stats )
327+ data = prepare_template_data (
328+ template_stats , phase_stats , top_individual , file_stats
329+ )
330330
331331 # Setup Jinja2 environment
332332 env = setup_jinja_environment (args ["template_dir" ])
0 commit comments