Sha256: f67516dc0a29169eb8f361db084b31fb29fe9041836ced5121bd5d64d8195830

Contents?: true

Size: 1.23 KB

Versions: 12

Compression:

Stored size: 1.23 KB

Contents

# encoding: utf-8
require 'ting_yun/metrics/stats'

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

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
tingyun_rpm-1.3.1 lib/ting_yun/agent/transaction/transaction_metrics.rb
tingyun_rpm-1.3.0 lib/ting_yun/agent/transaction/transaction_metrics.rb
tingyun_rpm-1.2.0 lib/ting_yun/agent/transaction/transaction_metrics.rb
tingyun_rpm-1.1.4.2 lib/ting_yun/agent/transaction/transaction_metrics.rb
tingyun_rpm-1.1.4.1 lib/ting_yun/agent/transaction/transaction_metrics.rb
tingyun_rpm-1.1.4 lib/ting_yun/agent/transaction/transaction_metrics.rb
tingyun_rpm-1.1.3 lib/ting_yun/agent/transaction/transaction_metrics.rb
tingyun_rpm-1.1.2 lib/ting_yun/agent/transaction/transaction_metrics.rb
tingyun_rpm-1.1.1 lib/ting_yun/agent/transaction/transaction_metrics.rb
tingyun_rpm-1.1.0 lib/ting_yun/agent/transaction/transaction_metrics.rb
tingyun_rpm-1.0.7 lib/ting_yun/agent/transaction/transaction_metrics.rb
tingyun_rpm-1.0.6 lib/ting_yun/agent/transaction/transaction_metrics.rb