Class: RubyProf::DotPrinter

Inherits:
AbstractPrinter show all
Defined in:
lib/ruby-prof/printers/dot_printer.rb

Overview

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

Constant Summary collapse

CLASS_COLOR =
'"#666666"'
EDGE_COLOR =
'"#666666"'

Instance Method Summary collapse

Methods inherited from AbstractPrinter

#filter_by, #max_percent, #method_href, #method_location, #min_percent, needs_dir?, #open_asset, #print_column_headers, #print_footer, #print_header, #setup_options, #sort_method, #time_format

Constructor Details

#initialize(result) ⇒ DotPrinter

Creates the DotPrinter using a RubyProf::Proile.



27
28
29
30
# File 'lib/ruby-prof/printers/dot_printer.rb', line 27

def initialize(result)
  super(result)
  @seen_methods = Set.new
end

Instance Method Details

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)


45
46
47
48
49
50
51
52
53
54
55
# File 'lib/ruby-prof/printers/dot_printer.rb', line 45

def print(output = STDOUT, options = {})
  @output = output
  setup_options(options)

  puts 'digraph "Profile" {'
  #puts "label=\"#{mode_name} >=#{min_percent}%\\nTotal: #{total_time}\";"
  puts "labelloc=t;"
  puts "labeljust=l;"
  print_threads
  puts '}'
end