YJIT: track time since initialization (#12263)

This commit is contained in:
Maxime Chevalier-Boisvert 2024-12-04 16:24:36 -05:00 committed by GitHub
parent 3c91a1e5fd
commit 4b4d52ef50
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
Notes: git 2024-12-04 21:24:59 +00:00
Merged-By: maximecb <maximecb@ruby-lang.org>
3 changed files with 17 additions and 2 deletions

View File

@ -389,7 +389,9 @@ module RubyVM::YJIT
end
out.puts "max_inline_versions: " + format_number(13, stats[:max_inline_versions])
out.puts "compiled_branch_count: " + format_number(13, stats[:compiled_branch_count])
out.puts "compile_time_ms: " + format_number(13, stats[:compile_time_ns] / (1000 * 1000))
out.puts "yjit_active_ms: " + format_number(13, stats[:yjit_active_ns] / 10**6)
out.puts "compile_time_ms: " + format_number_pct(13, stats[:compile_time_ns] / 10**6 , stats[:yjit_active_ns] / 10**6)
out.puts "block_next_count: " + format_number(13, stats[:block_next_count])
out.puts "defer_count: " + format_number(13, stats[:defer_count])
out.puts "defer_empty_count: " + format_number(13, stats[:defer_empty_count])

View File

@ -12,7 +12,7 @@ use std::collections::HashMap;
use crate::codegen::CodegenGlobals;
use crate::cruby::*;
use crate::options::*;
use crate::yjit::yjit_enabled_p;
use crate::yjit::{yjit_enabled_p, YJIT_INIT_TIME};
/// Running total of how many ISeqs are in the system.
#[no_mangle]
@ -797,6 +797,10 @@ fn rb_yjit_gen_stats_dict(key: VALUE) -> VALUE {
set_stat_usize!(hash, "iseq_alloc_count", rb_yjit_iseq_alloc_count as usize);
set_stat!(hash, "object_shape_count", rb_object_shape_count());
// Time since YJIT init in nanoseconds
let time_nanos = Instant::now().duration_since(YJIT_INIT_TIME.unwrap()).as_nanos();
set_stat_usize!(hash, "yjit_active_ns", time_nanos as usize);
}
// If we're not generating stats, put only default counters

View File

@ -8,6 +8,7 @@ use crate::stats::incr_counter;
use crate::stats::with_compile_time;
use std::os::raw::{c_char, c_int};
use std::time::Instant;
use crate::log::Log;
/// Is YJIT on? The interpreter uses this variable to decide whether to trigger
@ -16,6 +17,9 @@ use crate::log::Log;
#[no_mangle]
pub static mut rb_yjit_enabled_p: bool = false;
// Time when YJIT was yjit was initialized (see yjit_init)
pub static mut YJIT_INIT_TIME: Option<Instant> = None;
/// Parse one command-line option.
/// This is called from ruby.c
#[no_mangle]
@ -76,6 +80,11 @@ fn yjit_init() {
let _ = std::fs::remove_file(&perf_map);
println!("YJIT perf map: {perf_map}");
}
// Note the time when YJIT was initialized
unsafe {
YJIT_INIT_TIME = Some(Instant::now());
}
}
#[no_mangle]