Class: Rdepend::Printer
- Inherits:
-
RubyProf::AbstractPrinter
- Object
- RubyProf::AbstractPrinter
- Rdepend::Printer
- Defined in:
- lib/rdepend/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::Printer.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
-
#initialize(result) ⇒ Printer
constructor
Creates the Printer using a RubyProf::Result.
-
#print(output = STDOUT, options = {}) ⇒ Object
Print a graph report to the provided output.
Constructor Details
#initialize(result) ⇒ Printer
Creates the Printer using a RubyProf::Result.
26 27 28 29 |
# File 'lib/rdepend/printer.rb', line 26 def initialize(result) super(result) @seen_methods = Set.new end |
Instance Method Details
#print(output = STDOUT, options = {}) ⇒ Object
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:
Printer.new(result).print(STDOUT, :min_percent=>5)
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/rdepend/printer.rb', line 44 def print(output = STDOUT, = {}) () add('digraph "Profile" {') #add("label=\"#{mode_name} >=#{min_percent}%\\nTotal: #{total_time}\";" add("labelloc=t;") add("labeljust=l;") print_threads add('}') if output == STDOUT @output = File.open(output, 'w') else File.open(output, 'w') { |file| file.write(@contents.join("\n")) } end `dot -Tsvg #{output} > #{output}.svg` end |