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