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.
# File lib/ruby-prof/call_tree_printer.rb, line 42 42: def convert(value) 43: (value * @value_scale).round 44: end
# File lib/ruby-prof/call_tree_printer.rb, line 46 46: def file(method) 47: File.expand_path(method.source_file) 48: end
# File lib/ruby-prof/call_tree_printer.rb, line 50 50: def name(method) 51: "#{method.klass_name}::#{method.method_name}" 52: end
# 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: end 31: @output << "\n\n" 32: 33: print_threads 34: end
# File lib/ruby-prof/call_tree_printer.rb, line 54 54: def print_methods(thread_id, methods) 55: methods.reverse_each do |method| 56: # Print out the file and method name 57: @output << "fl=#{file(method)}\n" 58: @output << "fn=#{name(method)}\n" 59: 60: # Now print out the function line number and its self time 61: @output << "#{method.line} #{convert(method.self_time)}\n" 62: 63: # Now print out all the children methods 64: method.children.each do |callee| 65: @output << "cfl=#{file(callee.target)}\n" 66: @output << "cfn=#{name(callee.target)}\n" 67: @output << "calls=#{callee.called} #{callee.line}\n" 68: 69: # Print out total times here! 70: @output << "#{callee.line} #{convert(callee.total_time)}\n" 71: end 72: @output << "\n" 73: end 74: end