Module: Simple::Metrics::Timer

Included in:
Simple::Metrics
Defined in:
lib/simple/metrics/timer.rb

Instance Method Summary collapse

Instance Method Details

#timer(name) ⇒ Object

Create creates a new timer, registers it with the metrics registry, yields the timer to the block and stops it when the block returns.

Parameters:

  • name (String)

    The name of the timer.



8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/simple/metrics/timer.rb', line 8

def timer(name)
  metric_name = new_metric_name(sanitize_classname(self.class.name), name, "timer")
  new_timer = metrics_registry.newTimer(metric_name,
                                        DEFAULT_DURATION_UNIT,
                                        DEFAULT_RATE_UNIT)
  captured_timer = new_timer.time
  begin
    yield new_timer
  ensure
    captured_timer.stop
  end
end