Sha256: 9d44e6ad842caf8494a32577361f1c27a011632a6af7228ce52878bd7090a6c0

Contents?: true

Size: 1.04 KB

Versions: 12

Compression:

Stored size: 1.04 KB

Contents

# The call info visitor class does a depth-first traversal
# across a thread's call stack.  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)
#
#   method_names = Array.new
#
#   visitor.visit do |call_info, event|
#     method_names << call_info.target.full_name if event == :enter
#   end
#
#   puts method_names

module RubyProf
  class CallInfoVisitor

    def initialize(thread)
      @thread = thread
    end

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

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

Version data entries

12 entries across 10 versions & 2 rubygems

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