Sha256: 780f1b6b6dca0fd2ee74e571199449721d48a1564bf5e8648de32c5622242bb9

Contents?: true

Size: 1.74 KB

Versions: 23

Compression:

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

# summarizes performance data for all calls to segments
# with the same metric_name
module NewRelic
  module Rack
    class DeveloperMode
      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
end

Version data entries

23 entries across 23 versions & 2 rubygems

Version Path
newrelic_rpm-4.0.0.332 lib/new_relic/rack/developer_mode/segment_summary.rb
newrelic_rpm-3.18.1.330 lib/new_relic/rack/developer_mode/segment_summary.rb
newrelic_rpm-3.18.0.329 lib/new_relic/rack/developer_mode/segment_summary.rb
newrelic_rpm-3.17.2.327 lib/new_relic/rack/developer_mode/segment_summary.rb
newrelic_rpm-3.17.1.326 lib/new_relic/rack/developer_mode/segment_summary.rb
newrelic_rpm-3.17.0.325 lib/new_relic/rack/developer_mode/segment_summary.rb
newrelic_rpm-3.16.3.323 lib/new_relic/rack/developer_mode/segment_summary.rb
newrelic_rpm-3.16.2.321 lib/new_relic/rack/developer_mode/segment_summary.rb
newrelic_rpm-3.16.1.320 lib/new_relic/rack/developer_mode/segment_summary.rb
newrelic_rpm-3.16.0.318 lib/new_relic/rack/developer_mode/segment_summary.rb
ish_lib_manager-0.0.1 test/dummy/vendor/bundle/ruby/2.3.0/gems/newrelic_rpm-3.15.2.317/lib/new_relic/rack/developer_mode/segment_summary.rb
newrelic_rpm-3.15.2.317 lib/new_relic/rack/developer_mode/segment_summary.rb
newrelic_rpm-3.15.1.316 lib/new_relic/rack/developer_mode/segment_summary.rb
newrelic_rpm-3.15.0.314 lib/new_relic/rack/developer_mode/segment_summary.rb
newrelic_rpm-3.14.3.313 lib/new_relic/rack/developer_mode/segment_summary.rb
newrelic_rpm-3.14.2.312 lib/new_relic/rack/developer_mode/segment_summary.rb
newrelic_rpm-3.14.1.311 lib/new_relic/rack/developer_mode/segment_summary.rb
newrelic_rpm-3.14.0.305 lib/new_relic/rack/developer_mode/segment_summary.rb
newrelic_rpm-3.13.2.302 lib/new_relic/rack/developer_mode/segment_summary.rb
newrelic_rpm-3.13.1.300 lib/new_relic/rack/developer_mode/segment_summary.rb