From 7f518caa94fcd9f7693c311e5cba00626ce9c5d8 Mon Sep 17 00:00:00 2001 From: Ajay Guthikonda Date: Thu, 4 Jan 2024 00:46:58 -0800 Subject: [PATCH] Add Ruby 3.3 `marking_time` and `sweeping_time` GC metrics (#5) Co-authored-by: Andrey Novikov --- CHANGELOG.md | 2 ++ lib/yabeda/gc.rb | 5 +++++ spec/yabeda/gc_spec.rb | 9 +++++++++ 3 files changed, 16 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index de86b7c..57a7ca6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,7 @@ ## [Unreleased] +- Added support for ruby 3.3 metrics + ## [0.1.0] - 2021-02-24 - Initial release diff --git a/lib/yabeda/gc.rb b/lib/yabeda/gc.rb index 8e6b89b..887fb69 100644 --- a/lib/yabeda/gc.rb +++ b/lib/yabeda/gc.rb @@ -53,6 +53,11 @@ module GC gauge :time, tags: [], comment: "The total time spent in garbage collections" if RUBY_VERSION >= "3.1" + if RUBY_VERSION >= "3.3" + gauge :marking_time, tags: [], comment: "Time spent in the marking phase" + gauge :sweeping_time, tags: [], comment: "Time spent in the sweeping phase" + end + collect do stats = ::GC.stat diff --git a/spec/yabeda/gc_spec.rb b/spec/yabeda/gc_spec.rb index c4fd8d5..d144eec 100644 --- a/spec/yabeda/gc_spec.rb +++ b/spec/yabeda/gc_spec.rb @@ -51,4 +51,13 @@ expect { subject }.to update_yabeda_gauge(Yabeda.gc.time).with(be_a(Integer)) end end + + if RUBY_VERSION >= "3.3" + it "tracks Ruby 3.3 time metrics for GC" do + expect { subject }.to( + update_yabeda_gauge(Yabeda.gc.marking_time).with(be_a(Integer)) + .and(update_yabeda_gauge(Yabeda.gc.sweeping_time).with(be_a(Integer))) + ) + end + end end