Skip to content

Commit 7cadb74

Browse files
Show heap breakdown in gc benches
1 parent 7b961bb commit 7cadb74

1 file changed

Lines changed: 27 additions & 0 deletions

File tree

harness-gc/harness.rb

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,13 @@ def run_benchmark(_num_itrs_hint, **, &block)
128128
extra["gc_major_reasons_bench"] = aggregate_reasons[bench_range]
129129
end
130130

131+
# Snapshot heap utilisation after benchmark
132+
if GC.respond_to?(:stat_heap)
133+
GC.start(full_mark: true)
134+
heap_snapshot = GC.stat_heap
135+
extra["gc_heap_final"] = heap_snapshot.transform_values { |v| v.is_a?(Hash) ? v.dup : v }
136+
end
137+
131138
return_results(times[warmup_range], times[bench_range], **extra)
132139

133140
non_warmups = times[bench_range]
@@ -158,4 +165,24 @@ def run_benchmark(_num_itrs_hint, **, &block)
158165
end
159166
end
160167
end
168+
169+
# Print heap utilisation table
170+
if heap_snapshot
171+
puts "\nHeap utilisation (after full GC):"
172+
header = "heap slot_size eden_slots live_slots free_slots eden_pages live_pct"
173+
puts header
174+
175+
heap_snapshot.each do |idx, stats|
176+
slot_size = stats[:slot_size] || 0
177+
eden_slots = stats[:heap_eden_slots] || 0
178+
live_slots = stats[:heap_live_slots] || 0
179+
free_slots = stats[:heap_free_slots] || 0
180+
eden_pages = stats[:heap_eden_pages] || 0
181+
live_pct = eden_slots > 0 ? (live_slots * 100.0 / eden_slots) : 0.0
182+
183+
puts "%4d %9d %10d %10d %10d %11d %7.1f%%" % [
184+
idx, slot_size, eden_slots, live_slots, free_slots, eden_pages, live_pct
185+
]
186+
end
187+
end
161188
end

0 commit comments

Comments
 (0)