Sha256: 0b2d9715a93e843681f38f6de060b6adebf28cb2787608c1ba2dd9badf9ea302

Contents?: true

Size: 1.36 KB

Versions: 42

Compression:

Stored size: 1.36 KB

Contents

# encoding: utf-8

# This class represents a set of metrics that were recorded during a single
# transaction. Since the name of the transaction is not known until its end, we
# don't save explicit scopes with these metrics, we just keep separate
# collections of scoped and unscoped metrics.

module OneApm
  class TransactionMetrics
    DEFAULT_PROC = Proc.new { |hash, name| hash[name] = OneApm::Metrics::Stats.new }

    def initialize
      @unscoped = Hash.new(&DEFAULT_PROC)
      @scoped   = Hash.new(&DEFAULT_PROC)
    end

    def record_scoped(names, value=nil, aux=nil, &blk)
      _record_metrics(names, value, aux, @scoped, &blk)
    end

    def record_unscoped(names, value=nil, aux=nil, &blk)
      _record_metrics(names, value, aux, @unscoped, &blk)
    end

    def has_key?(key)
      @unscoped.has_key?(key)
    end

    def [](key)
      @unscoped[key]
    end

    def each_unscoped
      @unscoped.each { |name, stats| yield name, stats }
    end

    def each_scoped
      @scoped.each { |name, stats| yield name, stats }
    end

    def _record_metrics(names, value, aux, target, &blk)
      # This looks dumb, but we're avoiding an extra Array allocation.
      case names
      when Array
        names.each do |name|
          target[name].record(value, aux, &blk)
        end
      else
        target[names].record(value, aux, &blk)
      end
    end
  end
end

Version data entries

42 entries across 42 versions & 1 rubygems

Version Path
oneapm_rpm-1.4.2 lib/one_apm/transaction/transaction_metrics.rb
oneapm_rpm-1.4.1 lib/one_apm/transaction/transaction_metrics.rb
oneapm_rpm-1.4.0 lib/one_apm/transaction/transaction_metrics.rb
oneapm_rpm-1.3.7 lib/one_apm/transaction/transaction_metrics.rb
oneapm_rpm-1.3.7.rc1 lib/one_apm/transaction/transaction_metrics.rb
oneapm_rpm-1.3.6 lib/one_apm/transaction/transaction_metrics.rb
oneapm_rpm-1.3.6.rc1 lib/one_apm/transaction/transaction_metrics.rb
oneapm_rpm-1.3.5 lib/one_apm/transaction/transaction_metrics.rb
oneapm_rpm-1.3.5.rc1 lib/one_apm/transaction/transaction_metrics.rb
oneapm_rpm-1.3.4 lib/one_apm/transaction/transaction_metrics.rb
oneapm_rpm-1.3.4.rc1 lib/one_apm/transaction/transaction_metrics.rb
oneapm_rpm-1.3.3 lib/one_apm/transaction/transaction_metrics.rb
oneapm_rpm-1.3.3.rc1 lib/one_apm/transaction/transaction_metrics.rb
oneapm_rpm-1.3.2 lib/one_apm/transaction/transaction_metrics.rb
oneapm_rpm-1.3.2.rc1 lib/one_apm/transaction/transaction_metrics.rb
oneapm_rpm-1.3.1 lib/one_apm/transaction/transaction_metrics.rb
oneapm_rpm-1.3.1.rc1 lib/one_apm/transaction/transaction_metrics.rb
oneapm_rpm-1.3.0 lib/one_apm/transaction/transaction_metrics.rb
oneapm_rpm-1.3.0.rc1 lib/one_apm/transaction/transaction_metrics.rb
oneapm_rpm-1.2.9 lib/one_apm/transaction/transaction_metrics.rb