From 0f94e653597dc2ae21ae39ac4c85266f3bb36ab6 Mon Sep 17 00:00:00 2001 From: Peter Zhu Date: Mon, 14 Aug 2023 11:24:50 -0400 Subject: Add stat force_incremental_marking_finish_count This commit adds key force_incremental_marking_finish_count to GC.stat_heap. This statistic returns the number of times the size pool has forced incremental marking to finish due to running out of slots. --- gc.c | 5 +++++ gc.rb | 3 +++ test/ruby/test_gc.rb | 1 + 3 files changed, 9 insertions(+) diff --git a/gc.c b/gc.c index d2c5c52692..0d650dbe68 100644 --- a/gc.c +++ b/gc.c @@ -707,6 +707,7 @@ typedef struct rb_size_pool_struct { size_t total_allocated_pages; size_t total_freed_pages; size_t force_major_gc_count; + size_t force_incremental_marking_finish_count; /* Sweeping statistics */ size_t freed_slots; @@ -8504,6 +8505,7 @@ gc_marks_continue(rb_objspace_t *objspace, rb_size_pool_t *size_pool, rb_heap_t else { gc_report(2, objspace, "gc_marks_continue: no more pooled pages (stack depth: %"PRIdSIZE").\n", mark_stack_size(&objspace->mark_stack)); + size_pool->force_incremental_marking_finish_count++; gc_marks_rest(objspace); } @@ -11182,6 +11184,7 @@ enum gc_stat_heap_sym { gc_stat_heap_sym_total_allocated_pages, gc_stat_heap_sym_total_freed_pages, gc_stat_heap_sym_force_major_gc_count, + gc_stat_heap_sym_force_incremental_marking_finish_count, gc_stat_heap_sym_last }; @@ -11201,6 +11204,7 @@ setup_gc_stat_heap_symbols(void) S(total_allocated_pages); S(total_freed_pages); S(force_major_gc_count); + S(force_incremental_marking_finish_count); #undef S } } @@ -11244,6 +11248,7 @@ gc_stat_heap_internal(int size_pool_idx, VALUE hash_or_sym) SET(total_allocated_pages, size_pool->total_allocated_pages); SET(total_freed_pages, size_pool->total_freed_pages); SET(force_major_gc_count, size_pool->force_major_gc_count); + SET(force_incremental_marking_finish_count, size_pool->force_incremental_marking_finish_count); #undef SET if (!NIL_P(key)) { /* matched key should return above */ diff --git a/gc.rb b/gc.rb index 4803a844ee..c3b104454c 100644 --- a/gc.rb +++ b/gc.rb @@ -244,6 +244,9 @@ module GC # [force_major_gc_count] # The number of times major garbage collection cycles this heap has forced # to start due to running out of free slots. + # [force_incremental_marking_finish_count] + # The number of times this heap has forced incremental marking to complete + # due to running out of pooled slots. # def self.stat_heap heap_name = nil, hash_or_key = nil Primitive.gc_stat_heap heap_name, hash_or_key diff --git a/test/ruby/test_gc.rb b/test/ruby/test_gc.rb index 0cf57cb088..aabdfc0cf8 100644 --- a/test/ruby/test_gc.rb +++ b/test/ruby/test_gc.rb @@ -163,6 +163,7 @@ class TestGc < Test::Unit::TestCase assert_operator stat_heap[:total_allocated_pages], :>=, 0 assert_operator stat_heap[:total_freed_pages], :>=, 0 assert_operator stat_heap[:force_major_gc_count], :>=, 0 + assert_operator stat_heap[:force_incremental_marking_finish_count], :>=, 0 end GC.stat_heap(0, stat_heap) -- cgit v1.2.3