From 3dff315ed3e01f54980410008b73c6a838528e08 Mon Sep 17 00:00:00 2001 From: ywenc Date: Fri, 18 Aug 2023 18:27:59 -0400 Subject: [PATCH] YJIT: Quiet mode when running with `--yjit-stats` (#8251) Quiet mode for running with --yjit-stats --- yjit.c | 1 + yjit.rb | 4 +++- yjit/src/options.rs | 17 +++++++++++++++-- yjit/src/stats.rs | 11 +++++++++++ 4 files changed, 30 insertions(+), 3 deletions(-) diff --git a/yjit.c b/yjit.c index 052346950f..badd46b99a 100644 --- a/yjit.c +++ b/yjit.c @@ -1169,6 +1169,7 @@ rb_yjit_set_exception_return(rb_control_frame_t *cfp, void *leave_exit, void *le // Primitives used by yjit.rb VALUE rb_yjit_stats_enabled_p(rb_execution_context_t *ec, VALUE self); +VALUE rb_yjit_print_stats_p(rb_execution_context_t *ec, VALUE self); VALUE rb_yjit_trace_exit_locations_enabled_p(rb_execution_context_t *ec, VALUE self); VALUE rb_yjit_get_stats(rb_execution_context_t *ec, VALUE self, VALUE context); VALUE rb_yjit_reset_stats_bang(rb_execution_context_t *ec, VALUE self); diff --git a/yjit.rb b/yjit.rb index 30e353a596..01d3efc6d2 100644 --- a/yjit.rb +++ b/yjit.rb @@ -226,7 +226,9 @@ module RubyVM::YJIT # Avoid calling a method here to not interfere with compilation tests if Primitive.rb_yjit_stats_enabled_p at_exit do - _print_stats + if Primitive.rb_yjit_print_stats_p + _print_stats + end _dump_locations end end diff --git a/yjit/src/options.rs b/yjit/src/options.rs index f08217bfc2..4448ece8ec 100644 --- a/yjit/src/options.rs +++ b/yjit/src/options.rs @@ -26,9 +26,12 @@ pub struct Options { // The number of registers allocated for stack temps pub num_temp_regs: usize, - // Capture and print out stats + // Capture stats pub gen_stats: bool, + // Print stats on exit (when gen_stats is also true) + pub print_stats: bool, + // Trace locations of exits pub gen_trace_exits: bool, @@ -62,6 +65,7 @@ pub static mut OPTIONS: Options = Options { num_temp_regs: 5, gen_stats: false, gen_trace_exits: false, + print_stats: true, trace_exits_sample_rate: 0, pause: false, dump_insns: false, @@ -176,7 +180,16 @@ pub fn parse_option(str_ptr: *const std::os::raw::c_char) -> Option<()> { ("greedy-versioning", "") => unsafe { OPTIONS.greedy_versioning = true }, ("no-type-prop", "") => unsafe { OPTIONS.no_type_prop = true }, - ("stats", "") => unsafe { OPTIONS.gen_stats = true }, + ("stats", _) => match opt_val.to_string().as_str() { + "" => unsafe { OPTIONS.gen_stats = true }, + "quiet" => { + unsafe { OPTIONS.gen_stats = true } + unsafe { OPTIONS.print_stats = false } + }, + _ => { + return None; + } + }, ("trace-exits", "") => unsafe { OPTIONS.gen_trace_exits = true; OPTIONS.gen_stats = true; OPTIONS.trace_exits_sample_rate = 0 }, ("trace-exits-sample-rate", sample_rate) => unsafe { OPTIONS.gen_trace_exits = true; OPTIONS.gen_stats = true; OPTIONS.trace_exits_sample_rate = sample_rate.parse().unwrap(); }, ("dump-insns", "") => unsafe { OPTIONS.dump_insns = true }, diff --git a/yjit/src/stats.rs b/yjit/src/stats.rs index 9ef3e8e94c..ef4d25d051 100644 --- a/yjit/src/stats.rs +++ b/yjit/src/stats.rs @@ -463,6 +463,17 @@ pub extern "C" fn rb_yjit_stats_enabled_p(_ec: EcPtr, _ruby_self: VALUE) -> VALU } } +/// Primitive called in yjit.rb +/// Check if stats generation should print at exit +#[no_mangle] +pub extern "C" fn rb_yjit_print_stats_p(_ec: EcPtr, _ruby_self: VALUE) -> VALUE { + if get_option!(print_stats) { + return Qtrue; + } else { + return Qfalse; + } +} + /// Primitive called in yjit.rb. /// Export all YJIT statistics as a Ruby hash. #[no_mangle]