mirror of
https://github.com/mruby/mruby
synced 2026-06-08 16:11:16 +00:00
gc.c: add optional GC statistics counters
Add gc_total_count, minor_gc_count, major_gc_count (uint32_t) to mrb_gc, guarded by MRB_GC_STATS. Zero cost when disabled. Co-authored-by: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -64,6 +64,12 @@ typedef struct mrb_gc {
|
||||
int arena_capa; /* size of protection array */
|
||||
#endif
|
||||
int arena_idx;
|
||||
|
||||
#ifdef MRB_GC_STATS
|
||||
uint32_t gc_total_count; /* total GC invocations */
|
||||
uint32_t minor_gc_count; /* minor GC count */
|
||||
uint32_t major_gc_count; /* major GC count */
|
||||
#endif
|
||||
} mrb_gc;
|
||||
|
||||
MRB_API mrb_bool mrb_object_dead_p(mrb_state *mrb, struct RBasic *object);
|
||||
|
||||
@@ -1322,9 +1322,19 @@ mrb_incremental_gc(mrb_state *mrb)
|
||||
if (gc->disabled || gc->iterating) return;
|
||||
|
||||
if (is_minor_gc(gc)) {
|
||||
#ifdef MRB_GC_STATS
|
||||
gc->gc_total_count++;
|
||||
gc->minor_gc_count++;
|
||||
#endif
|
||||
incremental_gc_finish(mrb, gc);
|
||||
}
|
||||
else {
|
||||
#ifdef MRB_GC_STATS
|
||||
if (gc->state == MRB_GC_STATE_ROOT) {
|
||||
gc->gc_total_count++;
|
||||
gc->major_gc_count++;
|
||||
}
|
||||
#endif
|
||||
incremental_gc_step(mrb, gc);
|
||||
}
|
||||
|
||||
@@ -1364,6 +1374,10 @@ mrb_full_gc(mrb_state *mrb)
|
||||
if (!mrb->c) return;
|
||||
if (gc->disabled || gc->iterating) return;
|
||||
|
||||
#ifdef MRB_GC_STATS
|
||||
gc->gc_total_count++;
|
||||
gc->major_gc_count++;
|
||||
#endif
|
||||
if (is_generational(gc)) {
|
||||
/* clear all the old objects back to young */
|
||||
clear_all_old(mrb, gc);
|
||||
|
||||
Reference in New Issue
Block a user