Sha256: a34a92543cb2ed8e18e02988128fb4e33dfbdb4129ad56e74b4c7a032c9f6b85

Contents?: true

Size: 1.08 KB

Versions: 3

Compression:

Stored size: 1.08 KB

Contents

module RubyProf
  # The call info visitor class does a depth-first traversal across a
  # list of method infos. At each call_info node, the visitor executes
  # the block provided in the #visit method. The block is passed two
  # parameters, the event and the call_info instance. Event will be
  # either :enter or :exit.
  #
  #   visitor = RubyProf::CallInfoVisitor.new(result.threads.first.root_methods)
  #
  #   method_names = Array.new
  #
  #   visitor.visit do |call_info, event|
  #     method_names << call_info.target.full_name if event == :enter
  #   end
  #
  #   puts method_names
  class CallInfoVisitor
    def initialize(root_methods)
      @call_infos = root_methods.map(&:callers).flatten
    end

    def visit(&block)
      @call_infos.each do |call_info|
        visit_call_info(call_info, &block)
      end
    end

    private

    def visit_call_info(call_info, &block)
      yield call_info, :enter
      call_info.target.callees.each do |child|
        visit_call_info(child, &block)
      end
      yield call_info, :exit
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
ruby-prof-1.1.0-x64-mingw32 lib/ruby-prof/call_info_visitor.rb
ruby-prof-1.1.0 lib/ruby-prof/call_info_visitor.rb
ruby-prof-1.0.0 lib/ruby-prof/call_info_visitor.rb