Skip to content

Commit

Permalink
YJIT: Count the number of failed instructions
Browse files Browse the repository at this point in the history
  • Loading branch information
k0kubun committed Jul 6, 2023
1 parent 48d95de commit e8a6246
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 13 deletions.
5 changes: 2 additions & 3 deletions doc/yjit/yjit.md
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ irb(main):001:0> RubyVM::YJIT.runtime_stats
{:inline_code_size=>340745,
:outlined_code_size=>297664,
:all_stats=>true,
:exec_instruction=>1547816,
:yjit_insns_count=>1547816,
:send_callsite_not_simple=>7267,
:send_kw_splat=>7,
:send_ivar_set_method=>72,
Expand All @@ -225,8 +225,7 @@ irb(main):001:0> RubyVM::YJIT.runtime_stats

Some of the counters include:

:exec_instruction - how many Ruby bytecode instructions have been executed
:yjit_insns_count - how many Ruby bytecode instruction have been executed in compiled code
:yjit_insns_count - how many Ruby bytecode instructions start execution in compiled code
:binding_allocations - number of bindings allocated
:binding_set - number of variables set via a binding
:code_gc_count - number of garbage collections of compiled code since process start
Expand Down
7 changes: 4 additions & 3 deletions yjit.rb
Original file line number Diff line number Diff line change
Expand Up @@ -158,11 +158,11 @@ def self.runtime_stats(context: false)
return stats unless Primitive.rb_yjit_stats_enabled_p

side_exits = total_exit_count(stats)
total_exits = side_exits + stats[:leave_interp_return]
total_exits = side_exits + stats[:failed_insns_count] + stats[:leave_interp_return]

# Number of instructions that finish executing in YJIT.
# See :count-placement: about the subtraction.
retired_in_yjit = stats[:exec_instruction] - side_exits
retired_in_yjit = stats[:yjit_insns_count] - stats[:failed_insns_count] - side_exits

# Average length of instruction sequences executed by YJIT
avg_len_in_yjit = total_exits > 0 ? retired_in_yjit.to_f / total_exits : 0
Expand Down Expand Up @@ -322,7 +322,8 @@ def _print_stats(out: $stderr) # :nodoc:
if stats.key?(:vm_insns_count)
out.puts "vm_insns_count: " + format_number(13, stats[:vm_insns_count])
end
out.puts "yjit_insns_count: " + format_number(13, stats[:exec_instruction])
out.puts "yjit_insns_count: " + format_number(13, stats[:yjit_insns_count])
out.puts "failed_insns_count: " + format_number(13, stats[:failed_insns_count])
if stats.key?(:ratio_in_yjit)
out.puts "ratio_in_yjit: " + ("%12.1f" % stats[:ratio_in_yjit]) + "%"
end
Expand Down
13 changes: 8 additions & 5 deletions yjit/src/codegen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -847,14 +847,14 @@ pub fn gen_single_block(
verify_ctx(&jit, &asm.ctx);
}

// :count-placement:
// Count bytecode instructions that start execution in generated code.
// Note that the increment happens even when the output takes side exit.
gen_counter_incr(&mut asm, Counter::yjit_insns_count);

// Lookup the codegen function for this instruction
let mut status = None;
if let Some(gen_fn) = get_gen_fn(VALUE(opcode)) {
// :count-placement:
// Count bytecode instructions that execute in generated code.
// Note that the increment happens even when the output takes side exit.
gen_counter_incr(&mut asm, Counter::exec_instruction);

// Add a comment for the name of the YARV instruction
asm.comment(&format!("Insn: {:04} {} (stack_size: {})", insn_idx, insn_name(opcode), asm.ctx.get_stack_size()));

Expand All @@ -871,6 +871,9 @@ pub fn gen_single_block(
// If we can't compile this instruction
// exit to the interpreter and stop compiling
if status == None {
// Count bytecode instructions that cannot be compiled.
gen_counter_incr(&mut asm, Counter::failed_insns_count);

if get_option!(dump_insns) {
println!("can't compile {}", insn_name(opcode));
}
Expand Down
4 changes: 2 additions & 2 deletions yjit/src/stats.rs
Original file line number Diff line number Diff line change
Expand Up @@ -202,8 +202,6 @@ pub(crate) use ptr_to_counter;

// Declare all the counters we track
make_counters! {
exec_instruction,

send_keywords,
send_klass_megamorphic,
send_kw_splat,
Expand Down Expand Up @@ -369,6 +367,8 @@ make_counters! {
binding_set,

vm_insns_count,
yjit_insns_count,
failed_insns_count,
compiled_iseq_entry,
compiled_iseq_count,
compiled_blockid_count,
Expand Down

0 comments on commit e8a6246

Please sign in to comment.