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

Add ruby3 gc metrics #3

Merged
merged 2 commits into from
Jun 15, 2022
Merged
Show file tree
Hide file tree
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
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,9 @@ Or install it yourself as:
## Metrics

| Metric | Description |
| ----------------------------------------- | --------------------------------------------------------------------------------------------------------- |
|-------------------------------------------|-----------------------------------------------------------------------------------------------------------|
| `count` | Count of all GCs |
| `time` | The total time spent in garbage collections (ruby 3+) |
| `minor_gc_count` | Count of minor GCs |
| `major_gc_count` | Count of major GCs |
| `heap_allocated_pages` | Total number of pages allocated for the heap |
Expand All @@ -48,6 +49,8 @@ Or install it yourself as:
| `oldmalloc_increase_bytes` | Total bytes allocated to old objects |
| `oldmalloc_increase_bytes_limit` | Bytes limit that will trigger garbage collection of old objects |
| `compact_count` | Count of all GC compactions |
| `read_barrier_faults` | The total number of times the read barrier was triggered during compaction (ruby 3+) |
| `total_moved_objects` | The total number of objects compaction has moved (ruby 3+) |

## Development

Expand Down
6 changes: 6 additions & 0 deletions lib/yabeda/gc.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,12 @@ module GC
gauge :oldmalloc_increase_bytes_limit, tags: [],
comment: "Bytes limit that will trigger garbage collection of old objects"

if RUBY_VERSION >= "3.0"
gauge :time, tags: [], comment: "The total time spent in garbage collections"
gauge :read_barrier_faults, tags: [], comment: "The total number of times the read barrier was triggered during compaction"
gauge :total_moved_objects, tags: [], comment: "The total number of objects compaction has moved"
end

collect do
stats = ::GC.stat

Expand Down
2 changes: 1 addition & 1 deletion lib/yabeda/gc/version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@

module Yabeda
module GC
VERSION = "0.1.1"
VERSION = "0.1.2"
end
end
20 changes: 14 additions & 6 deletions spec/yabeda/gc_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@

RSpec.describe Yabeda::GC do
before do
Yabeda.gc.public_methods(false).each do |method_name|
next if method_name == :register_metric

::GC.stat.each_key do |method_name|
Yabeda.gc.__send__(method_name).values.clear
end
end
Expand Down Expand Up @@ -45,12 +43,22 @@
)
end

if RUBY_VERSION >= "3.0"
it "tracks ruby3 metrics for GC" do
Yabeda.collectors.each(&:call)

expect(summary).to include(
time: { {} => be_a(Integer) },
read_barrier_faults: { {} => be_a(Integer) },
total_moved_objects: { {} => be_a(Integer) }
)
end
end

def summary
result = {}

Yabeda.gc.public_methods(false).each do |method_name|
next if method_name == :register_metric

::GC.stat.each_key do |method_name|
metric = Yabeda.gc.__send__(method_name)
result[metric.name] = metric.values
end
Expand Down