Class: Wip::DebugReporter
- Inherits:
-
Object
- Object
- Wip::DebugReporter
- Defined in:
- lib/wip/debug_reporter.rb
Overview
Prints each step wip takes and how long it took, when debug mode is enabled.
Instance Method Summary collapse
-
#initialize(enabled:, out: $stderr) ⇒ DebugReporter
constructor
A new instance of DebugReporter.
- #step(label) ⇒ Object
Constructor Details
#initialize(enabled:, out: $stderr) ⇒ DebugReporter
Returns a new instance of DebugReporter.
6 7 8 9 |
# File 'lib/wip/debug_reporter.rb', line 6 def initialize(enabled:, out: $stderr) @enabled = enabled @out = out end |
Instance Method Details
#step(label) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/wip/debug_reporter.rb', line 11 def step(label) return yield unless @enabled started = Process.clock_gettime(Process::CLOCK_MONOTONIC) @out.puts "wip: [debug] #{label}" monitor = ResourceMonitor.new(out: @out) monitor.start(label) begin yield ensure monitor.stop elapsed = Process.clock_gettime(Process::CLOCK_MONOTONIC) - started @out.puts format('wip: [debug] done in %<elapsed>.2fs: %<label>s', elapsed: elapsed, label: label) end end |