Skip to content

Commit 84ace78

Browse files
luke-grubereightbitraptor
authored andcommitted
Implement the ability to use multiple harnesses
This commit introduces a harness that can be used to chain two (or more) harnesses together. For example. To run a Ractor test with Vernier you can wrap the ractor harness with the vernier one as follows HARNESS_CHAIN="vernier,ractor" ruby -Iharness-chain benchmarks-ractor/optcarrot/benchmark.rb
1 parent 076a4e2 commit 84ace78

File tree

1 file changed

+52
-0
lines changed

1 file changed

+52
-0
lines changed

harness-chain/harness.rb

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
require_relative '../harness/harness-common'
2+
3+
# Ex: HARNESS_CHAIN="vernier,ractor"
4+
# Wraps the ractor harness in ther vernier harness
5+
CHAIN = ENV['HARNESS_CHAIN'].to_s.split(',')
6+
CHAIN.reject! { |el| el.to_s.strip.empty? }
7+
if CHAIN.size < 2
8+
$stderr.puts "You need to chain at least 2 harnesses. Exiting."
9+
exit 1
10+
end
11+
12+
if CHAIN.include?("vernier") && CHAIN.last != "vernier"
13+
require_relative "../harness/harness-extra"
14+
def run_enough_to_profile(n, **kwargs, &block)
15+
block.call
16+
end
17+
end
18+
19+
$current_harness = nil
20+
$benchmark_methods = []
21+
22+
class Object
23+
def self.method_added(name)
24+
if name == :run_benchmark && $current_harness
25+
$benchmark_methods << [$current_harness, Object.instance_method(name)]
26+
end
27+
end
28+
end
29+
30+
def run_benchmark(n, **kwargs, &block)
31+
CHAIN.each do |h|
32+
begin
33+
path = "../harness-#{h}/harness"
34+
$current_harness = h
35+
require_relative path
36+
rescue LoadError => e
37+
if e.path == path
38+
$stderr.puts "Can't find harness harness-#{h}/harness.rb. Exiting."
39+
exit 1
40+
end
41+
raise
42+
end
43+
end
44+
procs = [block]
45+
$benchmark_methods.reverse_each do |harness_name, harness_method|
46+
prok = procs.pop
47+
procs << proc { harness_method.bind(self).call(n, **kwargs, &prok) }
48+
end
49+
raise "Bad logic: #{procs.size}" unless procs.size == 1
50+
result = procs.last.call
51+
result || return_results([0], [1.0])
52+
end

0 commit comments

Comments
 (0)