RJIT: Support --rjit-stats on release build as well

This commit is contained in:
Takashi Kokubun 2023-03-17 22:31:41 -07:00
parent b9f411b3a8
commit 644c998525
5 changed files with 9 additions and 20 deletions

View File

@ -22,7 +22,8 @@ You may still manually pass `--enable-rjit` to try RJIT on unsupported platforms
### --enable-rjit=dev ### --enable-rjit=dev
`--enable-rjit=dev` makes the interpreter slower, but enables `ruby --rjit-stats` to work. `--enable-rjit=dev` makes the interpreter slower, but enables `vm_insns_count` and `ratio_in_rjit`
in `ruby --rjit-stats` to work.
## make ## make
### rjit-bindgen ### rjit-bindgen
@ -35,7 +36,7 @@ macOS seems to have libclang by default. On Ubuntu, you can install it with `apt
## ruby ## ruby
### --rjit-stats ### --rjit-stats
This prints RJIT stats at exit. Available with `--enable-rjit=dev` on configure. This prints RJIT stats at exit. Some stats are available only with `--enable-rjit=dev` on configure.
### --rjit-dump-disasm ### --rjit-dump-disasm

View File

@ -22,6 +22,8 @@ module RubyVM::RJIT
retired_in_rjit = stats[:rjit_insns_count] - stats[:side_exit_count] retired_in_rjit = stats[:rjit_insns_count] - stats[:side_exit_count]
stats[:total_insns_count] = retired_in_rjit + stats[:vm_insns_count] stats[:total_insns_count] = retired_in_rjit + stats[:vm_insns_count]
stats[:ratio_in_rjit] = 100.0 * retired_in_rjit / stats[:total_insns_count] stats[:ratio_in_rjit] = 100.0 * retired_in_rjit / stats[:total_insns_count]
else
stats.delete(:vm_insns_count)
end end
stats stats

4
rjit.c
View File

@ -145,8 +145,8 @@ rb_rjit_setup_options(const char *s, struct rjit_options *rjit_opt)
#define M(shortopt, longopt, desc) RUBY_OPT_MESSAGE(shortopt, longopt, desc) #define M(shortopt, longopt, desc) RUBY_OPT_MESSAGE(shortopt, longopt, desc)
const struct ruby_opt_message rb_rjit_option_messages[] = { const struct ruby_opt_message rb_rjit_option_messages[] = {
#if RJIT_STATS
M("--rjit-stats", "", "Enable collecting RJIT statistics"), M("--rjit-stats", "", "Enable collecting RJIT statistics"),
#if RJIT_STATS
M("--rjit-trace-exits", "", "Trace side exit locations"), M("--rjit-trace-exits", "", "Trace side exit locations"),
#endif #endif
M("--rjit-exec-mem-size=num", "", "Size of executable memory block in MiB (default: " STRINGIZE(DEFAULT_EXEC_MEM_SIZE) ")"), M("--rjit-exec-mem-size=num", "", "Size of executable memory block in MiB (default: " STRINGIZE(DEFAULT_EXEC_MEM_SIZE) ")"),
@ -158,9 +158,9 @@ const struct ruby_opt_message rb_rjit_option_messages[] = {
}; };
#undef M #undef M
#if RJIT_STATS
struct rb_rjit_runtime_counters rb_rjit_counters = { 0 }; struct rb_rjit_runtime_counters rb_rjit_counters = { 0 };
#if RJIT_STATS
void void
rb_rjit_collect_vm_usage_insn(int insn) rb_rjit_collect_vm_usage_insn(int insn)
{ {

View File

@ -406,10 +406,8 @@ rjit_exit_traces(void)
#define SIZEOF(type) RB_SIZE2NUM(sizeof(type)) #define SIZEOF(type) RB_SIZE2NUM(sizeof(type))
#define SIGNED_TYPE_P(type) RBOOL((type)(-1) < (type)(1)) #define SIGNED_TYPE_P(type) RBOOL((type)(-1) < (type)(1))
#if RJIT_STATS
// Insn side exit counters // Insn side exit counters
static size_t rjit_insn_exits[VM_INSTRUCTION_SIZE] = { 0 }; static size_t rjit_insn_exits[VM_INSTRUCTION_SIZE] = { 0 };
#endif // YJIT_STATS
// macOS: brew install capstone // macOS: brew install capstone
// Ubuntu/Debian: apt-get install libcapstone-dev // Ubuntu/Debian: apt-get install libcapstone-dev

View File

@ -18,13 +18,7 @@ module RubyVM::RJIT # :nodoc: all
end end
def rjit_insn_exits def rjit_insn_exits
addr = Primitive.cstmt! %{ addr = Primitive.cexpr! 'SIZET2NUM((size_t)rjit_insn_exits)'
#if RJIT_STATS
return SIZET2NUM((size_t)rjit_insn_exits);
#else
return SIZET2NUM(0);
#endif
}
CType::Immediate.parse("size_t").new(addr) CType::Immediate.parse("size_t").new(addr)
end end
@ -36,13 +30,7 @@ module RubyVM::RJIT # :nodoc: all
end end
def rb_rjit_counters def rb_rjit_counters
addr = Primitive.cstmt! %{ addr = Primitive.cexpr! 'SIZET2NUM((size_t)&rb_rjit_counters)'
#if RJIT_STATS
return SIZET2NUM((size_t)&rb_rjit_counters);
#else
return SIZET2NUM(0);
#endif
}
rb_rjit_runtime_counters.new(addr) rb_rjit_runtime_counters.new(addr)
end end