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
 99 def self.needs_dir?
100   true
101 end

Public Instance Methods

base_name() click to toggle source
    # File lib/ruby-prof/printers/call_tree_printer.rb
103 def base_name
104   @options[:profile] || "profile"
105 end
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
78 def convert(value)
79   (value * @value_scale).round
80 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
82 def file(method)
83   method.source_file ? File.expand_path(method.source_file) : ''
84 end
file_name_for_thread(thread) click to toggle source
    # File lib/ruby-prof/printers/call_tree_printer.rb
113 def file_name_for_thread(thread)
114   if thread.fiber_id == Fiber.current.object_id
115     [base_name, "callgrind.out", $$].join(".")
116   else
117     [base_name, "callgrind.out", $$, thread.fiber_id].join(".")
118   end
119 end
file_path_for_thread(thread) click to toggle source
    # File lib/ruby-prof/printers/call_tree_printer.rb
121 def file_path_for_thread(thread)
122   File.join(path, file_name_for_thread(thread))
123 end
path() click to toggle source
   # File lib/ruby-prof/printers/call_tree_printer.rb
95 def path
96   @options[:path] || "."
97 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
107 def remove_subsidiary_files_from_previous_profile_runs
108   pattern = [base_name, "callgrind.out", $$, "*"].join(".")
109   files = Dir.glob(File.join(path, pattern))
110   FileUtils.rm_f(files)
111 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