Skip to content

Commit

Permalink
Merge pull request #3991 from jethrodaniel/add-ratio_in_yjit
Browse files Browse the repository at this point in the history
Support stats "ratio_in_yjit"
  • Loading branch information
ivoanjo authored Oct 17, 2024
2 parents 7cd16a5 + a06708a commit 27ea135
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 6 deletions.
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
name: Test (${{ matrix.os }}, ${{ matrix.ruby }})
rubyopt:
- '--yjit'
- '--yjit --yjit-stats=quiet'
exclude:
- ruby: '3.2'
rubyopt: '--yjit --yjit-stats=quiet'
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

0 comments on commit 27ea135

Please sign in to comment.