From 58b9e6a168acf723fd5e6fb96ef5630922ac02d7 Mon Sep 17 00:00:00 2001 From: fallwith Date: Tue, 12 Apr 2022 15:19:10 -0700 Subject: [PATCH 1/3] Support Ruby 3.2+ cache invalidation stats Ruby 3.2 uses a new `RubyVM` stat to track more fine grained constant cache invalidation data. Sum the fine grained values together to produce a Ruby 3.1 compatible value for now and leave a TODO for possibly reporting the individual constant key/value pairs later. --- lib/new_relic/agent/vm/mri_vm.rb | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/lib/new_relic/agent/vm/mri_vm.rb b/lib/new_relic/agent/vm/mri_vm.rb index ddb071e8b9..9c936f51df 100644 --- a/lib/new_relic/agent/vm/mri_vm.rb +++ b/lib/new_relic/agent/vm/mri_vm.rb @@ -49,7 +49,19 @@ def gather_ruby_vm_stats(snap) end if supports?(:constant_cache_invalidations) - snap.constant_cache_invalidations = RubyVM.stat[:global_constant_state] + snap.constant_cache_invalidations = gather_constant_cache_invalidatiions + end + end + + def gather_constant_cache_invalidatiions + # Ruby >= 3.2 uses :constant_cache + # see: https://github.com/ruby/ruby/pull/5433 and https://bugs.ruby-lang.org/issues/18589 + # TODO: now that 3.2+ provides more granual cache invalidation data, should we report it instead of summing? + if RUBY_VERSION >= '3.2.0' + RubyVM.stat[:constant_cache].values.sum + # Ruby < 3.2 uses :global_constant_state + else + RubyVM.stat[:global_constant_state] end end From 9abd4b120e63d8cfa3849a07b5b95644a6eea3c4 Mon Sep 17 00:00:00 2001 From: James Bunch Date: Fri, 15 Apr 2022 16:06:41 -0700 Subject: [PATCH 2/3] Update lib/new_relic/agent/vm/mri_vm.rb Typo fix Co-authored-by: Kayla Reopelle (she/her) <87386821+kaylareopelle@users.noreply.github.com> --- lib/new_relic/agent/vm/mri_vm.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/new_relic/agent/vm/mri_vm.rb b/lib/new_relic/agent/vm/mri_vm.rb index 9c936f51df..8ed8e93ad8 100644 --- a/lib/new_relic/agent/vm/mri_vm.rb +++ b/lib/new_relic/agent/vm/mri_vm.rb @@ -49,7 +49,7 @@ def gather_ruby_vm_stats(snap) end if supports?(:constant_cache_invalidations) - snap.constant_cache_invalidations = gather_constant_cache_invalidatiions + snap.constant_cache_invalidations = gather_constant_cache_invalidations end end From 887319b270380227bc57d861176b20385f19179a Mon Sep 17 00:00:00 2001 From: James Bunch Date: Fri, 15 Apr 2022 16:06:54 -0700 Subject: [PATCH 3/3] Update lib/new_relic/agent/vm/mri_vm.rb Typo fix Co-authored-by: Kayla Reopelle (she/her) <87386821+kaylareopelle@users.noreply.github.com> --- lib/new_relic/agent/vm/mri_vm.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/new_relic/agent/vm/mri_vm.rb b/lib/new_relic/agent/vm/mri_vm.rb index 8ed8e93ad8..5f128db86c 100644 --- a/lib/new_relic/agent/vm/mri_vm.rb +++ b/lib/new_relic/agent/vm/mri_vm.rb @@ -53,7 +53,7 @@ def gather_ruby_vm_stats(snap) end end - def gather_constant_cache_invalidatiions + def gather_constant_cache_invalidations # Ruby >= 3.2 uses :constant_cache # see: https://github.com/ruby/ruby/pull/5433 and https://bugs.ruby-lang.org/issues/18589 # TODO: now that 3.2+ provides more granual cache invalidation data, should we report it instead of summing?