Sha256: 1103e5460cd6a09ca88fa6593e67cf14e57e4c53b8249abb2e37bacd65ede6b7

Contents?: true

Size: 937 Bytes

Versions: 1

Compression:

Stored size: 937 Bytes

Contents

module Simple
  module Metrics
    module Timer
      # Create creates a new timer, registers it with the metrics registry,
      # yields the timer to the block and stops it when the block returns.
      #
      # @param [String] name The name of the timer
      # @param [String] klass_name The name of the class, usually the application. Defaults to
      # `self.class.name`
      # @param [TimeUnit] time_unit The rate at which to measure timed data. Defaults to
      # TimeUnit::SECONDS
      def timer(name, klass_name = self.class.name, 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, DEFAULT_DURATION_UNIT, time_unit)
        captured_timer = new_timer.time
        begin
          yield new_timer
        ensure
          captured_timer.stop
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
kb-simple-metrics-0.0.12-java lib/simple/metrics/timer.rb