Class: BenchmarkDriver::BulkOutput
- Inherits:
-
Object
- Object
- BenchmarkDriver::BulkOutput
- Defined in:
- lib/benchmark_driver/bulk_output.rb
Overview
This is API for your casual output plugin and NOT internally used by BenchmarkDriver.
By fully utilizing with_*/report APIs, you can implement streaming-output plugins. See also: lib/benchmark_driver/output.rb (this class’s instance will be ‘@output`) But using these APIs can be difficult because the API is not stable yet and it’s hard to deal with the complex state machine.
If you don’t need to output results in a streaming manner, you can create an output plugin class that inherits ‘BenchmarkDriver::BulkOutput`, which requires to override only `#bulk_output` that takes all inputs at once.
Instance Method Summary collapse
-
#bulk_output(job_context_result:, metrics:) ⇒ Object
The main API you need to override if you make a class inherit ‘BenchmarkDriver::BulkOutput`.
-
#initialize(metrics:, jobs:, contexts:, options: {}) ⇒ BulkOutput
constructor
A new instance of BulkOutput.
- #report(result) ⇒ Object
- #with_benchmark(&block) ⇒ Object
- #with_context(context, &block) ⇒ Object
- #with_job(job, &block) ⇒ Object
- #with_warmup(&block) ⇒ Object
Constructor Details
#initialize(metrics:, jobs:, contexts:, options: {}) ⇒ BulkOutput
Returns a new instance of BulkOutput.
17 18 19 |
# File 'lib/benchmark_driver/bulk_output.rb', line 17 def initialize(metrics:, jobs:, contexts:, options: {}) @metrics = metrics end |
Instance Method Details
#bulk_output(job_context_result:, metrics:) ⇒ Object
The main API you need to override if you make a class inherit ‘BenchmarkDriver::BulkOutput`.
24 25 26 |
# File 'lib/benchmark_driver/bulk_output.rb', line 24 def bulk_output(job_context_result:, metrics:) raise NotImplementedError.new("#{self.class} must override #bulk_output") end |
#report(result) ⇒ Object
54 55 56 57 58 |
# File 'lib/benchmark_driver/bulk_output.rb', line 54 def report(result) if defined?(@job_context_result) @job_context_result[@job][@context] = result end end |
#with_benchmark(&block) ⇒ Object
32 33 34 35 36 37 38 39 |
# File 'lib/benchmark_driver/bulk_output.rb', line 32 def with_benchmark(&block) @job_context_result = Hash.new do |hash, job| hash[job] = {} end result = block.call bulk_output(job_context_result: @job_context_result, metrics: @metrics) result end |
#with_context(context, &block) ⇒ Object
48 49 50 51 |
# File 'lib/benchmark_driver/bulk_output.rb', line 48 def with_context(context, &block) @context = context block.call end |
#with_job(job, &block) ⇒ Object
42 43 44 45 |
# File 'lib/benchmark_driver/bulk_output.rb', line 42 def with_job(job, &block) @job = job block.call end |
#with_warmup(&block) ⇒ Object
28 29 30 |
# File 'lib/benchmark_driver/bulk_output.rb', line 28 def with_warmup(&block) block.call # noop end |