Skip to content

Commit 33cd970

Browse files
authored
[DOC] ZJIT: Add a section for stats (ruby#14497)
1 parent d82e9f9 commit 33cd970

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed

doc/zjit.md

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,49 @@ You can also run a single test case by matching the method name:
110110
make test-all TESTS="test/ruby/test_zjit.rb -n TestZJIT#test_putobject"
111111
```
112112

113+
## Statistics Collection
114+
115+
ZJIT provides detailed statistics about JIT compilation and execution behavior.
116+
117+
### Basic Stats
118+
119+
Run with basic statistics printed on exit:
120+
121+
```bash
122+
./miniruby --zjit-stats script.rb
123+
```
124+
125+
Collect stats without printing (access via `RubyVM::ZJIT.stats` in Ruby):
126+
127+
```bash
128+
./miniruby --zjit-stats=quiet script.rb
129+
```
130+
131+
### Accessing Stats in Ruby
132+
133+
```ruby
134+
# Check if stats are enabled
135+
if RubyVM::ZJIT.stats_enabled?
136+
stats = RubyVM::ZJIT.stats
137+
puts "Compiled ISEQs: #{stats[:compiled_iseq_count]}"
138+
puts "Failed ISEQs: #{stats[:failed_iseq_count]}"
139+
140+
# You can also reset stats during execution
141+
RubyVM::ZJIT.reset_stats!
142+
end
143+
```
144+
145+
### Performance Ratio
146+
147+
The `ratio_in_zjit` stat shows the percentage of Ruby instructions executed in JIT code vs interpreter. This metric only appears when ZJIT is built with `--enable-zjit=stats` (which enables `rb_vm_insn_count` tracking) and represents a key performance indicator for ZJIT effectiveness.
148+
149+
To build with stats support:
150+
151+
```bash
152+
./configure --enable-zjit=stats
153+
make -j
154+
```
155+
113156
## ZJIT Glossary
114157

115158
This glossary contains terms that are helpful for understanding ZJIT.

0 commit comments

Comments
 (0)