Sha256: b514e5a6fda866accdbeef2dfabaeeb05da98158bcfe73ebf13cda1f5a286732

Contents?: true

Size: 1.66 KB

Versions: 50

Compression:

Stored size: 1.66 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.

module NewRelic
  module TransactionAnalysis
    # summarizes performance data for all calls to segments
    # with the same metric_name
    class SegmentSummary
      attr_accessor :metric_name, :total_time, :exclusive_time, :call_count, :current_nest_count
      def initialize(metric_name, sample)
        @metric_name = metric_name
        @total_time, @exclusive_time, @call_count = 0,0,0
        @sample = sample
        @current_nest_count = 0
      end

      def <<(segment)
        if metric_name != segment.metric_name
          raise ArgumentError, "Metric Name Mismatch: #{segment.metric_name} != #{metric_name}"
        end

        # a nested segment should use the sum of the top level totals
        @total_time += segment.duration if current_nest_count == 0
        @exclusive_time += segment.exclusive_duration
        @call_count += 1
      end

      def average_time
        @total_time / @call_count
      end

      def average_exclusive_time
        @exclusive_time / @call_count
      end

      def exclusive_time_percentage
        return 0 unless @exclusive_time && @sample.duration && @sample.duration > 0
        @exclusive_time / @sample.duration
      end

      def total_time_percentage
        return 0 unless @total_time && @sample.duration && @sample.duration > 0
        @total_time / @sample.duration
      end

      def ui_name
        return @metric_name if @metric_name == 'Remainder'
        NewRelic::MetricParser::MetricParser.parse(@metric_name).developer_name
      end
    end
  end
end

Version data entries

50 entries across 50 versions & 1 rubygems

Version Path
newrelic_rpm-3.11.2.286 lib/new_relic/transaction_analysis/segment_summary.rb
newrelic_rpm-3.11.1.284 lib/new_relic/transaction_analysis/segment_summary.rb
newrelic_rpm-3.11.0.283 lib/new_relic/transaction_analysis/segment_summary.rb
newrelic_rpm-3.10.0.279 lib/new_relic/transaction_analysis/segment_summary.rb
newrelic_rpm-3.9.9.275 lib/new_relic/transaction_analysis/segment_summary.rb
newrelic_rpm-3.9.8.273 lib/new_relic/transaction_analysis/segment_summary.rb
newrelic_rpm-3.9.7.266 lib/new_relic/transaction_analysis/segment_summary.rb
newrelic_rpm-3.9.6.257 lib/new_relic/transaction_analysis/segment_summary.rb
newrelic_rpm-3.9.5.251 lib/new_relic/transaction_analysis/segment_summary.rb
newrelic_rpm-3.9.4.245 lib/new_relic/transaction_analysis/segment_summary.rb
newrelic_rpm-3.9.3.241 lib/new_relic/transaction_analysis/segment_summary.rb
newrelic_rpm-3.9.2.239 lib/new_relic/transaction_analysis/segment_summary.rb
newrelic_rpm-3.9.1.236 lib/new_relic/transaction_analysis/segment_summary.rb
newrelic_rpm-3.9.0.229 lib/new_relic/transaction_analysis/segment_summary.rb
newrelic_rpm-3.8.1.221 lib/new_relic/transaction_analysis/segment_summary.rb
newrelic_rpm-3.8.0.218 lib/new_relic/transaction_analysis/segment_summary.rb
newrelic_rpm-3.7.3.204 lib/new_relic/transaction_analysis/segment_summary.rb
newrelic_rpm-3.7.3.199 lib/new_relic/transaction_analysis/segment_summary.rb
newrelic_rpm-3.7.2.195 lib/new_relic/transaction_analysis/segment_summary.rb
newrelic_rpm-3.7.2.192 lib/new_relic/transaction_analysis/segment_summary.rb