Class: RubyProf::GraphPrinter
- Inherits:
-
AbstractPrinter
- Object
- AbstractPrinter
- RubyProf::GraphPrinter
- Defined in:
- lib/ruby-prof/graph_printer.rb
Overview
Generates graph profile reports as text. To use the graph printer:
result = RubyProf.profile do
[code to profile]
end
printer = RubyProf::GraphPrinter.new(result, 5)
printer.print(STDOUT, 0)
The constructor takes two arguments. See the README
Constant Summary collapse
- PERCENTAGE_WIDTH =
8
- TIME_WIDTH =
10
- CALL_WIDTH =
17
Instance Method Summary collapse
- #calculate_thread_times ⇒ Object
-
#initialize(result) ⇒ GraphPrinter
constructor
Create a GraphPrinter.
-
#print(output = STDOUT, options = {}) ⇒ Object
Print a graph report to the provided output.
Methods inherited from AbstractPrinter
#method_name, #min_percent, #print_file, #setup_options
Constructor Details
#initialize(result) ⇒ GraphPrinter
Create a GraphPrinter. Result is a RubyProf::Result
object generated from a profiling run.
23 24 25 26 27 |
# File 'lib/ruby-prof/graph_printer.rb', line 23 def initialize(result) super(result) @thread_times = Hash.new calculate_thread_times end |
Instance Method Details
#calculate_thread_times ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/ruby-prof/graph_printer.rb', line 29 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 = {}) ⇒ Object
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.
49 50 51 52 53 |
# File 'lib/ruby-prof/graph_printer.rb', line 49 def print(output = STDOUT, = {}) @output = output () print_threads end |