Skip to content

Commit 9712669

Browse files
committed
Limit YJIT stats to the measured benchmark code
Reset stats at the beginning of the benchmark and collect stats before loading any additional code.
1 parent cbe285e commit 9712669

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

harness/harness-common.rb

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,15 +101,17 @@ def return_results(warmup_iterations, bench_iterations)
101101
"bench" => bench_iterations,
102102
}
103103

104+
# Collect yjit stats before loading any additional code.
105+
yjit_stats = RubyVM::YJIT.runtime_stats if defined?(RubyVM::YJIT) && RubyVM::YJIT.enabled?
106+
104107
# Collect our own peak mem usage as soon as reasonable after finishing the last iteration.
105108
rss = get_rss
106109
yjit_bench_results["rss"] = rss
107110
if maxrss = get_maxrss
108111
yjit_bench_results["maxrss"] = maxrss
109112
end
110113

111-
if defined?(RubyVM::YJIT) && RubyVM::YJIT.enabled?
112-
yjit_stats = RubyVM::YJIT.runtime_stats
114+
if yjit_stats
113115
yjit_bench_results["yjit_stats"] = yjit_stats
114116

115117
formatted_stats = proc { |key| "%10s" % yjit_stats[key].to_s.reverse.scan(/\d{1,3}/).join(",").reverse }

harness/harness.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ def run_benchmark(_num_itrs_hint, &block)
3838
num_itrs = 0
3939
header = "itr: time"
4040

41+
RubyVM::YJIT.reset_stats! if defined?(RubyVM::YJIT) && RubyVM::YJIT.enabled?
42+
4143
# If $YJIT_BENCH_STATS is given, print the diff of these stats at each iteration.
4244
if ENV["YJIT_BENCH_STATS"]
4345
yjit_stats = ENV["YJIT_BENCH_STATS"].split(",").map { |key| [key.to_sym, nil] }.to_h

0 commit comments

Comments
 (0)