Class: RubyProf::CallTreePrinter
- Inherits:
-
AbstractPrinter
- Object
- AbstractPrinter
- RubyProf::CallTreePrinter
- Defined in:
- lib/ruby-prof/call_tree_printer.rb
Overview
Generate profiling information in calltree format for use by kcachegrind and similar tools.
Direct Known Subclasses
Instance Method Summary collapse
- #convert(value) ⇒ Object
- #file(method) ⇒ Object
- #print(output = STDOUT, options = {}) ⇒ Object
- #print_methods(thread_id, methods) ⇒ Object
- #print_threads ⇒ Object
Methods inherited from AbstractPrinter
#initialize, #method_name, #min_percent, #print_file, #setup_options
Constructor Details
This class inherits a constructor from RubyProf::AbstractPrinter
Instance Method Details
#convert(value) ⇒ Object
50 51 52 |
# File 'lib/ruby-prof/call_tree_printer.rb', line 50 def convert(value) (value * @value_scale).round end |
#file(method) ⇒ Object
54 55 56 |
# File 'lib/ruby-prof/call_tree_printer.rb', line 54 def file(method) File.(method.source_file) end |
#print(output = STDOUT, options = {}) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/ruby-prof/call_tree_printer.rb', line 8 def print(output = STDOUT, = {}) @output = output () # add a header - this information is somewhat arbitrary @output << "events: " case RubyProf.measure_mode when RubyProf::PROCESS_TIME @value_scale = RubyProf::CLOCKS_PER_SEC; @output << 'process_time' when RubyProf::WALL_TIME @value_scale = 1_000_000 @output << 'wall_time' when RubyProf.const_defined?(:CPU_TIME) && RubyProf::CPU_TIME @value_scale = RubyProf.cpu_frequency @output << 'cpu_time' when RubyProf.const_defined?(:ALLOCATIONS) && RubyProf::ALLOCATIONS @value_scale = 1 @output << 'allocations' when RubyProf.const_defined?(:MEMORY) && RubyProf::MEMORY @value_scale = 1 @output << 'memory' when RubyProf.const_defined?(:GC_RUNS) && RubyProf::GC_RUNS @value_scale = 1 @output << 'gc_runs' when RubyProf.const_defined?(:GC_TIME) && RubyProf::GC_TIME @value_scale = 1000000 @output << 'gc_time' else raise "Unknown measure mode: #{RubyProf.measure_mode}" end @output << "\n\n" print_threads end |
#print_methods(thread_id, methods) ⇒ Object
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/ruby-prof/call_tree_printer.rb', line 58 def print_methods(thread_id, methods) methods.reverse_each do |method| # Print out the file and method name @output << "fl=#{file(method)}\n" @output << "fn=#{method_name(method)}\n" # Now print out the function line number and its self time @output << "#{method.line} #{convert(method.self_time)}\n" # Now print out all the children methods method.children.each do |callee| @output << "cfl=#{file(callee.target)}\n" @output << "cfn=#{method_name(callee.target)}\n" @output << "calls=#{callee.called} #{callee.line}\n" # Print out total times here! @output << "#{callee.line} #{convert(callee.total_time)}\n" end @output << "\n" end end |
#print_threads ⇒ Object
44 45 46 47 48 |
# File 'lib/ruby-prof/call_tree_printer.rb', line 44 def print_threads @result.threads.each do |thread_id, methods| print_methods(thread_id, methods) end end |