Class: BenchmarkDriver::Runner::CommandStdout

Inherits:
Object
  • Object
show all
Defined in:
lib/benchmark_driver/runner/command_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]
  :stdout_to_metrics, # @param [String]
)

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of CommandStdout.

Parameters:



51
52
53
54
55
# File 'lib/benchmark_driver/runner/command_stdout.rb', line 51

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


59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# 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