Class: BenchmarkDriver::Runner::RubyStdout

Inherits:
Object
  • Object
show all
Defined in:
lib/benchmark_driver/runner/ruby_stdout.rb

Overview

Use stdout of ruby command

Defined Under Namespace

Classes: JobParser=Module.new

Constant Summary collapse

CommandFailure =
Class.new(StandardError)
Job =

JobParser returns this, ‘BenchmarkDriver::Runner.runner_for` searches “*::Job”

::BenchmarkDriver::Struct.new(
  :name,                   # @param [String] name - This is mandatory for all runner
  :metrics,                # @param [Array<BenchmarkDriver::Metric>]
  :command,                # @param [Array<String>]
  :working_directory,      # @param [String,NilClass]
  :value_from_stdout,      # @param [String]
  :environment_from_stdout # @param [Hash{ String => String }]
)

Instance Method Summary collapse

Constructor Details

#initialize(config:, output:, contexts:) ⇒ RubyStdout

Returns a new instance of RubyStdout.

Parameters:



71
72
73
74
75
# File 'lib/benchmark_driver/runner/ruby_stdout.rb', line 71

def initialize(config:, output:, contexts:)
  @config = config
  @output = output
  @contexts = contexts
end

Instance Method Details

#run(jobs) ⇒ Object

This method is dynamically called by ‘BenchmarkDriver::JobRunner.run`

Parameters:

  • jobs (Array<BenchmarkDriver::Default::Job>)


79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
# File 'lib/benchmark_driver/runner/ruby_stdout.rb', line 79

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 }
          result = BenchmarkDriver::Repeater.with_repeat(**repeat_params) do
            begin
              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]
            rescue CommandFailure => e
              $stderr.puts("\n```\n#{e.message}```\n")
              [BenchmarkDriver::Result::ERROR, {}]
            end
          end
          value, environment = result.value

          @output.with_context(name: exec.name, executable: exec) do
            @output.report(
              values: { metric => value },
              all_values: { metric => result.all_values },
              environment: environment,
            )
          end
        end
      end
    end
  end
end