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

Support stats "ratio_in_yjit" #3991

Merged
merged 10 commits into from
Oct 17, 2024
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
10 changes: 8 additions & 2 deletions .github/workflows/test-yjit.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,16 @@ jobs:
- '3.2'
- '3.3'
# ADD NEW RUBIES HERE
jethrodaniel marked this conversation as resolved.
Show resolved Hide resolved
name: Test (${{ matrix.os }}, ${{ matrix.ruby }})
rubyopt:
- '--yjit'
- '--yjit --yjit-stats=quiet'
exclude:
- ruby: '3.2'
rubyopt: '--yjit --yjit-stats=quiet'
jethrodaniel marked this conversation as resolved.
Show resolved Hide resolved
name: Test YJIT (${{ matrix.os }}, ${{ matrix.ruby }} ${{ matrix.rubyopt }})
runs-on: ${{ matrix.os }}
env:
RUBYOPT: "--yjit"
RUBYOPT: ${{ matrix.rubyopt }}
SKIP_SIMPLECOV: 1
DD_INSTRUMENTATION_TELEMETRY_ENABLED: false
DD_REMOTE_CONFIGURATION_ENABLED: false
Expand Down
5 changes: 5 additions & 0 deletions lib/datadog/core/environment/yjit.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,11 @@ def yjit_alloc_size
::RubyVM::YJIT.runtime_stats[:yjit_alloc_size]
end

# Ratio of YJIT-executed instructions
def ratio_in_yjit
::RubyVM::YJIT.runtime_stats[:ratio_in_yjit]
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 @@ -31,6 +31,7 @@ module Metrics
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'
METRIC_YJIT_RATIO_IN_YJIT = 'runtime.ruby.yjit.ratio_in_yjit'

TAG_SERVICE = 'service'
end
Expand Down
4 changes: 4 additions & 0 deletions lib/datadog/core/runtime/metrics.rb
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,10 @@ def flush_yjit_stats
Core::Runtime::Ext::Metrics::METRIC_YJIT_YJIT_ALLOC_SIZE,
Core::Environment::YJIT.yjit_alloc_size
)
gauge_if_not_nil(
Core::Runtime::Ext::Metrics::METRIC_YJIT_RATIO_IN_YJIT,
Core::Environment::YJIT.ratio_in_yjit
)
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 @@ -11,6 +11,7 @@ module Datadog
def self?.code_region_size: () -> untyped
def self?.object_shape_count: () -> untyped
def self?.yjit_alloc_size: () -> untyped
def self?.ratio_in_yjit: () -> untyped

def self?.available?: () -> untyped
end
Expand Down
24 changes: 20 additions & 4 deletions spec/datadog/core/runtime/metrics_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -198,11 +198,9 @@
skip('Test only runs on Ruby >= 3.2') if RUBY_VERSION < '3.2.'
end

context 'with YJIT enabled and RubyVM::YJIT.stats_enabled? false' do
context 'with YJIT enabled' do
before do
unless Datadog::Core::Environment::YJIT.available?
skip('Test only runs with YJIT enabled and RubyVM::YJIT.stats_enabled? false')
end
skip('Test only runs with YJIT enabled') unless Datadog::Core::Environment::YJIT.available?
allow(runtime_metrics).to receive(:gauge)
end

Expand Down Expand Up @@ -248,6 +246,24 @@
end
end
end

context 'with YJIT enabled and RubyVM::YJIT.stats_enabled? true' do
before do
skip('Test only runs on Ruby >= 3.3') if RUBY_VERSION < '3.3.'
unless Datadog::Core::Environment::YJIT.available? && ::RubyVM::YJIT.stats_enabled?
skip('Test only runs with YJIT enabled and RubyVM::YJIT.stats_enabled? true')
end
allow(runtime_metrics).to receive(:gauge)
end

it do
flush

expect(runtime_metrics).to have_received(:gauge)
.with(Datadog::Core::Runtime::Ext::Metrics::METRIC_YJIT_RATIO_IN_YJIT, kind_of(Numeric))
.once
end
end
end
end

Expand Down
Loading