Sha256: 929fa9f4281dcac932251022a5c515c8d482a3dc9ea3fdbfeedbf4b9c6ced7d2

Contents?: true

Size: 1.3 KB

Versions: 15

Compression:

Stored size: 1.3 KB

Contents

# encoding: utf-8

module RubyProf
  class AggregateCallInfo
    attr_reader :call_infos

    def initialize(call_infos)
      if call_infos.length == 0
        raise(ArgumentError, "Must specify at least one call info.")
      end
      @call_infos = call_infos
    end

    def target
      call_infos.first.target
    end

    def parent
      call_infos.first.parent
    end

    def line
      call_infos.first.line
    end

    def children
      call_infos.inject(Array.new) do |result, call_info|
        result.concat(call_info.children)
      end
    end

    def total_time
      aggregate_without_recursion(:total_time)
    end

    def self_time
      aggregate_without_recursion(:self_time)
    end

    def wait_time
      aggregate_without_recursion(:wait_time)
    end

    def children_time
      aggregate_without_recursion(:children_time)
    end

    def called
      aggregate(:called)
    end

    def to_s
      "#{call_infos.first.target.full_name}"
    end

    private

    def aggregate(method_name)
      call_infos.inject(0) do |sum, call_info|
        sum + call_info.send(method_name)
      end
    end

    def aggregate_without_recursion(method_name)
      call_infos.inject(0) do |sum, call_info|
        call_info.recursive ? sum : sum + call_info.send(method_name)
      end
    end
  end
end

Version data entries

15 entries across 13 versions & 2 rubygems

Version Path
honeybadger-2.4.0 vendor/gems/ruby/1.9.1/gems/ruby-prof-0.15.1/lib/ruby-prof/aggregate_call_info.rb
honeybadger-2.4.0 vendor/gems/ruby/2.2.0/gems/ruby-prof-0.15.1/lib/ruby-prof/aggregate_call_info.rb
honeybadger-2.4.0 vendor/gems/ruby/2.1.0/gems/ruby-prof-0.15.1/lib/ruby-prof/aggregate_call_info.rb
ruby-prof-0.15.8 lib/ruby-prof/aggregate_call_info.rb
ruby-prof-0.15.7 lib/ruby-prof/aggregate_call_info.rb
ruby-prof-0.15.6 lib/ruby-prof/aggregate_call_info.rb
ruby-prof-0.15.5 lib/ruby-prof/aggregate_call_info.rb
ruby-prof-0.15.4 lib/ruby-prof/aggregate_call_info.rb
ruby-prof-0.15.3 lib/ruby-prof/aggregate_call_info.rb
ruby-prof-0.15.2 lib/ruby-prof/aggregate_call_info.rb
ruby-prof-0.15.1 lib/ruby-prof/aggregate_call_info.rb
ruby-prof-0.15.0 lib/ruby-prof/aggregate_call_info.rb
ruby-prof-0.14.2 lib/ruby-prof/aggregate_call_info.rb
ruby-prof-0.14.1 lib/ruby-prof/aggregate_call_info.rb
ruby-prof-0.14.0 lib/ruby-prof/aggregate_call_info.rb