diff --git a/debug_counter.h b/debug_counter.h index 3c5d693fe6..b29d5ef560 100644 --- a/debug_counter.h +++ b/debug_counter.h @@ -101,6 +101,25 @@ RB_DEBUG_COUNTER(lvar_set) RB_DEBUG_COUNTER(lvar_set_dynamic) RB_DEBUG_COUNTER(lvar_set_slowpath) +/* GC counts: + * + * * count: simple count + * * _minor: minor gc + * * _major: major gc + * * other suffix is corresponding to last_gc_info or + * gc_profile_record_flag in gc.c. + */ +RB_DEBUG_COUNTER(gc_count) +RB_DEBUG_COUNTER(gc_minor_newobj) +RB_DEBUG_COUNTER(gc_minor_malloc) +RB_DEBUG_COUNTER(gc_minor_method) +RB_DEBUG_COUNTER(gc_minor_capi) +RB_DEBUG_COUNTER(gc_minor_stress) +RB_DEBUG_COUNTER(gc_major_nofree) +RB_DEBUG_COUNTER(gc_major_oldgen) +RB_DEBUG_COUNTER(gc_major_shady) +RB_DEBUG_COUNTER(gc_major_force) + /* object allocation counts: * * * obj_newobj: newobj counts diff --git a/gc.c b/gc.c index f6f5617dd8..d5588bc19c 100644 --- a/gc.c +++ b/gc.c @@ -6536,6 +6536,23 @@ gc_start(rb_objspace_t *objspace, int reason) reason, do_full_mark, !is_incremental_marking(objspace), objspace->flags.immediate_sweep); +#if USE_DEBUG_COUNTER + RB_DEBUG_COUNTER_INC(gc_count); + if (reason & GPR_FLAG_MAJOR_MASK) { + (void)RB_DEBUG_COUNTER_INC_IF(gc_major_nofree, reason & GPR_FLAG_MAJOR_BY_NOFREE); + (void)RB_DEBUG_COUNTER_INC_IF(gc_major_oldgen, reason & GPR_FLAG_MAJOR_BY_OLDGEN); + (void)RB_DEBUG_COUNTER_INC_IF(gc_major_shady, reason & GPR_FLAG_MAJOR_BY_SHADY); + (void)RB_DEBUG_COUNTER_INC_IF(gc_major_force, reason & GPR_FLAG_MAJOR_BY_FORCE); + } + else { + (void)RB_DEBUG_COUNTER_INC_IF(gc_minor_newobj, reason & GPR_FLAG_NEWOBJ); + (void)RB_DEBUG_COUNTER_INC_IF(gc_minor_malloc, reason & GPR_FLAG_MALLOC); + (void)RB_DEBUG_COUNTER_INC_IF(gc_minor_method, reason & GPR_FLAG_METHOD); + (void)RB_DEBUG_COUNTER_INC_IF(gc_minor_capi, reason & GPR_FLAG_CAPI); + (void)RB_DEBUG_COUNTER_INC_IF(gc_minor_stress, reason & GPR_FLAG_NEWOBJ); + } +#endif + objspace->profile.count++; objspace->profile.latest_gc_info = reason; objspace->profile.total_allocated_objects_at_gc_start = objspace->total_allocated_objects;