class BenchmarkDriver::Runner::CommandStdout
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/command_stdout.rb, line 51 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/command_stdout.rb, line 59 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 result = BenchmarkDriver::Repeater.with_repeat(config: @config, larger_better: metric.larger_better) do stdout = with_chdir(job.working_directory) do with_ruby_prefix(exec) { execute(*exec.command, *job.command) } end StdoutToMetrics.new( stdout: stdout, stdout_to_metrics: job.stdout_to_metrics, ).metrics_value end @output.with_context(name: exec.name, executable: exec) do @output.report(values: { metric => result.value }, all_values: { metric => result.all_values }) end end end end end end
Private Instance Methods
execute(*args)
click to toggle source
# File lib/benchmark_driver/runner/command_stdout.rb, line 104 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/command_stdout.rb, line 96 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/command_stdout.rb, line 88 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