Skip to content

Commit

Permalink
Hoist out the exec_instruction counter
Browse files Browse the repository at this point in the history
  • Loading branch information
k0kubun committed Jul 7, 2023
1 parent f776f2f commit 0f50f13
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 16 deletions.
2 changes: 1 addition & 1 deletion doc/yjit/yjit.md
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +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
:exec_instruction - how many Ruby bytecode instructions have been executed
: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: 2 additions & 5 deletions yjit.rb
Original file line number Diff line number Diff line change
Expand Up @@ -162,9 +162,7 @@ def self.runtime_stats(context: false)

# Number of instructions that finish executing in YJIT.
# See :count-placement: about the subtraction.
# We add failed_insns_count because it's in side_exits
# but not in exec_instructions.
retired_in_yjit = stats[:exec_instructions] + stats[:failed_insns_count] - side_exits
retired_in_yjit = stats[:exec_instruction] - 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 @@ -318,14 +316,13 @@ def _print_stats(out: $stderr) # :nodoc:
out.puts "code_gc_count: " + format_number(13, stats[:code_gc_count])
out.puts "num_gc_obj_refs: " + format_number(13, stats[:num_gc_obj_refs])
out.puts "object_shape_count: " + format_number(13, stats[:object_shape_count])
out.puts "failed_insns_count: " + format_number(13, stats[:failed_insns_count])
out.puts "side_exit_count: " + format_number(13, stats[:side_exit_count])
out.puts "total_exit_count: " + format_number(13, stats[:total_exit_count])
out.puts "total_insns_count: " + format_number(13, stats[:total_insns_count]) if stats.key?(:total_insns_count)
if stats.key?(:vm_insns_count)
out.puts "vm_insns_count: " + format_number(13, stats[:vm_insns_count])
end
out.puts "exec_instructions: " + format_number(13, stats[:exec_instructions])
out.puts "exec_instruction: " + format_number(13, stats[:exec_instruction])
if stats.key?(:ratio_in_yjit)
out.puts "ratio_in_yjit: " + ("%12.1f" % stats[:ratio_in_yjit]) + "%"
end
Expand Down
13 changes: 5 additions & 8 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 execute in generated code.
// Note that the increment happens even when the output takes side exit.
gen_counter_incr(&mut asm, Counter::exec_instruction);

// 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_instructions);

// 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 @@ -866,9 +866,6 @@ pub fn gen_single_block(

// Call the code generation function
status = gen_fn(&mut jit, &mut asm, ocb);
} else {
// Count bytecode instructions that are not supported by YJIT.
gen_counter_incr(&mut asm, Counter::failed_insns_count);
}

// If we can't compile this instruction
Expand Down
3 changes: 1 addition & 2 deletions yjit/src/stats.rs
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ pub(crate) use ptr_to_counter;

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

send_keywords,
send_klass_megamorphic,
Expand Down Expand Up @@ -369,7 +369,6 @@ make_counters! {
binding_set,

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

0 comments on commit 0f50f13

Please sign in to comment.