Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplify CRuby GC.stat info fetching #2320

Merged
merged 1 commit into from
Nov 17, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 6 additions & 14 deletions lib/new_relic/agent/vm/mri_vm.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def gather_stats(snap)

def gather_gc_stats(snap)
gather_gc_runs(snap) if supports?(:gc_runs)
gather_derived_stats(snap) if GC.respond_to?(:stat)
gather_derived_stats(snap)
end

def gather_gc_runs(snap)
Expand All @@ -33,19 +33,11 @@ def gather_gc_runs(snap)

def gather_derived_stats(snap)
stat = GC.stat
snap.total_allocated_object = derive_from_gc_stats(%i[total_allocated_objects total_allocated_object], stat)
snap.major_gc_count = derive_from_gc_stats(:major_gc_count, stat)
snap.minor_gc_count = derive_from_gc_stats(:minor_gc_count, stat)
snap.heap_live = derive_from_gc_stats(%i[heap_live_slots heap_live_slot heap_live_num], stat)
snap.heap_free = derive_from_gc_stats(%i[heap_free_slots heap_free_slot heap_free_num], stat)
end

def derive_from_gc_stats(keys, stat)
Array(keys).each do |key|
value = stat[key]
return value if value
end
nil
snap.total_allocated_object = stat.fetch(:total_allocated_objects, nil)
snap.major_gc_count = stat.fetch(:major_gc_count, nil)
snap.minor_gc_count = stat.fetch(:minor_gc_count, nil)
snap.heap_live = stat.fetch(:heap_live_slots, nil)
snap.heap_free = stat.fetch(:heap_free_slots, nil)
end

def gather_gc_time(snap)
Expand Down
Loading