Class: RubyProf::CallTreeAbstractPrinter

Inherits:
Object
  • Object
show all
Defined in:
lib/ruby-prof/call_tree/abstract_printer.rb

Direct Known Subclasses

CallTreeHtmlPrinter, CallTreeTextPrinter

Instance Method Summary collapse

Constructor Details

#initialize(call_tree, min_percentage = 0) ⇒ CallTreeAbstractPrinter

Returns a new instance of CallTreeAbstractPrinter.



3
4
5
6
# File 'lib/ruby-prof/call_tree/abstract_printer.rb', line 3

def initialize(call_tree, min_percentage=0)
  @call_tree = call_tree
  @min_percentage = min_percentage.to_f
end

Instance Method Details

#format_method(method) ⇒ Object



20
21
22
# File 'lib/ruby-prof/call_tree/abstract_printer.rb', line 20

def format_method(method)
  raise "abstract"
end


8
9
10
# File 'lib/ruby-prof/call_tree/abstract_printer.rb', line 8

def print(io)
  print_methods(io, @call_tree.children)
end


12
13
14
15
16
17
18
# File 'lib/ruby-prof/call_tree/abstract_printer.rb', line 12

def print_methods(io, methods, parent_time=nil)
  methods.sort_by{|m| m.time}.reverse.each do |method|
    io << format_method(method)
    next if parent_time and method.time < parent_time * @min_percentage / 100
    print_methods(io, method.children, method.time)
  end
end