Module: Simple::Metrics::Timer
- Included in:
- Simple::Metrics
- Defined in:
- lib/simple/metrics/timer.rb
Instance Method Summary collapse
-
#timer(name, options = {}) ⇒ 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.
Instance Method Details
#timer(name, options = {}) ⇒ 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.
‘{}`
10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/simple/metrics/timer.rb', line 10 def timer(name, ={}) klass_name = [:name] || self.class.name duration_unit = [:duration_unit] || Simple::Metrics::DEFAULT_DURATION_UNIT time_unit = [:time_unit] || Simple::Metrics::DEFAULT_RATE_UNIT metric_name = new_metric_name(sanitize_classname(klass_name), name, 'timer') new_timer = metrics_registry.newTimer(metric_name, duration_unit, time_unit) captured_timer = new_timer.time begin yield new_timer ensure captured_timer.stop end end |