Sha256: 38a7f7f9a613d747931681400941cc41a705ba6be755766e8778181a35eaf04f

Contents?: true

Size: 962 Bytes

Versions: 1

Compression:

Stored size: 962 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 [Hash] options A hash containing keys/value pairs to override defaults. Defaults to
      # `{}`
      def timer(name, options={})
        klass_name = options[:name] || self.class.name
        duration_unit = options[:duration_unit] || Simple::Metrics::DEFAULT_DURATION_UNIT
        time_unit = options[: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
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

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