lib/benchmark_driver/runner/memory.rb in benchmark_driver-0.13.3 vs lib/benchmark_driver/runner/memory.rb in benchmark_driver-0.14.0

- old
+ new

@@ -66,18 +66,22 @@ script: job.script, teardown: job.teardown, loop_count: job.loop_count, ) - output = with_script(benchmark.render) do |path| - execute('/usr/bin/time', *context.executable.command, path) - end + with_script(benchmark.render) do |path| + output = IO.popen(['/usr/bin/time', *context.executable.command, path], err: [:child, :out], &:read) + if $?.success? + match_data = /^(?<user>\d+.\d+)user\s+(?<system>\d+.\d+)system\s+(?<elapsed1>\d+):(?<elapsed2>\d+.\d+)elapsed.+\([^\s]+\s+(?<maxresident>\d+)maxresident\)k$/.match(output) + raise "Unexpected format given from /usr/bin/time:\n#{out}" unless match_data[:maxresident] - match_data = /^(?<user>\d+.\d+)user\s+(?<system>\d+.\d+)system\s+(?<elapsed1>\d+):(?<elapsed2>\d+.\d+)elapsed.+\([^\s]+\s+(?<maxresident>\d+)maxresident\)k$/.match(output) - raise "Unexpected format given from /usr/bin/time:\n#{out}" unless match_data[:maxresident] - - Integer(match_data[:maxresident]) * 1000.0 # kilobytes -> bytes + Integer(match_data[:maxresident]) * 1000.0 # kilobytes -> bytes + else + $stdout.print(output) + BenchmarkDriver::Result::ERROR + end + end end def with_script(script) if @config.verbose >= 2 sep = '-' * 30 @@ -87,17 +91,9 @@ Tempfile.open(['benchmark_driver-', '.rb']) do |f| f.puts script f.close return yield(f.path) end - end - - def execute(*args) - output = IO.popen(args, err: [:child, :out], &:read) # handle stdout? - unless $?.success? - raise "Failed to execute: #{args.shelljoin} (status: #{$?.exitstatus})" - end - output end # @param [String] prelude # @param [String] script # @param [String] teardown