Class: RubyProf::MultiPrinter
- Inherits:
-
Object
- Object
- RubyProf::MultiPrinter
- Defined in:
- lib/ruby-prof/printers/multi_printer.rb
Overview
Helper class to simplify printing profiles of several types from one profiling run. Currently prints a flat profile, a callgrind profile, a call stack profile and a graph profile.
Class Method Summary collapse
Instance Method Summary collapse
-
#flat_profile ⇒ Object
the name of the flat profile file.
-
#graph_profile ⇒ Object
the name of the graph profile file.
-
#initialize(result, printers = [:stack, :graph, :tree, :flat]) ⇒ MultiPrinter
constructor
A new instance of MultiPrinter.
-
#print(options) ⇒ Object
create profile files under options or the current directory.
- #print_to_flat(options) ⇒ Object
- #print_to_graph(options) ⇒ Object
- #print_to_stack(options) ⇒ Object
- #print_to_tree(options) ⇒ Object
-
#stack_profile ⇒ Object
the name of the call stack profile file.
-
#tree_profile ⇒ Object
the name of the callgrind profile file.
- #validate_print_params(options) ⇒ Object
Constructor Details
#initialize(result, printers = [:stack, :graph, :tree, :flat]) ⇒ MultiPrinter
Returns a new instance of MultiPrinter.
8 9 10 11 12 13 |
# File 'lib/ruby-prof/printers/multi_printer.rb', line 8 def initialize(result, printers = [:stack, :graph, :tree, :flat]) @stack_printer = CallStackPrinter.new(result) if printers.include?(:stack) @graph_printer = GraphHtmlPrinter.new(result) if printers.include?(:graph) @tree_printer = CallTreePrinter.new(result) if printers.include?(:tree) @flat_printer = FlatPrinter.new(result) if printers.include?(:flat) end |
Class Method Details
.needs_dir? ⇒ Boolean
15 16 17 |
# File 'lib/ruby-prof/printers/multi_printer.rb', line 15 def self.needs_dir? true end |
Instance Method Details
#flat_profile ⇒ Object
the name of the flat profile file
50 51 52 |
# File 'lib/ruby-prof/printers/multi_printer.rb', line 50 def flat_profile "#{@directory}/#{@profile}.flat.txt" end |
#graph_profile ⇒ Object
the name of the graph profile file
40 41 42 |
# File 'lib/ruby-prof/printers/multi_printer.rb', line 40 def graph_profile "#{@directory}/#{@profile}.graph.html" end |
#print(options) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/ruby-prof/printers/multi_printer.rb', line 22 def print() validate_print_params() @profile = .delete(:profile) || "profile" @directory = .delete(:path) || File.(".") print_to_stack() if @stack_printer print_to_graph() if @graph_printer print_to_tree() if @tree_printer print_to_flat() if @flat_printer end |
#print_to_flat(options) ⇒ Object
70 71 72 73 74 |
# File 'lib/ruby-prof/printers/multi_printer.rb', line 70 def print_to_flat() File.open(flat_profile, "w") do |f| @flat_printer.print(f, ) end end |
#print_to_graph(options) ⇒ Object
60 61 62 63 64 |
# File 'lib/ruby-prof/printers/multi_printer.rb', line 60 def print_to_graph() File.open(graph_profile, "w") do |f| @graph_printer.print(f, ) end end |
#print_to_stack(options) ⇒ Object
54 55 56 57 58 |
# File 'lib/ruby-prof/printers/multi_printer.rb', line 54 def print_to_stack() File.open(stack_profile, "w") do |f| @stack_printer.print(f, .merge(:graph => "#{@profile}.graph.html")) end end |
#print_to_tree(options) ⇒ Object
66 67 68 |
# File 'lib/ruby-prof/printers/multi_printer.rb', line 66 def print_to_tree() @tree_printer.print(.merge(:path => @directory, :profile => @profile)) end |
#stack_profile ⇒ Object
the name of the call stack profile file
35 36 37 |
# File 'lib/ruby-prof/printers/multi_printer.rb', line 35 def stack_profile "#{@directory}/#{@profile}.stack.html" end |
#tree_profile ⇒ Object
the name of the callgrind profile file
45 46 47 |
# File 'lib/ruby-prof/printers/multi_printer.rb', line 45 def tree_profile "#{@directory}/#{@profile}.callgrind.out.#{$$}" end |
#validate_print_params(options) ⇒ Object
76 77 78 79 80 81 82 |
# File 'lib/ruby-prof/printers/multi_printer.rb', line 76 def validate_print_params() if .is_a?(IO) raise ArgumentError, "#{self.class.name}#print cannot print to IO objects" elsif !.is_a?(Hash) raise ArgumentError, "#{self.class.name}#print requires an options hash" end end |