Sha256: c84403bc180eb305969ef2d6e0af9a7316c67e22896ce6d603998d5469295739

Contents?: true

Size: 1.01 KB

Versions: 4

Compression:

Stored size: 1.01 KB

Contents

module HeimdallApm
  # Stats associated with a single metric (used in metrics Hashs as value where
  # keys are the metrics names)
  #
  class MetricStats
    attr_accessor :call_count
    attr_accessor :total_call_time
    attr_accessor :total_exclusive_time
    attr_accessor :min_call_time
    attr_accessor :max_call_time

    # If this metric is scoped inside another, use exclusive time for min/max.
    # Non-scoped metrics (like Controller) track the total call time.
    def initialize(scoped: false)
      @scoped = scoped
      @call_count = 0
      @total_call_time = 0.0
      @total_exclusive_time = 0.0
      @min_call_time = 0.0
      @max_call_time = 0.0
    end

    def update(call_time, exclusive_time = nil)
      self.call_count += 1
      self.total_call_time += call_time
      self.total_exclusive_time += exclusive_time

      t = @scoped ? exclusive_time : call_time
      self.min_call_time = t if call_count == 0 || t < min_call_time
      self.max_call_time = t if t > max_call_time
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
heimdall_apm-0.1.3 lib/heimdall_apm/metric_stats.rb
heimdall_apm-0.1.2 lib/heimdall_apm/metric_stats.rb
heimdall_apm-0.1.1 lib/heimdall_apm/metric_stats.rb
heimdall_apm-0.1.0 lib/heimdall_apm/metric_stats.rb