-
Notifications
You must be signed in to change notification settings - Fork 375
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Guage RubyVM::YJIT.runtime_stats if YJIT enabled
YJIT was deemed production ready in Ruby 3.2. YJIT includes its own [runtime stats](https://github.com/ruby/ruby/blob/master/doc/yjit/yjit.md#other-statistics) which would be useful to guage. Currently, this is only enabled when YJIT is enabled (running Ruby with the "--yjit" flag), but NOT when the "--yjit-stats" is _also_ passed. YJIT, by default, has the following runtime stats: ``` $ RUBYOPT='--yjit' ruby -e 'pp RubyVM::YJIT.runtime_stats' => { :inline_code_size=>0, :outlined_code_size=>116, :freed_page_count=>0, :freed_code_size=>0, :live_page_count=>1, :code_gc_count=>0, :code_region_size=>16384, :object_shape_count=>236 } With the `--yjit-stats` flag, it returns 325 separate stats: ``` $ RUBYOPT="--yjit --yjit-stats" ruby -e 'pp RubyVM::YJIT.runtime_stats.keys.length' => 325 ``` And not all of them are numeric: ``` $ RUBYOPT="--yjit --yjit-stats" ruby -e 'pp RubyVM::YJIT.runtime_stats.keys.select { |k| !kind_of?(Numeric) }.any?' => true ```
- Loading branch information
1 parent
35bf597
commit 2ca71db
Showing
7 changed files
with
220 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
name: Test YJIT | ||
on: [push] | ||
jobs: | ||
test-yjit: | ||
strategy: | ||
fail-fast: false | ||
matrix: | ||
os: | ||
- ubuntu-latest | ||
ruby: | ||
- '3.2' | ||
# ADD NEW RUBIES HERE | ||
name: Test (${{ matrix.os }}, ${{ matrix.ruby }}) | ||
runs-on: ${{ matrix.os }} | ||
env: | ||
RUBYOPT: "--yjit" | ||
SKIP_SIMPLECOV: 1 | ||
DD_INSTRUMENTATION_TELEMETRY_ENABLED: false | ||
steps: | ||
- uses: actions/checkout@v3 | ||
# bundler appears to match both prerelease and release rubies when we | ||
# want the former only. relax the constraint to allow any version for | ||
# head rubies | ||
- if: ${{ matrix.ruby == 'head' }} | ||
run: sed -i~ -e '/spec\.required_ruby_version/d' ddtrace.gemspec | ||
- uses: ruby/setup-ruby@9669f3ee51dc3f4eda8447ab696b3ab19a90d14b # v1.144.0 | ||
with: | ||
ruby-version: ${{ matrix.ruby }} | ||
bundler-cache: true # runs 'bundle install' and caches installed gems automatically | ||
bundler: latest # needed to fix issue with steep on Ruby 3.0/3.1 | ||
cache-version: v2 # bump this to invalidate cache | ||
- run: bundle exec rake spec:yjit |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
# frozen_string_literal: true | ||
|
||
module Datadog | ||
module Core | ||
module Environment | ||
# Reports YJIT primitive runtime statistics. | ||
module YJIT | ||
module_function | ||
|
||
# Inline code size | ||
def inline_code_size | ||
::RubyVM::YJIT.runtime_stats[:inline_code_size] | ||
end | ||
|
||
# Outlined code size | ||
def outlined_code_size | ||
::RubyVM::YJIT.runtime_stats[:outlined_code_size] | ||
end | ||
|
||
# GCed pages | ||
def freed_page_count | ||
::RubyVM::YJIT.runtime_stats[:freed_page_count] | ||
end | ||
|
||
# GCed code size | ||
def freed_code_size | ||
::RubyVM::YJIT.runtime_stats[:freed_code_size] | ||
end | ||
|
||
# Live pages | ||
def live_page_count | ||
::RubyVM::YJIT.runtime_stats[:live_page_count] | ||
end | ||
|
||
# Code GC count | ||
def code_gc_count | ||
::RubyVM::YJIT.runtime_stats[:code_gc_count] | ||
end | ||
|
||
# Size of memory region allocated for JIT code | ||
def code_region_size | ||
::RubyVM::YJIT.runtime_stats[:code_region_size] | ||
end | ||
|
||
# Total number of object shapes | ||
def object_shape_count | ||
::RubyVM::YJIT.runtime_stats[:object_shape_count] | ||
end | ||
|
||
def available? | ||
# Not available when --yjit-stats is enabled. | ||
# | ||
# RubyVM::YJIT.runtime_stats contains 8 keys when `.stats_enabled?` is false. | ||
# However, when `.stats_enabled?` is true `.runtime_stats` returns 325 different | ||
# statistics, and not all of them are Numeric. | ||
defined?(::RubyVM::YJIT) \ | ||
&& ::RubyVM::YJIT.enabled? \ | ||
&& ::RubyVM::YJIT.respond_to?(:runtime_stats) \ | ||
&& !::RubyVM::YJIT.stats_enabled? | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters