lib/benchmark_driver/runner/ips.rb in benchmark_driver-0.15.12 vs lib/benchmark_driver/runner/ips.rb in benchmark_driver-0.15.13
- old
+ new
@@ -105,12 +105,12 @@
loop_count: job.loop_count,
)
duration = Tempfile.open(['benchmark_driver-', '.rb']) do |f|
with_script(benchmark.render(result: f.path)) do |path|
- IO.popen([*context.executable.command, path], &:read) # TODO: print stdout if verbose=2
- if $?.success? && ((value = Float(f.read)) > 0)
+ success = execute(*context.executable.command, path, exception: false)
+ if success && ((value = Float(f.read)) > 0)
value
else
BenchmarkDriver::Result::ERROR
end
end
@@ -135,26 +135,32 @@
[loop_count.to_f / duration, duration]
end
end
def with_script(script)
- if @config.verbose >= 2
- sep = '-' * 30
- $stdout.puts "\n\n#{sep}[Script begin]#{sep}\n#{script}#{sep}[Script end]#{sep}\n\n"
- end
+ debug_output('Script', script) if @config.verbose >= 2
Tempfile.open(['benchmark_driver-', '.rb']) do |f|
f.puts script
f.close
return yield(f.path)
end
end
- def execute(*args)
- IO.popen(args, &:read) # TODO: print stdout if verbose=2
- unless $?.success?
- raise "Failed to execute: #{args.shelljoin} (status: #{$?.exitstatus})"
+ def execute(*args, exception: true)
+ $stderr.puts "$ #{args.shelljoin}" if @config.verbose >= 2
+
+ stdout = IO.popen(args, &:read)
+ debug_output('Command output', stdout) if @config.verbose >= 2
+ if exception && !$?.success?
+ raise "Failed to execute: #{args.shelljoin} (status: #{$?})"
end
+ $?.success?
+ end
+
+ def debug_output(name, text)
+ sep = '-' * 30
+ $stdout.puts "\n\n#{sep}[#{name} begin]#{sep}\n#{text}#{sep}[#{name} end]#{sep}\n\n"
end
WarmupScript = ::BenchmarkDriver::Struct.new(:preludes, :script, :teardown, :loop_count, :first_warmup_duration, :second_warmup_duration) do
# @param [String] result - A file to write result
def render(result:)