Class: JRubyProf::GraphTextPrinter

Inherits:
AbstractPrinter show all
Defined in:
lib/jruby-prof/graph_text_printer.rb

Direct Known Subclasses

GraphHtmlPrinter

Constant Summary collapse

TABLE_HEADER =
" %total    %self      total      self    children    calls   Name"

Instance Attribute Summary

Attributes inherited from AbstractPrinter

#thread_set

Instance Method Summary collapse

Methods inherited from AbstractPrinter

#initialize, #print_to_file

Constructor Details

This class inherits a constructor from JRubyProf::AbstractPrinter

Instance Method Details



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/jruby-prof/graph_text_printer.rb', line 28

def print_method(output, method, total_duration, print_percents)
  return if method.name =~ /JRubyProf\.stop/
  total    = method.duration
  total_pc = (total.to_f/total_duration)*100
  children = method.childrens_duration
  self_    = total - children
  self_pc  = (self_.to_f/total_duration)*100
  calls    = method.count
  name     = method.name
  if print_percents
    output.print " #{("%2.2f" % total_pc).rjust(6)}% #{("%2.2f" % self_pc).rjust(6)}%"
  else
    output.print "                "
  end
  output.puts "#{total.to_s.rjust(11)} #{self_.to_s.rjust(9)} #{children.to_s.rjust(11)} #{calls.to_s.rjust(8)}  #{name}"
end


6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/jruby-prof/graph_text_printer.rb', line 6

def print_on(output)
  thread_set.invocations.each_with_index do |invocation, i|
    output.puts
    output.puts "Thread #{i + 1} / #{thread_set.length}"
    output.puts
    methods = invocation.get_methods.values.sort_by {|m| m.duration }.reverse
    output.puts TABLE_HEADER
    output.puts "-"*100
    total_duration = thread_set.duration
    rows = methods.map do |method|
      method.parent_contexts.each do |context|  
        print_method(output, context, total_duration, false)
      end
      print_method(output, method, total_duration, true)
      method.child_contexts.each do |context|  
        print_method(output, context, total_duration, false)
      end
      output.puts "-"*100
    end
  end
end