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

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:



68
69
70
71
72
# File 'lib/benchmark_driver/runner/ruby_stdout.rb', line 68

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>)


76
77
78
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
# 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