diff options
author | Adam Hess <HParker@github.com> | 2023-04-13 07:07:07 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-04-13 10:07:07 -0400 |
commit | 854baee2c936006d7f38ebb27ee577c00afc6249 (patch) | |
tree | c5bb8bf804adccc29a1af4065c62365dba9445c4 /yjit/src/options.rs | |
parent | 02a7e12b80823919fb614ad3ea6241d5115d14fe (diff) | |
download | ruby-854baee2c936006d7f38ebb27ee577c00afc6249.tar.gz |
YJIT: Add a sampling option to exit tracing (#7693)
Add a sampling option to trace exits
Running YJIT with trace exits enabled can make very large metrics files.
This allows us to configure a sample rate to make tracing exits possible
on larger tests. This also updates the documented YJIT options.
Co-authored-by: Alan Wu <XrXr@users.noreply.github.com>
Co-authored-by: John Hawthorn <john@hawthorn.email>
Co-authored-by: Maxime Chevalier-Boisvert <maximechevalierb@gmail.com>
Diffstat (limited to 'yjit/src/options.rs')
-rw-r--r-- | yjit/src/options.rs | 20 |
1 files changed, 19 insertions, 1 deletions
diff --git a/yjit/src/options.rs b/yjit/src/options.rs index 03acc7bbe0..78a507ce11 100644 --- a/yjit/src/options.rs +++ b/yjit/src/options.rs @@ -32,6 +32,9 @@ pub struct Options { // Trace locations of exits pub gen_trace_exits: bool, + // how often to sample exit trace data + pub trace_exits_sample_rate: usize, + // Whether to start YJIT in paused state (initialize YJIT but don't // compile anything) pub pause: bool, @@ -59,6 +62,7 @@ pub static mut OPTIONS: Options = Options { num_temp_regs: 5, gen_stats: false, gen_trace_exits: false, + trace_exits_sample_rate: 0, pause: false, dump_insns: false, dump_disasm: None, @@ -173,7 +177,8 @@ pub fn parse_option(str_ptr: *const std::os::raw::c_char) -> Option<()> { ("greedy-versioning", "") => unsafe { OPTIONS.greedy_versioning = true }, ("no-type-prop", "") => unsafe { OPTIONS.no_type_prop = true }, ("stats", "") => unsafe { OPTIONS.gen_stats = true }, - ("trace-exits", "") => unsafe { OPTIONS.gen_trace_exits = true; OPTIONS.gen_stats = true }, + ("trace-exits", "") => unsafe { OPTIONS.gen_trace_exits = true; OPTIONS.gen_stats = true; OPTIONS.trace_exits_sample_rate = 0 }, + ("trace-exits-sample-rate", sample_rate) => unsafe { OPTIONS.gen_trace_exits = true; OPTIONS.gen_stats = true; OPTIONS.trace_exits_sample_rate = sample_rate.parse().unwrap(); }, ("dump-insns", "") => unsafe { OPTIONS.dump_insns = true }, ("verify-ctx", "") => unsafe { OPTIONS.verify_ctx = true }, @@ -183,6 +188,19 @@ pub fn parse_option(str_ptr: *const std::os::raw::c_char) -> Option<()> { } } + // before we continue, check that sample_rate is either 0 or a prime number + let trace_sample_rate = unsafe { OPTIONS.trace_exits_sample_rate }; + if trace_sample_rate > 1 { + let mut i = 2; + while i*i <= trace_sample_rate { + if trace_sample_rate % i == 0 { + println!("Warning: using a non-prime number as your sampling rate can result in less accurate sampling data"); + return Some(()); + } + i += 1; + } + } + // dbg!(unsafe {OPTIONS}); // Option successfully parsed |