class RubyProf::CallTreePrinter

Generates profiling information in callgrind format for use by kcachegrind and similar tools.

Public Class Methods

needs_dir?() click to toggle source
   # File lib/ruby-prof/printers/call_tree_printer.rb
97 def self.needs_dir?
98   true
99 end

Public Instance Methods

calltree_name(method_info) click to toggle source
   # File lib/ruby-prof/printers/call_tree_printer.rb
12 def calltree_name(method_info)
13   klass_path = method_info.klass_name.gsub("::", '/')
14   result = "#{klass_path}::#{method_info.method_name}"
15 
16   case method_info.klass_flags
17     when 0x2
18       "#{result}^"
19     when 0x4
20       "#{result}^"
21     when 0x8
22      "#{result}*"
23     else
24      result
25   end
26 end
convert(value) click to toggle source
   # File lib/ruby-prof/printers/call_tree_printer.rb
76 def convert(value)
77   (value * @value_scale).round
78 end
determine_event_specification_and_value_scale() click to toggle source
   # File lib/ruby-prof/printers/call_tree_printer.rb
28 def determine_event_specification_and_value_scale
29   @event_specification = "events: "
30   case RubyProf.measure_mode
31     when RubyProf::PROCESS_TIME
32       @value_scale = RubyProf::CLOCKS_PER_SEC
33       @event_specification << 'process_time'
34     when RubyProf::WALL_TIME
35       @value_scale = 1_000_000
36       @event_specification << 'wall_time'
37     when RubyProf.const_defined?(:ALLOCATIONS) && RubyProf::ALLOCATIONS
38       @value_scale = 1
39       @event_specification << 'allocations'
40     when RubyProf.const_defined?(:MEMORY) && RubyProf::MEMORY
41       @value_scale = 1
42       @event_specification << 'memory'
43     when RubyProf.const_defined?(:GC_RUNS) && RubyProf::GC_RUNS
44       @value_scale = 1
45       @event_specification << 'gc_runs'
46     when RubyProf.const_defined?(:GC_TIME) && RubyProf::GC_TIME
47       @value_scale = 1000000
48       @event_specification << 'gc_time'
49     else
50       raise "Unknown measure mode: #{RubyProf.measure_mode}"
51   end
52 end
file(method) click to toggle source
   # File lib/ruby-prof/printers/call_tree_printer.rb
80 def file(method)
81   method.source_file ? File.expand_path(method.source_file) : ''
82 end
file_name_for_thread(thread) click to toggle source
    # File lib/ruby-prof/printers/call_tree_printer.rb
107 def file_name_for_thread(thread)
108   if thread.fiber_id == Fiber.current.object_id
109     ["callgrind.out", $$].join(".")
110   else
111     ["callgrind.out", $$, thread.fiber_id].join(".")
112   end
113 end
file_path_for_thread(thread) click to toggle source
    # File lib/ruby-prof/printers/call_tree_printer.rb
115 def file_path_for_thread(thread)
116   File.join(path, file_name_for_thread(thread))
117 end
path() click to toggle source
   # File lib/ruby-prof/printers/call_tree_printer.rb
93 def path
94   @options[:path] || "."
95 end
print(options = {}) click to toggle source
print_headers(output, thread) click to toggle source
print_method(output, method) click to toggle source
print_thread(thread) click to toggle source
print_threads() click to toggle source
remove_subsidiary_files_from_previous_profile_runs() click to toggle source
    # File lib/ruby-prof/printers/call_tree_printer.rb
101 def remove_subsidiary_files_from_previous_profile_runs
102   pattern = ["callgrind.out", $$, "*"].join(".")
103   files = Dir.glob(File.join(path, pattern))
104   FileUtils.rm_f(files)
105 end
validate_print_params(options) click to toggle source
   # File lib/ruby-prof/printers/call_tree_printer.rb
61 def validate_print_params(options)
62   if options.is_a?(IO)
63     raise ArgumentError, "#{self.class.name}#print cannot print to IO objects"
64   elsif !options.is_a?(Hash)
65     raise ArgumentError, "#{self.class.name}#print requires an options hash"
66   end
67 end