Skip to content

Commit 27ea135

Browse files
authored
Merge pull request #3991 from jethrodaniel/add-ratio_in_yjit
Support stats "ratio_in_yjit"
2 parents 7cd16a5 + a06708a commit 27ea135

File tree

6 files changed

+39
-6
lines changed

6 files changed

+39
-6
lines changed

.github/workflows/test-yjit.yaml

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,16 @@ jobs:
1111
- '3.2'
1212
- '3.3'
1313
# ADD NEW RUBIES HERE
14-
name: Test (${{ matrix.os }}, ${{ matrix.ruby }})
14+
rubyopt:
15+
- '--yjit'
16+
- '--yjit --yjit-stats=quiet'
17+
exclude:
18+
- ruby: '3.2'
19+
rubyopt: '--yjit --yjit-stats=quiet'
20+
name: Test YJIT (${{ matrix.os }}, ${{ matrix.ruby }} ${{ matrix.rubyopt }})
1521
runs-on: ${{ matrix.os }}
1622
env:
17-
RUBYOPT: "--yjit"
23+
RUBYOPT: ${{ matrix.rubyopt }}
1824
SKIP_SIMPLECOV: 1
1925
DD_INSTRUMENTATION_TELEMETRY_ENABLED: false
2026
DD_REMOTE_CONFIGURATION_ENABLED: false

lib/datadog/core/environment/yjit.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,11 @@ def yjit_alloc_size
5252
::RubyVM::YJIT.runtime_stats[:yjit_alloc_size]
5353
end
5454

55+
# Ratio of YJIT-executed instructions
56+
def ratio_in_yjit
57+
::RubyVM::YJIT.runtime_stats[:ratio_in_yjit]
58+
end
59+
5560
def available?
5661
defined?(::RubyVM::YJIT) \
5762
&& ::RubyVM::YJIT.enabled? \

lib/datadog/core/runtime/ext.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ module Metrics
3131
METRIC_YJIT_OBJECT_SHAPE_COUNT = 'runtime.ruby.yjit.object_shape_count'
3232
METRIC_YJIT_OUTLINED_CODE_SIZE = 'runtime.ruby.yjit.outlined_code_size'
3333
METRIC_YJIT_YJIT_ALLOC_SIZE = 'runtime.ruby.yjit.yjit_alloc_size'
34+
METRIC_YJIT_RATIO_IN_YJIT = 'runtime.ruby.yjit.ratio_in_yjit'
3435

3536
TAG_SERVICE = 'service'
3637
end

lib/datadog/core/runtime/metrics.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,10 @@ def flush_yjit_stats
181181
Core::Runtime::Ext::Metrics::METRIC_YJIT_YJIT_ALLOC_SIZE,
182182
Core::Environment::YJIT.yjit_alloc_size
183183
)
184+
gauge_if_not_nil(
185+
Core::Runtime::Ext::Metrics::METRIC_YJIT_RATIO_IN_YJIT,
186+
Core::Environment::YJIT.ratio_in_yjit
187+
)
184188
end
185189
end
186190
end

sig/datadog/core/environment/yjit.rbs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ module Datadog
1111
def self?.code_region_size: () -> untyped
1212
def self?.object_shape_count: () -> untyped
1313
def self?.yjit_alloc_size: () -> untyped
14+
def self?.ratio_in_yjit: () -> untyped
1415

1516
def self?.available?: () -> untyped
1617
end

spec/datadog/core/runtime/metrics_spec.rb

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -198,11 +198,9 @@
198198
skip('Test only runs on Ruby >= 3.2') if RUBY_VERSION < '3.2.'
199199
end
200200

201-
context 'with YJIT enabled and RubyVM::YJIT.stats_enabled? false' do
201+
context 'with YJIT enabled' do
202202
before do
203-
unless Datadog::Core::Environment::YJIT.available?
204-
skip('Test only runs with YJIT enabled and RubyVM::YJIT.stats_enabled? false')
205-
end
203+
skip('Test only runs with YJIT enabled') unless Datadog::Core::Environment::YJIT.available?
206204
allow(runtime_metrics).to receive(:gauge)
207205
end
208206

@@ -248,6 +246,24 @@
248246
end
249247
end
250248
end
249+
250+
context 'with YJIT enabled and RubyVM::YJIT.stats_enabled? true' do
251+
before do
252+
skip('Test only runs on Ruby >= 3.3') if RUBY_VERSION < '3.3.'
253+
unless Datadog::Core::Environment::YJIT.available? && ::RubyVM::YJIT.stats_enabled?
254+
skip('Test only runs with YJIT enabled and RubyVM::YJIT.stats_enabled? true')
255+
end
256+
allow(runtime_metrics).to receive(:gauge)
257+
end
258+
259+
it do
260+
flush
261+
262+
expect(runtime_metrics).to have_received(:gauge)
263+
.with(Datadog::Core::Runtime::Ext::Metrics::METRIC_YJIT_RATIO_IN_YJIT, kind_of(Numeric))
264+
.once
265+
end
266+
end
251267
end
252268
end
253269

0 commit comments

Comments
 (0)