Skip to content

Commit aeca350

Browse files
authored
Port run_benchmarks.rb --yjit-stats=STATS for ZJIT (#398)
1 parent 1da02d7 commit aeca350

File tree

3 files changed

+21
-10
lines changed

3 files changed

+21
-10
lines changed

harness/harness-common.rb

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -138,8 +138,8 @@ def return_results(warmup_iterations, bench_iterations)
138138
yjit_bench_results["maxrss"] = maxrss
139139
end
140140

141-
# If YJIT or ZJIT is enabled, show some of their stats at the end.
142-
if yjit_stats
141+
# If YJIT or ZJIT is enabled, show some of its stats unless it does by itself.
142+
if yjit_stats && !RubyVM::YJIT.stats_enabled?
143143
yjit_bench_results["yjit_stats"] = yjit_stats
144144
stats_keys = [
145145
*ENV.fetch("YJIT_BENCH_STATS", "").split(",").map(&:to_sym),
@@ -150,9 +150,10 @@ def return_results(warmup_iterations, bench_iterations)
150150
:compile_time_ns,
151151
].uniq
152152
puts "YJIT stats:"
153-
elsif zjit_stats
153+
elsif zjit_stats && !RubyVM::ZJIT.stats_enabled?
154154
yjit_bench_results["zjit_stats"] = zjit_stats
155155
stats_keys = [
156+
*ENV.fetch("ZJIT_BENCH_STATS", "").split(",").map(&:to_sym),
156157
:compile_time_ns,
157158
:profile_time_ns,
158159
:gc_time_ns,

harness/harness.rb

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -40,16 +40,18 @@ def run_benchmark(_num_itrs_hint, &block)
4040

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

43-
# If $YJIT_BENCH_STATS is given, print the diff of these stats at each iteration.
44-
if ENV["YJIT_BENCH_STATS"]
45-
yjit_stats = ENV["YJIT_BENCH_STATS"].split(",").map { |key| [key.to_sym, nil] }.to_h
43+
# If $YJIT_BENCH_STATS or $ZJIT_BENCH_STATS is given, print the diff of these stats at each iteration.
44+
if yjit_stats = ENV["YJIT_BENCH_STATS"]
45+
yjit_stats = yjit_stats.split(",").map(&:to_sym).map { |key| [key, RubyVM::YJIT.runtime_stats(key)] }.to_h
4646
yjit_stats.each_key { |key| header << " #{key}" }
4747
end
48+
if zjit_stats = ENV["ZJIT_BENCH_STATS"]
49+
zjit_stats = zjit_stats.split(",").map(&:to_sym).map { |key| [key, RubyVM::ZJIT.stats(key)] }.to_h
50+
zjit_stats.each_key { |key| header << " #{key}" }
51+
end
4852

4953
puts header
5054
begin
51-
yjit_stats&.each_key { |key| yjit_stats[key] = RubyVM::YJIT.runtime_stats(key) }
52-
5355
time = realtime(&block)
5456
num_itrs += 1
5557

@@ -59,10 +61,14 @@ def run_benchmark(_num_itrs_hint, &block)
5961

6062
yjit_stats&.each do |key, old_value|
6163
new_value = RubyVM::YJIT.runtime_stats(key)
62-
diff = (new_value - old_value)
63-
itr_str << " %#{key.size}s" % format_number(diff)
64+
itr_str << " %#{key.size}s" % format_number(new_value - old_value)
6465
yjit_stats[key] = new_value
6566
end
67+
zjit_stats&.each do |key, old_value|
68+
new_value = RubyVM::ZJIT.stats(key)
69+
itr_str << " %#{key.size}s" % format_number(new_value - old_value)
70+
zjit_stats[key] = new_value
71+
end
6672

6773
puts itr_str
6874
# NOTE: we may want to preallocate an array and avoid append

run_benchmarks.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -396,6 +396,10 @@ def run_benchmarks(ruby:, ruby_description:, categories:, name_filters:, out_pat
396396
ENV["YJIT_BENCH_STATS"] = str
397397
end
398398

399+
opts.on("--zjit-stats=STATS", "print ZJIT stats at each iteration for the default harness") do |str|
400+
ENV["ZJIT_BENCH_STATS"] = str
401+
end
402+
399403
opts.on("--yjit_opts=OPT_STRING", "string of command-line options to run YJIT with (ignored if you use -e)") do |str|
400404
args.yjit_opts=str
401405
end

0 commit comments

Comments
 (0)