Sha256: dcc9aa0485b0d9b5eb4582714c239ca6f3d1b987e43884208a556e41f0a47d4a

Contents?: true

Size: 1015 Bytes

Versions: 32

Compression:

Stored size: 1015 Bytes

Contents

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

    def visit(&block)
      visit_call_tree(@call_tree, &block)
    end

    private

    def visit_call_tree(call_tree, &block)
      yield call_tree, :enter
      call_tree.children.each do |child|
        visit_call_tree(child, &block)
      end
      yield call_tree, :exit
    end
  end
end

Version data entries

32 entries across 32 versions & 2 rubygems

Version Path
ruby-prof-1.7.1-x64-mingw-ucrt lib/ruby-prof/call_tree_visitor.rb
ruby-prof-1.7.1 lib/ruby-prof/call_tree_visitor.rb
ruby-prof-1.7.0-x64-mingw-ucrt lib/ruby-prof/call_tree_visitor.rb
ruby-prof-1.7.0 lib/ruby-prof/call_tree_visitor.rb
honeybadger-5.4.0 vendor/bundle/ruby/3.2.0/gems/ruby-prof-1.6.3/lib/ruby-prof/call_tree_visitor.rb
honeybadger-5.3.0 vendor/bundle/ruby/3.2.0/gems/ruby-prof-1.6.3/lib/ruby-prof/call_tree_visitor.rb
ruby-prof-1.6.3-x64-mingw-ucrt lib/ruby-prof/call_tree_visitor.rb
ruby-prof-1.6.3 lib/ruby-prof/call_tree_visitor.rb
ruby-prof-1.6.2-x64-mingw-ucrt lib/ruby-prof/call_tree_visitor.rb
ruby-prof-1.6.2 lib/ruby-prof/call_tree_visitor.rb
ruby-prof-1.6.1 lib/ruby-prof/call_tree_visitor.rb
ruby-prof-1.6.1-x64-mingw-ucrt lib/ruby-prof/call_tree_visitor.rb
ruby-prof-1.5.0-x64-mingw-ucrt lib/ruby-prof/call_tree_visitor.rb
ruby-prof-1.5.0 lib/ruby-prof/call_tree_visitor.rb
ruby-prof-1.4.5-x64-mingw-ucrt lib/ruby-prof/call_tree_visitor.rb
ruby-prof-1.4.5 lib/ruby-prof/call_tree_visitor.rb
ruby-prof-1.4.4-x64-mingw-ucrt lib/ruby-prof/call_tree_visitor.rb
ruby-prof-1.4.4 lib/ruby-prof/call_tree_visitor.rb
ruby-prof-1.4.3-x64-mingw32 lib/ruby-prof/call_tree_visitor.rb
ruby-prof-1.4.3 lib/ruby-prof/call_tree_visitor.rb