Skip to content

Commit df2d1d5

Browse files
author
Aiden Fox Ivey
authored
ZJIT: Decouple stats and side exit tracing (ruby#14688)
1 parent e90729a commit df2d1d5

4 files changed

Lines changed: 12 additions & 11 deletions

File tree

doc/zjit.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -155,10 +155,10 @@ make -j
155155

156156
### Tracing side exits
157157

158-
Through [Stackprof](https://github.com/tmm1/stackprof), detailed information about the methods that the JIT side-exits from can be displayed after some execution of a program. Note that the use of `--zjit-trace-exits` must be used alongside `--zjit-stats`.
158+
Through [Stackprof](https://github.com/tmm1/stackprof), detailed information about the methods that the JIT side-exits from can be displayed after some execution of a program.
159159

160160
```bash
161-
./miniruby --zjit-stats --zjit-trace-exits script.rb
161+
./miniruby --zjit-trace-exits script.rb
162162
```
163163

164164
A file called `zjit_exit_locations.dump` will be created in the same directory as `script.rb`. Viewing the side exited methods can be done with Stackprof:

zjit.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@
99
module RubyVM::ZJIT
1010
# Avoid calling a Ruby method here to avoid interfering with compilation tests
1111
if Primitive.rb_zjit_print_stats_p
12-
at_exit {
13-
print_stats
14-
dump_locations
15-
}
12+
at_exit { print_stats }
13+
end
14+
if Primitive.rb_zjit_trace_exit_locations_enabled_p
15+
at_exit { dump_locations }
1616
end
1717
end
1818

zjit/src/state.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -392,7 +392,7 @@ pub extern "C" fn rb_zjit_record_exit_stack(exit_pc: *const VALUE) {
392392
/// Mark `raw_samples` so they can be used by rb_zjit_add_frame.
393393
pub fn gc_mark_raw_samples() {
394394
// Return if ZJIT is not enabled
395-
if !zjit_enabled_p() || !get_option!(stats) || !get_option!(trace_side_exits) {
395+
if !zjit_enabled_p() || !get_option!(trace_side_exits) {
396396
return;
397397
}
398398

zjit/src/stats.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
33
use std::time::Instant;
44
use std::sync::atomic::Ordering;
5+
use crate::options::OPTIONS;
56

67
#[cfg(feature = "stats_allocator")]
78
#[path = "../../jit/src/lib.rs"]
@@ -475,11 +476,11 @@ pub struct SideExitLocations {
475476

476477
/// Primitive called in zjit.rb
477478
///
478-
/// Check if trace_exits generation is enabled. Requires the stats feature
479-
/// to be enabled.
479+
/// Check if trace_exits generation is enabled.
480480
#[unsafe(no_mangle)]
481481
pub extern "C" fn rb_zjit_trace_exit_locations_enabled_p(_ec: EcPtr, _ruby_self: VALUE) -> VALUE {
482-
if get_option!(stats) && get_option!(trace_side_exits) {
482+
// Builtin zjit.rb calls this even if ZJIT is disabled, so OPTIONS may not be set.
483+
if unsafe { OPTIONS.as_ref() }.is_some_and(|opts| opts.trace_side_exits) {
483484
Qtrue
484485
} else {
485486
Qfalse
@@ -490,7 +491,7 @@ pub extern "C" fn rb_zjit_trace_exit_locations_enabled_p(_ec: EcPtr, _ruby_self:
490491
/// into raw, lines, and frames hash for RubyVM::YJIT.exit_locations.
491492
#[unsafe(no_mangle)]
492493
pub extern "C" fn rb_zjit_get_exit_locations(_ec: EcPtr, _ruby_self: VALUE) -> VALUE {
493-
if !zjit_enabled_p() || !get_option!(stats) || !get_option!(trace_side_exits) {
494+
if !zjit_enabled_p() || !get_option!(trace_side_exits) {
494495
return Qnil;
495496
}
496497

0 commit comments

Comments
 (0)