Class: BenchmarkDriver::Output::Charty

Inherits:
BulkOutput
  • Object
show all
Defined in:
lib/benchmark_driver/output/charty.rb

Constant Summary collapse

GRAPH_PATH =
'charty.png'
OPTIONS =
{
  chart: ['--output-chart CHART', Regexp.union(['bar', 'box']), 'Specify chart type: bar, box (default: bar)'],
  path: ['--output-path PATH', String, "Chart output path (default: #{GRAPH_PATH})"]
}

Instance Method Summary collapse

Constructor Details

#initialize(contexts:, options:) ⇒ Charty

Returns a new instance of Charty.

Parameters:

  • metrics (Array<BenchmarkDriver::Metric>)
  • jobs (Array<BenchmarkDriver::Job>)
  • contexts (Array<BenchmarkDriver::Context>)


15
16
17
18
19
20
# File 'lib/benchmark_driver/output/charty.rb', line 15

def initialize(contexts:, options:, **)
  super
  @contexts = contexts
  @chart = options.fetch(:chart, 'bar')
  @path = options.fetch(:path, GRAPH_PATH)
end

Instance Method Details

#bulk_output(job_context_result:, metrics:) ⇒ Object

Parameters:

  • result (Hash{ BenchmarkDriver::Job => Hash{ BenchmarkDriver::Context => { BenchmarkDriver::Metric => Float } } })
  • metrics (Array<BenchmarkDriver::Metric>)


24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/benchmark_driver/output/charty.rb', line 24

def bulk_output(job_context_result:, metrics:)
  print "rendering graph..."
  charty = Charty::Plotter.new(:pyplot)

  metric = metrics.first # only one metric is supported for now
  if job_context_result.keys.size == 1
    job = job_context_result.keys.first

    names = job_context_result[job].keys.map(&:name)
    case @chart
    when 'bar'
      values = job_context_result[job].values.map { |result| result.values.fetch(metric) }
      chart = charty.barh do
        series names, values
        ylabel metric.unit
      end
    when 'box'
      values = job_context_result[job].values.map { |result| result.all_values.fetch(metric) }
      chart = charty.box_plot do
        labels names
        data values
        ylabel metric.unit
      end
    else
      raise ArgumentError, "unexpected --output-chart: #{@chart}"
    end
  else
    jobs = job_context_result.keys

    case @chart
    when 'bar'
      values = @contexts.map{|context|
        [
          jobs.map{|job| "#{job.name}(#{context.name})" },
          jobs.map{|job| job_context_result[job][context].values.fetch(metric).round }
        ]
      }
      chart = charty.barh do
        values.each do |value|
          series *value
        end
        ylabel metric.unit
      end
    when 'box'
      raise NotImplementedError, "--output-chart=box is not supported with multiple jobs"
    else
      raise ArgumentError, "unexpected --output-chart: #{@chart}"
    end
  end
  chart.save(@path)
  puts ": #{@path}"
end

#with_context(context, &block) ⇒ Object



82
83
84
85
# File 'lib/benchmark_driver/output/charty.rb', line 82

def with_context(context, &block)
  puts "  * #{context.name}..."
  super
end

#with_job(job, &block) ⇒ Object



77
78
79
80
# File 'lib/benchmark_driver/output/charty.rb', line 77

def with_job(job, &block)
  puts "* #{job.name}..."
  super
end