class Statue::Stopwatch
Public Class Methods
new(name:, now: Clock.now_in_ms, reporter: Statue)
click to toggle source
# File lib/statue/stopwatch.rb, line 4 def initialize(name:, now: Clock.now_in_ms, reporter: Statue) @reporter = reporter @name = name @start = @partial = now end
Public Instance Methods
partial(suffix = nil, now: Clock.now_in_ms, **options)
click to toggle source
# File lib/statue/stopwatch.rb, line 10 def partial(suffix = nil, now: Clock.now_in_ms, **options) previous, @partial = @partial, now @reporter.report_duration(metric_name(suffix || "runtime.partial"), @partial - previous, **options) end
reset(now: Clock.now_in_ms)
click to toggle source
# 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)
click to toggle source
# File lib/statue/stopwatch.rb, line 16 def stop(suffix = nil, now: Clock.now_in_ms, report_partial: false, **options) partial(report_partial.is_a?(String) ? report_partial : nil, now: now, **options) if report_partial previous, @start = @start, now @reporter.report_duration(metric_name(suffix || "runtime.total"), @start - previous, **options) end
Private Instance Methods
metric_name(suffix)
click to toggle source
# File lib/statue/stopwatch.rb, line 30 def metric_name(suffix) "#{@name}.#{suffix}" end