diff --git a/lib/ruby_vm/mjit/compiler.rb b/lib/ruby_vm/mjit/compiler.rb index f855c8a6a5..18f2d94016 100644 --- a/lib/ruby_vm/mjit/compiler.rb +++ b/lib/ruby_vm/mjit/compiler.rb @@ -224,6 +224,14 @@ module RubyVM::MJIT raise "compiling #{insn.name} returned unexpected status: #{status.inspect}" end end + + incr_counter(:compiled_block_count) + end + + def incr_counter(name) + if C.mjit_opts.stats + C.rb_mjit_counters[name][0] += 1 + end end end end diff --git a/lib/ruby_vm/mjit/stats.rb b/lib/ruby_vm/mjit/stats.rb index 7fa9236257..bc5a30738e 100644 --- a/lib/ruby_vm/mjit/stats.rb +++ b/lib/ruby_vm/mjit/stats.rb @@ -36,6 +36,7 @@ module RubyVM::MJIT print_counters(stats, prefix: 'send_', prompt: 'method call exit reasons') + $stderr.puts "compiled_block_count: #{format('%10d', stats[:compiled_block_count])}" $stderr.puts "side_exit_count: #{format('%10d', stats[:side_exit_count])}" $stderr.puts "total_insns_count: #{format('%10d', stats[:total_insns_count])}" if stats.key?(:total_insns_count) $stderr.puts "vm_insns_count: #{format('%10d', stats[:vm_insns_count])}" if stats.key?(:vm_insns_count) diff --git a/mjit.c b/mjit.c index 76e249de62..26a05fc6ea 100644 --- a/mjit.c +++ b/mjit.c @@ -491,6 +491,15 @@ mjit_stats_enabled_p(rb_execution_context_t *ec, VALUE self) return RBOOL(mjit_stats_enabled); } +// Disable anything that could impact stats. It ends up disabling JIT calls as well. +static VALUE +mjit_stop_stats(rb_execution_context_t *ec, VALUE self) +{ + mjit_call_p = false; + mjit_stats_p = false; + return Qnil; +} + #include "mjit.rbinc" #endif // USE_MJIT diff --git a/mjit.rb b/mjit.rb index 695c56fad1..f9679e9164 100644 --- a/mjit.rb +++ b/mjit.rb @@ -15,7 +15,10 @@ module RubyVM::MJIT end if Primitive.mjit_stats_enabled_p - at_exit { print_stats } + at_exit do + Primitive.mjit_stop_stats + print_stats + end end end diff --git a/mjit_c.h b/mjit_c.h index 69a37f3e80..5c08616dcd 100644 --- a/mjit_c.h +++ b/mjit_c.h @@ -107,6 +107,7 @@ extern uint8_t *rb_mjit_mem_block; #define MJIT_RUNTIME_COUNTERS(...) struct rb_mjit_runtime_counters { size_t __VA_ARGS__; }; MJIT_RUNTIME_COUNTERS( vm_insns_count, + mjit_insns_count, send_kw_splat, send_guard_known_object, @@ -118,7 +119,7 @@ MJIT_RUNTIME_COUNTERS( send_kwarg, send_tailcall, - mjit_insns_count + compiled_block_count ) #undef MJIT_RUNTIME_COUNTERS extern struct rb_mjit_runtime_counters rb_mjit_counters; diff --git a/mjit_c.rb b/mjit_c.rb index 65673b1257..871e5b461c 100644 --- a/mjit_c.rb +++ b/mjit_c.rb @@ -796,6 +796,7 @@ module RubyVM::MJIT # :nodoc: all @rb_mjit_runtime_counters ||= CType::Struct.new( "rb_mjit_runtime_counters", Primitive.cexpr!("SIZEOF(struct rb_mjit_runtime_counters)"), vm_insns_count: [CType::Immediate.parse("size_t"), Primitive.cexpr!("OFFSETOF((*((struct rb_mjit_runtime_counters *)NULL)), vm_insns_count)")], + mjit_insns_count: [CType::Immediate.parse("size_t"), Primitive.cexpr!("OFFSETOF((*((struct rb_mjit_runtime_counters *)NULL)), mjit_insns_count)")], send_kw_splat: [CType::Immediate.parse("size_t"), Primitive.cexpr!("OFFSETOF((*((struct rb_mjit_runtime_counters *)NULL)), send_kw_splat)")], send_guard_known_object: [CType::Immediate.parse("size_t"), Primitive.cexpr!("OFFSETOF((*((struct rb_mjit_runtime_counters *)NULL)), send_guard_known_object)")], send_missing_cme: [CType::Immediate.parse("size_t"), Primitive.cexpr!("OFFSETOF((*((struct rb_mjit_runtime_counters *)NULL)), send_missing_cme)")], @@ -805,7 +806,7 @@ module RubyVM::MJIT # :nodoc: all send_args_splat: [CType::Immediate.parse("size_t"), Primitive.cexpr!("OFFSETOF((*((struct rb_mjit_runtime_counters *)NULL)), send_args_splat)")], send_kwarg: [CType::Immediate.parse("size_t"), Primitive.cexpr!("OFFSETOF((*((struct rb_mjit_runtime_counters *)NULL)), send_kwarg)")], send_tailcall: [CType::Immediate.parse("size_t"), Primitive.cexpr!("OFFSETOF((*((struct rb_mjit_runtime_counters *)NULL)), send_tailcall)")], - mjit_insns_count: [CType::Immediate.parse("size_t"), Primitive.cexpr!("OFFSETOF((*((struct rb_mjit_runtime_counters *)NULL)), mjit_insns_count)")], + compiled_block_count: [CType::Immediate.parse("size_t"), Primitive.cexpr!("OFFSETOF((*((struct rb_mjit_runtime_counters *)NULL)), compiled_block_count)")], ) end