Skip to content
class method

GC.stat_heap

(?::Integer? heap_name, ?::Hash[::Symbol, untyped]? hash) -> ::Hash[::Symbol, untyped]
(::Integer heap_name, ::Symbol key) -> ::Integer
GC.stat_heap → new_hash
GC.stat_heap(heap_id) → new_hash
GC.stat_heap(heap_id, key) → value
GC.stat_heap(nil, hash) → hash
GC.stat_heap(heap_id, hash) → hash

This method is implementation-specific to CRuby.

Returns statistics for GC heaps. The particular statistics are implementation-specific and may change in the future without notice.

With no argument given, returns statistics for all heaps:

Example
GC.stat_heap
# =>
{0 =>
  {slot_size: 40,
   heap_eden_pages: 246,
   heap_eden_slots: 402802,
   total_allocated_pages: 246,
   force_major_gc_count: 2,
   force_incremental_marking_finish_count: 1,
   total_allocated_objects: 33867152,
   total_freed_objects: 33520523},
 1 =>
  {slot_size: 80,
   heap_eden_pages: 84,
   heap_eden_slots: 68746,
   total_allocated_pages: 84,
   force_major_gc_count: 1,
   force_incremental_marking_finish_count: 4,
   total_allocated_objects: 147491,
   total_freed_objects: 90699},
 2 =>
  {slot_size: 160,
   heap_eden_pages: 157,
   heap_eden_slots: 64182,
   total_allocated_pages: 157,
   force_major_gc_count: 0,
   force_incremental_marking_finish_count: 0,
   total_allocated_objects: 211460,
   total_freed_objects: 190075},
 3 =>
  {slot_size: 320,
   heap_eden_pages: 8,
   heap_eden_slots: 1631,
   total_allocated_pages: 8,
   force_major_gc_count: 0,
   force_incremental_marking_finish_count: 0,
   total_allocated_objects: 1422,
   total_freed_objects: 700},
 4 =>
  {slot_size: 640,
   heap_eden_pages: 16,
   heap_eden_slots: 1628,
   total_allocated_pages: 16,
   force_major_gc_count: 0,
   force_incremental_marking_finish_count: 0,
   total_allocated_objects: 1230,
   total_freed_objects: 309}}

In the example above, the keys in the outer hash are the heap identifiers:

Example
GC.stat_heap.keys # => [0, 1, 2, 3, 4]

On CRuby, each heap identifier is an integer; on other implementations, a heap identifier may be a string.

With only argument heap_id given, returns statistics for the given heap identifier:

Example
GC.stat_heap(2)
# =>
{slot_size: 160,
 heap_eden_pages: 157,
 heap_eden_slots: 64182,
 total_allocated_pages: 157,
 force_major_gc_count: 0,
 force_incremental_marking_finish_count: 0,
 total_allocated_objects: 225018,
 total_freed_objects: 206647}

With arguments heap_id and key given, returns the value for the given key in the given heap:

Example
GC.stat_heap(2, :slot_size) # => 160

With arguments nil and hash given, merges the statistics for all heaps into the given hash:

Example
h = {foo: 0, bar: 1}
GC.stat_heap(nil, h).keys # => [:foo, :bar, 0, 1, 2, 3, 4]

With arguments heap_id and hash given, merges the statistics for the given heap into the given hash:

Example
h = {foo: 0, bar: 1}
GC.stat_heap(2, h).keys
# =>
[:foo,
 :bar,
 :slot_size,
 :heap_eden_pages,
 :heap_eden_slots,
 :total_allocated_pages,
 :force_major_gc_count,
 :force_incremental_marking_finish_count,
 :total_allocated_objects,
 :total_freed_objects]

The statistics for a heap may include:

  • :slot_size: The slot size of the heap in bytes.

  • :heap_allocatable_pages: The number of pages that can be allocated without triggering a new garbage collection cycle.

  • :heap_eden_pages: The number of pages in the eden heap.

  • :heap_eden_slots: The total number of slots in all of the pages in the eden heap.

  • :total_allocated_pages: The total number of pages that have been allocated in the heap.

  • :total_freed_pages: The total number of pages that have been freed and released back to the system in the heap.

  • :force_major_gc_count: The number of times this heap has forced major garbage collection cycles 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.

See also .stat .stress .start .stress= also in 4.1 · 3.4 · 3.3 · 3.2