class RubyProf::DotPrinter

Generates a graphviz graph in dot format.

To use the dot printer:

result = RubyProf.profile do
  [code to profile]
end

printer = RubyProf::DotPrinter.new(result)
printer.print(STDOUT)

You can use either dot viewer such as GraphViz, or the dot command line tool to reformat the output into a wide variety of outputs:

dot -Tpng graph.dot > graph.png

Constants

CLASS_COLOR
EDGE_COLOR

Public Class Methods

new(result) click to toggle source

Creates the DotPrinter using a RubyProf::Proile.

Calls superclass method RubyProf::AbstractPrinter::new
# File lib/ruby-prof/printers/dot_printer.rb, line 27
def initialize(result)
  super(result)
  @seen_methods = Set.new
end

Public Instance Methods

print(output = STDOUT, options = {}) click to toggle source

Print a graph report to the provided output.

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

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

When profiling results that cover a large number of method calls it helps to use the :min_percent option, for example:

DotPrinter.new(result).print(STDOUT, :min_percent=>5)

Private Instance Methods

dot_id(subject) click to toggle source

Determines an ID to use to represent the subject in the Dot file.

# File lib/ruby-prof/printers/dot_printer.rb, line 78
def dot_id(subject)
  subject.object_id
end
mode_name() click to toggle source

Something of a hack, figure out which constant went with the RubyProf.measure_mode so that we can display it. Otherwise it's easy to forget what measurement was made.

# File lib/ruby-prof/printers/dot_printer.rb, line 62
def mode_name
  RubyProf.constants.find{|c| RubyProf.const_get(c) == RubyProf.measure_mode}
end
print_classes(thread) click to toggle source
print_edges(total_time, method) click to toggle source
print_thread(thread) click to toggle source
print_threads() click to toggle source
puts(str) click to toggle source

Silly little helper for printing to the @output

# File lib/ruby-prof/printers/dot_printer.rb, line 127
def puts(str)
  @output.puts(str)
end