class RubyProf::CallTreePrinter

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

Note: when profiling for a callgrind printer, one should use the merge_fibers: true option when creating the profile. Otherwise each fiber would appear as a separate profile.

Public Class Methods

needs_dir?() click to toggle source
# File lib/ruby-prof/printers/call_tree_printer.rb, line 90
def self.needs_dir?
  true
end

Public Instance Methods

base_name() click to toggle source
# File lib/ruby-prof/printers/call_tree_printer.rb, line 94
def base_name
  @options[:profile] || "profile"
end
convert(value) click to toggle source
# File lib/ruby-prof/printers/call_tree_printer.rb, line 69
def convert(value)
  (value * @value_scale).round
end
determine_event_specification_and_value_scale() click to toggle source
# File lib/ruby-prof/printers/call_tree_printer.rb, line 16
def determine_event_specification_and_value_scale
  @event_specification = "events: "
  case RubyProf.measure_mode
    when RubyProf::PROCESS_TIME
      @value_scale = RubyProf::CLOCKS_PER_SEC
      @event_specification << 'process_time'
    when RubyProf::WALL_TIME
      @value_scale = 1_000_000
      @event_specification << 'wall_time'
    when RubyProf.const_defined?(:CPU_TIME) && RubyProf::CPU_TIME
      @value_scale = RubyProf.cpu_frequency
      @event_specification << 'cpu_time'
    when RubyProf.const_defined?(:ALLOCATIONS) && RubyProf::ALLOCATIONS
      @value_scale = 1
      @event_specification << 'allocations'
    when RubyProf.const_defined?(:MEMORY) && RubyProf::MEMORY
      @value_scale = 1
      @event_specification << 'memory'
    when RubyProf.const_defined?(:GC_RUNS) && RubyProf::GC_RUNS
      @value_scale = 1
      @event_specification << 'gc_runs'
    when RubyProf.const_defined?(:GC_TIME) && RubyProf::GC_TIME
      @value_scale = 1000000
      @event_specification << 'gc_time'
    else
      raise "Unknown measure mode: #{RubyProf.measure_mode}"
  end
end
file(method) click to toggle source
# File lib/ruby-prof/printers/call_tree_printer.rb, line 73
def file(method)
  File.expand_path(method.source_file)
end
file_name_for_thread(thread) click to toggle source
# File lib/ruby-prof/printers/call_tree_printer.rb, line 104
def file_name_for_thread(thread)
  if thread.fiber_id == Fiber.current.object_id
    [base_name, "callgrind.out", $$].join(".")
  else
    [base_name, "callgrind.out", $$, thread.fiber_id].join(".")
  end
end
file_path_for_thread(thread) click to toggle source
# File lib/ruby-prof/printers/call_tree_printer.rb, line 112
def file_path_for_thread(thread)
  File.join(path, file_name_for_thread(thread))
end
path() click to toggle source
# File lib/ruby-prof/printers/call_tree_printer.rb, line 86
def path
  @options[:path] || "."
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, line 98
def remove_subsidiary_files_from_previous_profile_runs
  pattern = [base_name, "callgrind.out", $$, "*"].join(".")
  files = Dir.glob(File.join(path, pattern))
  FileUtils.rm_f(files)
end
validate_print_params(options) click to toggle source
# File lib/ruby-prof/printers/call_tree_printer.rb, line 52
def validate_print_params(options)
  if options.is_a?(IO)
    raise ArgumentError, "#{self.class.name}#print cannot print to IO objects"
  elsif !options.is_a?(Hash)
    raise ArgumentError, "#{self.class.name}#print requires an options hash"
  end
end