Class RubyProf::CallTreePrinter
In: lib/ruby-prof/call_tree_printer.rb
Parent: AbstractPrinter

Generate profiling information in calltree format for use by kcachegrind and similar tools.

Methods

convert   file   name   print   print_methods   print_threads  

Public Instance methods

[Source]

    # File lib/ruby-prof/call_tree_printer.rb, line 35
35:     def convert(value)
36:       (value * 1000).round
37:     end

[Source]

    # File lib/ruby-prof/call_tree_printer.rb, line 39
39:     def file(method)
40:       File.expand_path(method.source_file)
41:     end

[Source]

    # File lib/ruby-prof/call_tree_printer.rb, line 43
43:     def name(method)
44:       "#{method.klass_name}::#{method.method_name}"
45:     end

[Source]

    # File lib/ruby-prof/call_tree_printer.rb, line 8
 8:     def print(output = STDOUT, options = {})
 9:       @output = output
10:       setup_options(options)
11:         
12:       # add a header - this information is somewhat arbitrary
13:       @output << "events: "
14:       case RubyProf.measure_mode
15:         when RubyProf::PROCESS_TIME
16:           @output << 'process_time'
17:         when RubyProf::WALL_TIME
18:           @output << 'wall_time'
19:         when RubyProf::CPU_TIME
20:           @output << 'cpu_time'
21:         when RubyProf::ALLOCATIONS
22:           @output << 'allocations'
23:       end
24:       @output << "\n\n"  
25: 
26:       print_threads
27:     end

[Source]

    # File lib/ruby-prof/call_tree_printer.rb, line 47
47:     def print_methods(thread_id, methods)
48:       methods.reverse_each do |method| 
49:         # Print out the file and method name
50:         @output << "fl=#{file(method)}\n"
51:         @output << "fn=#{name(method)}\n"
52: 
53:         # Now print out the function line number and its self time
54:         @output << "#{method.line} #{convert(method.self_time)}\n"
55: 
56:         # Now print out all the children methods
57:         method.children.each do |callee|
58:           @output << "cfl=#{file(callee.target)}\n"
59:           @output << "cfn=#{name(callee.target)}\n"
60:           @output << "calls=#{callee.called} #{callee.line}\n"
61: 
62:           # Print out total times here!
63:           @output << "#{callee.line} #{convert(callee.total_time)}\n"
64:         end
65:       @output << "\n"
66:       end
67:     end

[Source]

    # File lib/ruby-prof/call_tree_printer.rb, line 29
29:     def print_threads
30:       @result.threads.each do |thread_id, methods|
31:         print_methods(thread_id ,methods)
32:       end
33:     end

[Validate]