Class: Statue::Stopwatch
- Inherits:
-
Object
- Object
- Statue::Stopwatch
- Defined in:
- lib/statue/stopwatch.rb
Instance Method Summary collapse
-
#initialize(name:, now: Clock.now_in_ms, reporter: Statue) ⇒ Stopwatch
constructor
A new instance of Stopwatch.
- #partial(suffix = nil, now: Clock.now_in_ms, **options) ⇒ Object
- #reset(now: Clock.now_in_ms) ⇒ Object
- #stop(suffix = nil, now: Clock.now_in_ms, report_partial: false, **options) ⇒ Object
Constructor Details
Instance Method Details
#partial(suffix = nil, now: Clock.now_in_ms, **options) ⇒ Object
10 11 12 13 14 |
# File 'lib/statue/stopwatch.rb', line 10 def partial(suffix = nil, now: Clock.now_in_ms, **) previous, @partial = @partial, now @reporter.report_duration(metric_name(suffix || "runtime.partial"), @partial - previous, **) end |
#reset(now: Clock.now_in_ms) ⇒ Object
24 25 26 |
# File 'lib/statue/stopwatch.rb', line 24 def reset(now: Clock.now_in_ms) @start = @partial = now end |
#stop(suffix = nil, now: Clock.now_in_ms, report_partial: false, **options) ⇒ Object
16 17 18 19 20 21 22 |
# File 'lib/statue/stopwatch.rb', line 16 def stop(suffix = nil, now: Clock.now_in_ms, report_partial: false, **) partial(report_partial.is_a?(String) ? report_partial : nil, now: now, **) if report_partial previous, @start = @start, now @reporter.report_duration(metric_name(suffix || "runtime.total"), @start - previous, **) end |