Skip to content

Commit

Permalink
Support stats "yjit_alloc_size" (#3661)
Browse files Browse the repository at this point in the history
What does this PR do?

Add stats "yjit_alloc_size"
which stats is available by default since Ruby 3.3
yjit_alloc_size and several more metadata-related stats are now available by default.
ref: ruby-lang.org/en/news/2023/12/25/ruby-3-3-0-released

Motivation:

The new metrics helps us tune --yjit-exec-mem-size option.
Monitoring both code_region_size and yjit_alloc_size makes it easier to understand the impact of YJIT's memory usage. (translated by DeepL)
ref: gihyo.jp/article/2024/01/ruby3.3-jit

* Support stats "yjit_alloc_size"

* Disable cop: Metrics/MethodLength

lib/datadog/core/runtime/metrics.rb:143:9: C: Metrics/MethodLength: Method has too many lines. [40/36]
        def flush_yjit_stats ...
        ^^^^^^^^^^^^^^^^^^^^

* Add Ruby 3.3 to matrix target in test-yjit

* Run test for metric :yjit_alloc_size if Ruby.version >= 3.3

ref: https://github.com/ruby/ruby/blob/029d92b8988d26955d0622f0cbb8ef3213200749/doc/NEWS/NEWS-3.3.0.md?plain=1#L435

---------

Co-authored-by: Oleg Pudeyev <[email protected]>
  • Loading branch information
MITSUBOSHI and p authored Jun 12, 2024
1 parent bd08222 commit b047a30
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 0 deletions.
5 changes: 5 additions & 0 deletions lib/datadog/core/environment/yjit.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@ def object_shape_count
::RubyVM::YJIT.runtime_stats[:object_shape_count]
end

# Size of memory Rust allocated for metadata
def yjit_alloc_size
::RubyVM::YJIT.runtime_stats[:yjit_alloc_size]
end

def available?
defined?(::RubyVM::YJIT) \
&& ::RubyVM::YJIT.enabled? \
Expand Down
1 change: 1 addition & 0 deletions lib/datadog/core/runtime/ext.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ module Metrics
METRIC_YJIT_LIVE_PAGE_COUNT = 'runtime.ruby.yjit.live_page_count'
METRIC_YJIT_OBJECT_SHAPE_COUNT = 'runtime.ruby.yjit.object_shape_count'
METRIC_YJIT_OUTLINED_CODE_SIZE = 'runtime.ruby.yjit.outlined_code_size'
METRIC_YJIT_YJIT_ALLOC_SIZE = 'runtime.ruby.yjit.yjit_alloc_size'

TAG_SERVICE = 'service'
end
Expand Down
6 changes: 6 additions & 0 deletions lib/datadog/core/runtime/metrics.rb
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ def gauge_if_not_nil(metric_name, metric_value)
gauge(metric_name, metric_value) if metric_value
end

# rubocop:disable Metrics/MethodLength
def flush_yjit_stats
# Only on Ruby >= 3.2
try_flush do
Expand Down Expand Up @@ -176,9 +177,14 @@ def flush_yjit_stats
Core::Runtime::Ext::Metrics::METRIC_YJIT_OUTLINED_CODE_SIZE,
Core::Environment::YJIT.outlined_code_size
)
gauge_if_not_nil(
Core::Runtime::Ext::Metrics::METRIC_YJIT_YJIT_ALLOC_SIZE,
Core::Environment::YJIT.yjit_alloc_size
)
end
end
end
# rubocop:enable Metrics/MethodLength
end
end
end
Expand Down
1 change: 1 addition & 0 deletions sig/datadog/core/environment/yjit.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ module Datadog
def self?.code_gc_count: () -> untyped
def self?.code_region_size: () -> untyped
def self?.object_shape_count: () -> untyped
def self?.yjit_alloc_size: () -> untyped

def self?.available?: () -> untyped
end
Expand Down
6 changes: 6 additions & 0 deletions spec/datadog/core/runtime/metrics_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,12 @@
expect(runtime_metrics).to have_received(:gauge)
.with(Datadog::Core::Runtime::Ext::Metrics::METRIC_YJIT_OUTLINED_CODE_SIZE, kind_of(Numeric))
.once

if RUBY_VERSION >= '3.3.0'
expect(runtime_metrics).to have_received(:gauge)
.with(Datadog::Core::Runtime::Ext::Metrics::METRIC_YJIT_YJIT_ALLOC_SIZE, kind_of(Numeric))
.once
end
end
end
end
Expand Down

0 comments on commit b047a30

Please sign in to comment.