class RubyProf::GraphPrinter

  1. lib/ruby-prof/graph_printer.rb
Parent: RubyProf

Generates graph profile reports as text. To use the graph printer:

result = RubyProf.profile do
  [code to profile]
end
printer = RubyProf::GraphPrinter.new(result)
printer.print(STDOUT, {})

The constructor takes two arguments. See the README

Methods

Public Class

  1. new

Public Instance

  1. calculate_thread_times
  2. print

Constants

CALL_WIDTH = 17  
PERCENTAGE_WIDTH = 8  
TIME_WIDTH = 10  

Public Class methods

new (result)

Create a GraphPrinter. Result is a RubyProf::Result object generated from a profiling run.

[show source]
# File lib/ruby-prof/graph_printer.rb, line 22
def initialize(result)
  super(result)
  @thread_times = Hash.new
  calculate_thread_times
end

Public Instance methods

calculate_thread_times ()
[show source]
# File lib/ruby-prof/graph_printer.rb, line 28
def calculate_thread_times
  # Cache thread times since this is an expensive
  # operation with the required sorting
  @result.threads.each do |thread_id, methods|
    top = methods.max

    thread_time = [top.total_time, 0.01].max

    @thread_times[thread_id] = thread_time
  end
end
print (output = STDOUT, options = {})

Print a graph report to the provided output.

output - Any IO oject, including STDOUT or a file. The default value is STDOUT.

options - Hash of print options. See setup_options for more information.

[show source]
# File lib/ruby-prof/graph_printer.rb, line 48
def print(output = STDOUT, options = {})
  @output = output
  setup_options(options)
  print_threads
end