@@ -494,6 +494,22 @@ def calculate_object_stats(stats):
494494 rows .append ((label , value , ratio ))
495495 return rows
496496
497+ def calculate_gc_stats (stats ):
498+ gc_stats = []
499+ for key , value in stats .items ():
500+ if not key .startswith ("GC" ):
501+ continue
502+ n , _ , rest = key [3 :].partition ("]" )
503+ name = rest .strip ()
504+ gen_n = int (n )
505+ while len (gc_stats ) <= gen_n :
506+ gc_stats .append ({})
507+ gc_stats [gen_n ][name ] = value
508+ return [
509+ (i , gen ["collections" ], gen ["objects collected" ], gen ["object visits" ])
510+ for (i , gen ) in enumerate (gc_stats )
511+ ]
512+
497513def emit_object_stats (stats ):
498514 with Section ("Object stats" , summary = "allocations, frees and dict materializatons" ):
499515 rows = calculate_object_stats (stats )
@@ -505,6 +521,22 @@ def emit_comparative_object_stats(base_stats, head_stats):
505521 head_rows = calculate_object_stats (head_stats )
506522 emit_table (("" , "Base Count:" , "Base Ratio:" , "Head Count:" , "Head Ratio:" ), join_rows (base_rows , head_rows ))
507523
524+ def emit_gc_stats (stats ):
525+ with Section ("GC stats" , summary = "GC collections and effectiveness" ):
526+ rows = calculate_gc_stats (stats )
527+ emit_table (("Generation:" , "Collections:" , "Objects collected:" , "Object visits:" ), rows )
528+
529+ def emit_comparative_gc_stats (base_stats , head_stats ):
530+ with Section ("GC stats" , summary = "GC collections and effectiveness" ):
531+ base_rows = calculate_gc_stats (base_stats )
532+ head_rows = calculate_gc_stats (head_stats )
533+ emit_table (
534+ ("Generation:" ,
535+ "Base collections:" , "Head collections:" ,
536+ "Base objects collected:" , "Head objects collected:" ,
537+ "Base object visits:" , "Head object visits:" ),
538+ join_rows (base_rows , head_rows ))
539+
508540def get_total (opcode_stats ):
509541 total = 0
510542 for opcode_stat in opcode_stats :
@@ -574,6 +606,7 @@ def output_single_stats(stats):
574606 emit_specialization_overview (opcode_stats , total )
575607 emit_call_stats (stats )
576608 emit_object_stats (stats )
609+ emit_gc_stats (stats )
577610 with Section ("Meta stats" , summary = "Meta statistics" ):
578611 emit_table (("" , "Count:" ), [('Number of data files' , stats ['__nfiles__' ])])
579612
@@ -596,6 +629,7 @@ def output_comparative_stats(base_stats, head_stats):
596629 )
597630 emit_comparative_call_stats (base_stats , head_stats )
598631 emit_comparative_object_stats (base_stats , head_stats )
632+ emit_comparative_gc_stats (base_stats , head_stats )
599633
600634def output_stats (inputs , json_output = None ):
601635 if len (inputs ) == 1 :
0 commit comments