Generate profiling information in calltree format for use by kcachegrind and similar tools.
Public instance methods
convert
(value)
[show source]
# File lib/ruby-prof/call_tree_printer.rb, line 50 50: def convert(value) 51: (value * @value_scale).round 52: end
file
(method)
[show source]
# File lib/ruby-prof/call_tree_printer.rb, line 54 54: def file(method) 55: File.expand_path(method.source_file) 56: end
name
(method)
[show source]
# File lib/ruby-prof/call_tree_printer.rb, line 58 58: def name(method) 59: "#{method.klass_name}::#{method.method_name}" 60: end
print
(output = STDOUT, options = {})
[show 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: @value_scale = RubyProf::CLOCKS_PER_SEC; 17: @output << 'process_time' 18: when RubyProf::WALL_TIME 19: @value_scale = 1_000_000 20: @output << 'wall_time' 21: when RubyProf.const_defined?(:CPU_TIME) && RubyProf::CPU_TIME 22: @value_scale = RubyProf.cpu_frequency 23: @output << 'cpu_time' 24: when RubyProf.const_defined?(:ALLOCATIONS) && RubyProf::ALLOCATIONS 25: @value_scale = 1 26: @output << 'allocations' 27: when RubyProf.const_defined?(:MEMORY) && RubyProf::MEMORY 28: @value_scale = 1 29: @output << 'memory' 30: when RubyProf.const_defined?(:GC_RUNS) && RubyProf::GC_RUNS 31: @value_scale = 1 32: @output << 'gc_runs' 33: when RubyProf.const_defined?(:GC_TIME) && RubyProf::GC_TIME 34: @value_scale = 1000000 35: @output << 'gc_time' 36: else 37: raise "Unknown measure mode: #{RubyProf.measure_mode}" 38: end 39: @output << "\n\n" 40: 41: print_threads 42: end
print_methods
(thread_id, methods)
[show source]
# File lib/ruby-prof/call_tree_printer.rb, line 62 62: def print_methods(thread_id, methods) 63: methods.reverse_each do |method| 64: # Print out the file and method name 65: @output << "fl=#{file(method)}\n" 66: @output << "fn=#{name(method)}\n" 67: 68: # Now print out the function line number and its self time 69: @output << "#{method.line} #{convert(method.self_time)}\n" 70: 71: # Now print out all the children methods 72: method.children.each do |callee| 73: @output << "cfl=#{file(callee.target)}\n" 74: @output << "cfn=#{name(callee.target)}\n" 75: @output << "calls=#{callee.called} #{callee.line}\n" 76: 77: # Print out total times here! 78: @output << "#{callee.line} #{convert(callee.total_time)}\n" 79: end 80: @output << "\n" 81: end 82: end
print_threads
()
[show source]
# File lib/ruby-prof/call_tree_printer.rb, line 44 44: def print_threads 45: @result.threads.each do |thread_id, methods| 46: print_methods(thread_id, methods) 47: end 48: end