Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 16 additions & 4 deletions harness/harness-common.rb
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,9 @@ def get_maxrss
raise unless result.zero?
maxrss_kb = buffer[offset, Fiddle::SIZEOF_LONG].unpack1('q')
1024 * maxrss_kb
rescue LoadError
warn "Failed to get max RSS: #{$!.message}"
nil
end

# Do expand_path at require-time, not when returning results, before the benchmark is likely to chdir
Expand All @@ -87,22 +90,31 @@ def return_results(warmup_iterations, bench_iterations)

# Collect our own peak mem usage as soon as reasonable after finishing the last iteration.
rss = get_rss
maxrss = get_maxrss
puts "RSS: %.1fMiB" % (rss / 1024.0 / 1024.0)
puts "MAXRSS: %.1fMiB" % (maxrss / 1024.0 / 1024.0)
yjit_bench_results["rss"] = rss
yjit_bench_results["maxrss"] = maxrss
puts "RSS: %.1fMiB" % (rss / 1024.0 / 1024.0)

if maxrss = get_maxrss
puts "MAXRSS: %.1fMiB" % (maxrss / 1024.0 / 1024.0)
yjit_bench_results["maxrss"] = maxrss
end

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

write_json_file(yjit_bench_results)
end

def write_json_file(yjit_bench_results)
require "json"

out_path = YB_OUTPUT_FILE
system('mkdir', '-p', File.dirname(out_path))

# Using default path? Print where we put it.
puts "Writing file #{out_path}" unless ENV["RESULT_JSON_PATH"]

File.write(out_path, JSON.pretty_generate(yjit_bench_results))
rescue LoadError
warn "Failed to write JSON file: #{$!.message}"
end
19 changes: 16 additions & 3 deletions harness/harness.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
require 'benchmark'
require_relative "./harness-common"

# Warmup iterations
Expand All @@ -19,14 +18,28 @@

puts RUBY_DESCRIPTION

if defined?(Process.clock_gettime) && defined?(Process::CLOCK_MONOTONIC)
def realtime
r0 = Process.clock_gettime(Process::CLOCK_MONOTONIC)
yield
Process.clock_gettime(Process::CLOCK_MONOTONIC) - r0
end
else
require "benchmark"

def realtime(&block)
Benchmark.realtime(&block)
end
end

# Takes a block as input
def run_benchmark(_num_itrs_hint)
def run_benchmark(_num_itrs_hint, &block)
times = []
total_time = 0
num_itrs = 0

begin
time = Benchmark.realtime { yield }
time = realtime(&block)
num_itrs += 1

# NOTE: we may want to avoid this as it could trigger GC?
Expand Down