Sha256: ef77d9a999df7d7687c17397ab14c5735ecc872113fc8f5b4ae8018f6219dc62

Contents?: true

Size: 1.59 KB

Versions: 21

Compression:

Stored size: 1.59 KB

Contents

# encoding: utf-8
# This file is distributed under New Relic's license terms.
# See https://github.com/newrelic/rpm/blob/master/LICENSE for complete details.

# 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 NewRelic
  module Agent
    class TransactionMetrics
      DEFAULT_PROC = Proc.new { |hash, name| hash[name] = NewRelic::Agent::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
end

Version data entries

21 entries across 21 versions & 1 rubygems

Version Path
newrelic_rpm-3.14.1.311 lib/new_relic/agent/transaction_metrics.rb
newrelic_rpm-3.14.0.305 lib/new_relic/agent/transaction_metrics.rb
newrelic_rpm-3.13.2.302 lib/new_relic/agent/transaction_metrics.rb
newrelic_rpm-3.13.1.300 lib/new_relic/agent/transaction_metrics.rb
newrelic_rpm-3.13.0.299 lib/new_relic/agent/transaction_metrics.rb
newrelic_rpm-3.12.1.298 lib/new_relic/agent/transaction_metrics.rb
newrelic_rpm-3.12.0.288 lib/new_relic/agent/transaction_metrics.rb
newrelic_rpm-3.11.2.286 lib/new_relic/agent/transaction_metrics.rb
newrelic_rpm-3.11.1.284 lib/new_relic/agent/transaction_metrics.rb
newrelic_rpm-3.11.0.283 lib/new_relic/agent/transaction_metrics.rb
newrelic_rpm-3.10.0.279 lib/new_relic/agent/transaction_metrics.rb
newrelic_rpm-3.9.9.275 lib/new_relic/agent/transaction_metrics.rb
newrelic_rpm-3.9.8.273 lib/new_relic/agent/transaction_metrics.rb
newrelic_rpm-3.9.7.266 lib/new_relic/agent/transaction_metrics.rb
newrelic_rpm-3.9.6.257 lib/new_relic/agent/transaction_metrics.rb
newrelic_rpm-3.9.5.251 lib/new_relic/agent/transaction_metrics.rb
newrelic_rpm-3.9.4.245 lib/new_relic/agent/transaction_metrics.rb
newrelic_rpm-3.9.3.241 lib/new_relic/agent/transaction_metrics.rb
newrelic_rpm-3.9.2.239 lib/new_relic/agent/transaction_metrics.rb
newrelic_rpm-3.9.1.236 lib/new_relic/agent/transaction_metrics.rb