class BenchmarkDriver::Runner::RubyStdout
Use stdout of ruby command
Constants
- Job
JobParser
returns this, `BenchmarkDriver::Runner.runner_for` searches “*::Job”- StdoutToMetrics
Public Class Methods
new(config:, output:, contexts:)
click to toggle source
@param [BenchmarkDriver::Config::RunnerConfig] config @param [BenchmarkDriver::Output] output @param [BenchmarkDriver::Context] contexts
# File lib/benchmark_driver/runner/ruby_stdout.rb, line 68 def initialize(config:, output:, contexts:) @config = config @output = output @contexts = contexts end
Public Instance Methods
run(jobs)
click to toggle source
This method is dynamically called by `BenchmarkDriver::JobRunner.run` @param [Array<BenchmarkDriver::Default::Job>] jobs
# File lib/benchmark_driver/runner/ruby_stdout.rb, line 76 def run(jobs) metric = jobs.first.metrics.first @output.with_benchmark do jobs.each do |job| @output.with_job(name: job.name) do @contexts.each do |context| exec = context.executable repeat_params = { config: @config, larger_better: metric.larger_better } value, environment = BenchmarkDriver::Repeater.with_repeat(repeat_params) do stdout = with_chdir(job.working_directory) do with_ruby_prefix(exec) { execute(*exec.command, *job.command) } end script = StdoutToMetrics.new( stdout: stdout, value_from_stdout: job.value_from_stdout, environment_from_stdout: job.environment_from_stdout, ) [script.value, script.environment] end @output.with_context(name: exec.name, executable: exec) do @output.report(values: { metric => value }, environment: environment) end end end end end end
Private Instance Methods
execute(*args)
click to toggle source
# File lib/benchmark_driver/runner/ruby_stdout.rb, line 124 def execute(*args) stdout, stderr, status = Open3.capture3(*args) unless status.success? raise "Failed to execute: #{args.shelljoin} (status: #{$?.exitstatus}):\n[stdout]:\n#{stdout}\n[stderr]:\n#{stderr}" end stdout end
with_chdir(working_directory, &block)
click to toggle source
# File lib/benchmark_driver/runner/ruby_stdout.rb, line 116 def with_chdir(working_directory, &block) if working_directory Dir.chdir(working_directory) { block.call } else block.call end end
with_ruby_prefix(executable, &block)
click to toggle source
# File lib/benchmark_driver/runner/ruby_stdout.rb, line 108 def with_ruby_prefix(executable, &block) env = ENV.to_h.dup ENV['PATH'] = "#{File.dirname(executable.command.first)}:#{ENV['PATH']}" block.call ensure ENV.replace(env) end