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.
This commit is contained in:
Peter Zhu 2023-08-14 11:24:50 -04:00
parent 8c5b9ebf71
commit 0f94e65359
3 changed files with 9 additions and 0 deletions

5
gc.c
View File

@ -707,6 +707,7 @@ typedef struct rb_size_pool_struct {
size_t total_allocated_pages; size_t total_allocated_pages;
size_t total_freed_pages; size_t total_freed_pages;
size_t force_major_gc_count; size_t force_major_gc_count;
size_t force_incremental_marking_finish_count;
/* Sweeping statistics */ /* Sweeping statistics */
size_t freed_slots; 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 { else {
gc_report(2, objspace, "gc_marks_continue: no more pooled pages (stack depth: %"PRIdSIZE").\n", gc_report(2, objspace, "gc_marks_continue: no more pooled pages (stack depth: %"PRIdSIZE").\n",
mark_stack_size(&objspace->mark_stack)); mark_stack_size(&objspace->mark_stack));
size_pool->force_incremental_marking_finish_count++;
gc_marks_rest(objspace); 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_allocated_pages,
gc_stat_heap_sym_total_freed_pages, gc_stat_heap_sym_total_freed_pages,
gc_stat_heap_sym_force_major_gc_count, gc_stat_heap_sym_force_major_gc_count,
gc_stat_heap_sym_force_incremental_marking_finish_count,
gc_stat_heap_sym_last gc_stat_heap_sym_last
}; };
@ -11201,6 +11204,7 @@ setup_gc_stat_heap_symbols(void)
S(total_allocated_pages); S(total_allocated_pages);
S(total_freed_pages); S(total_freed_pages);
S(force_major_gc_count); S(force_major_gc_count);
S(force_incremental_marking_finish_count);
#undef S #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_allocated_pages, size_pool->total_allocated_pages);
SET(total_freed_pages, size_pool->total_freed_pages); SET(total_freed_pages, size_pool->total_freed_pages);
SET(force_major_gc_count, size_pool->force_major_gc_count); 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 #undef SET
if (!NIL_P(key)) { /* matched key should return above */ if (!NIL_P(key)) { /* matched key should return above */

3
gc.rb
View File

@ -244,6 +244,9 @@ module GC
# [force_major_gc_count] # [force_major_gc_count]
# The number of times major garbage collection cycles this heap has forced # The number of times major garbage collection cycles this heap has forced
# to start due to running out of free slots. # 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 def self.stat_heap heap_name = nil, hash_or_key = nil
Primitive.gc_stat_heap heap_name, hash_or_key Primitive.gc_stat_heap heap_name, hash_or_key

View File

@ -163,6 +163,7 @@ class TestGc < Test::Unit::TestCase
assert_operator stat_heap[:total_allocated_pages], :>=, 0 assert_operator stat_heap[:total_allocated_pages], :>=, 0
assert_operator stat_heap[:total_freed_pages], :>=, 0 assert_operator stat_heap[:total_freed_pages], :>=, 0
assert_operator stat_heap[:force_major_gc_count], :>=, 0 assert_operator stat_heap[:force_major_gc_count], :>=, 0
assert_operator stat_heap[:force_incremental_marking_finish_count], :>=, 0
end end
GC.stat_heap(0, stat_heap) GC.stat_heap(0, stat_heap)