From 729bcf98be0b7a8b39706d86b45e8c03d2bcb8a5 Mon Sep 17 00:00:00 2001 From: Luke Gruber Date: Wed, 27 May 2026 14:07:12 -0400 Subject: [PATCH] add new RUBY_BENCH_CMD_PREFIX option If you want to run `perf` during the benchmark run, but you don't want to record any non-benchmark code, there is currently no way to do this outside of the perf harness. The perf harness has the downside that it only works with perf, and not with samply or other profilers. RUBY_BENCH_CMD_PREFIX="perf record -g" ./run_benchmarks.rb --chruby="head::ruby_head --yjit --yjit-perf=map" railsbench You can use any command you want, so it's not limited to perf: RUBY_BENCH_CMD_PREFIX="samply record" ./run_benchmarks.rb --chruby="head::ruby_head --yjit" railsbench Note that unlike the perf harness, this wraps the entire benchmark run with the command, so even warmup iterations are recorded. This option can be used with any command, so it's not limited to profiling. You can currently run perf or samply by running the benchmark directly, but it's useful to go through `run_benchmarks.rb` option processing and chruby switching. --- lib/benchmark_suite.rb | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/lib/benchmark_suite.rb b/lib/benchmark_suite.rb index cb71fc78..53bf1422 100644 --- a/lib/benchmark_suite.rb +++ b/lib/benchmark_suite.rb @@ -157,6 +157,11 @@ def run_single_benchmark(script_path, result_json_path, ruby, cmd_prefix, env, b # Use per-benchmark default_harness if set, otherwise use global harness benchmark_harness = benchmark_harness_for(benchmark_name) + + if prefix = ENV["RUBY_BENCH_CMD_PREFIX"] + cmd_prefix = prefix.shellsplit + cmd_prefix + end + # Set up the benchmarking command cmd = cmd_prefix + [ *ruby,