@@ -205,8 +205,8 @@ def aggregate_profiles(profile_dir: str) -> Dict[str, float]:
205205 return aggregated
206206
207207
208- def display_profile_data (aggregated_data : Dict [str , float ]) -> None :
209- """Display aggregated profile data in the same format as clang-tidy"""
208+ def print_profile_data (aggregated_data : Dict [str , float ]) -> None :
209+ """Print aggregated checks profile data in the same format as clang-tidy"""
210210 if not aggregated_data :
211211 return
212212
@@ -236,14 +236,17 @@ def display_profile_data(aggregated_data: Dict[str, float]) -> None:
236236 checkers .items (), key = lambda x : x [1 ]["user" ] + x [1 ]["sys" ], reverse = True
237237 )
238238
239- print (
239+ def print_stderr (* args , ** kwargs ) -> None :
240+ print (* args , file = sys .stderr , ** kwargs )
241+
242+ print_stderr (
240243 "===-------------------------------------------------------------------------==="
241244 )
242- print (" clang-tidy checks profiling" )
243- print (
245+ print_stderr (" clang-tidy checks profiling" )
246+ print_stderr (
244247 "===-------------------------------------------------------------------------==="
245248 )
246- print (
249+ print_stderr (
247250 f" Total Execution Time: { total_user + total_sys :.4f} seconds ({ total_wall :.4f} wall clock)\n "
248251 )
249252
@@ -261,7 +264,7 @@ def display_profile_data(aggregated_data: Dict[str, float]) -> None:
261264 combined_header = "--User+System--" .center (combined_width + additional_width )
262265 wall_header = "---Wall Time---" .center (wall_width + additional_width )
263266
264- print (
267+ print_stderr (
265268 f" { user_header } { sys_header } { combined_header } { wall_header } --- Name ---"
266269 )
267270
@@ -271,29 +274,28 @@ def display_profile_data(aggregated_data: Dict[str, float]) -> None:
271274 wall_time = data ["wall" ]
272275 combined_time = user_time + sys_time
273276
274- user_pct = (user_time / total_user * 100 ) if total_user > 0 else 0
275- sys_pct = (sys_time / total_sys * 100 ) if total_sys > 0 else 0
276- combined_pct = (
277+ user_percent = (user_time / total_user * 100 ) if total_user > 0 else 0
278+ sys_percent = (sys_time / total_sys * 100 ) if total_sys > 0 else 0
279+ combined_percent = (
277280 (combined_time / total_combined * 100 ) if total_combined > 0 else 0
278281 )
279- wall_pct = (wall_time / total_wall * 100 ) if total_wall > 0 else 0
282+ wall_percent = (wall_time / total_wall * 100 ) if total_wall > 0 else 0
280283
281- user_str = f"{ user_time :{user_width }.4f} ({ user_pct :5.1f} %)"
282- sys_str = f"{ sys_time :{sys_width }.4f} ({ sys_pct :5.1f} %)"
283- combined_str = f"{ combined_time :{combined_width }.4f} ({ combined_pct :5.1f} %)"
284- wall_str = f"{ wall_time :{wall_width }.4f} ({ wall_pct :5.1f} %)"
284+ user_str = f"{ user_time :{user_width }.4f} ({ user_percent :5.1f} %)"
285+ sys_str = f"{ sys_time :{sys_width }.4f} ({ sys_percent :5.1f} %)"
286+ combined_str = f"{ combined_time :{combined_width }.4f} ({ combined_percent :5.1f} %)"
287+ wall_str = f"{ wall_time :{wall_width }.4f} ({ wall_percent :5.1f} %)"
285288
286- print (
289+ print_stderr (
287290 f" { user_str } { sys_str } { combined_str } { wall_str } { checker_name } "
288291 )
289292
290- # Total line
291293 user_total_str = f"{ total_user :{user_width }.4f} (100.0%)"
292294 sys_total_str = f"{ total_sys :{sys_width }.4f} (100.0%)"
293295 combined_total_str = f"{ total_combined :{combined_width }.4f} (100.0%)"
294296 wall_total_str = f"{ total_wall :{wall_width }.4f} (100.0%)"
295297
296- print (
298+ print_stderr (
297299 f" { user_total_str } { sys_total_str } { combined_total_str } { wall_total_str } Total"
298300 )
299301
@@ -731,9 +733,11 @@ async def main() -> None:
731733 return
732734
733735 if args .enable_check_profile and profile_dir :
736+ # Ensure all clang-tidy stdout is flushed before printing profiling
737+ sys .stdout .flush ()
734738 aggregated_data = aggregate_profiles (profile_dir )
735739 if aggregated_data :
736- display_profile_data (aggregated_data )
740+ print_profile_data (aggregated_data )
737741 else :
738742 print ("No profiling data found." )
739743
0 commit comments