Skip to content

Commit

Permalink
Limit YJIT stats to the measured benchmark code (#352)
Browse files Browse the repository at this point in the history
Reset stats at the beginning of the benchmark
and collect stats before loading any additional code.
  • Loading branch information
rwstauner authored Dec 9, 2024
1 parent cbe285e commit 6d9c1d8
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
6 changes: 4 additions & 2 deletions harness/harness-common.rb
Original file line number Diff line number Diff line change
Expand Up @@ -101,15 +101,17 @@ def return_results(warmup_iterations, bench_iterations)
"bench" => bench_iterations,
}

# Collect yjit stats before loading any additional code.
yjit_stats = RubyVM::YJIT.runtime_stats if defined?(RubyVM::YJIT) && RubyVM::YJIT.enabled?

# Collect our own peak mem usage as soon as reasonable after finishing the last iteration.
rss = get_rss
yjit_bench_results["rss"] = rss
if maxrss = get_maxrss
yjit_bench_results["maxrss"] = maxrss
end

if defined?(RubyVM::YJIT) && RubyVM::YJIT.enabled?
yjit_stats = RubyVM::YJIT.runtime_stats
if yjit_stats
yjit_bench_results["yjit_stats"] = yjit_stats

formatted_stats = proc { |key| "%10s" % yjit_stats[key].to_s.reverse.scan(/\d{1,3}/).join(",").reverse }
Expand Down
2 changes: 2 additions & 0 deletions harness/harness.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ def run_benchmark(_num_itrs_hint, &block)
num_itrs = 0
header = "itr: time"

RubyVM::YJIT.reset_stats! if defined?(RubyVM::YJIT) && RubyVM::YJIT.enabled?

# If $YJIT_BENCH_STATS is given, print the diff of these stats at each iteration.
if ENV["YJIT_BENCH_STATS"]
yjit_stats = ENV["YJIT_BENCH_STATS"].split(",").map { |key| [key.to_sym, nil] }.to_h
Expand Down

0 comments on commit 6d9c1d8

Please sign in to comment.