MCPcopy Index your code
hub / github.com/python/cpython / _print_summary

Method _print_summary

Lib/profiling/sampling/pstats_collector.py:267–422  ·  view source on GitHub ↗

Print summary of interesting functions.

(self, stats_list, total_samples)

Source from the content-addressed store, hash-verified

265 return "μs", float(MICROSECONDS_PER_SECOND)
266
267 def _print_summary(self, stats_list, total_samples):
268 """Print summary of interesting functions."""
269 print(
270 f"\n{ANSIColors.BOLD_BLUE}Summary of Interesting Functions:{ANSIColors.RESET}"
271 )
272
273 # Aggregate stats by fully qualified function name (ignoring line numbers)
274 func_aggregated = {}
275 for (
276 func,
277 direct_calls,
278 cumulative_calls,
279 total_time,
280 cumulative_time,
281 callers,
282 ) in stats_list:
283 # Use filename:function_name as the key to get fully qualified name
284 qualified_name = f"{func[0]}:{func[2]}"
285 if qualified_name not in func_aggregated:
286 func_aggregated[qualified_name] = [
287 0,
288 0,
289 0,
290 0,
291 ] # direct_calls, cumulative_calls, total_time, cumulative_time
292 func_aggregated[qualified_name][0] += direct_calls
293 func_aggregated[qualified_name][1] += cumulative_calls
294 func_aggregated[qualified_name][2] += total_time
295 func_aggregated[qualified_name][3] += cumulative_time
296
297 # Convert aggregated data back to list format for processing
298 aggregated_stats = []
299 for qualified_name, (
300 prim_calls,
301 total_calls,
302 total_time,
303 cumulative_time,
304 ) in func_aggregated.items():
305 # Parse the qualified name back to filename and function name
306 if ":" in qualified_name:
307 filename, func_name = qualified_name.rsplit(":", 1)
308 else:
309 filename, func_name = "", qualified_name
310 # Create a dummy func tuple with filename and function name for display
311 dummy_func = (filename, "", func_name)
312 aggregated_stats.append(
313 (
314 dummy_func,
315 prim_calls,
316 total_calls,
317 total_time,
318 cumulative_time,
319 {},
320 )
321 )
322
323 # Determine best units for summary metrics
324 max_total_time = max(

Callers 1

print_statsMethod · 0.95

Calls 4

_determine_best_unitMethod · 0.95
itemsMethod · 0.45
rsplitMethod · 0.45
appendMethod · 0.45

Tested by

no test coverage detected