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. The first is a RubyProf::Result object generated from a profiling run. The second is the minimum %total (the methods total time divided by the overall total time) that a method must take for it to be printed out in the report. Use this parameter to eliminate methods that are not important to the overall profiling results.
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.
29 30 31 32 33 |
# File 'lib/ruby-prof/graph_printer.rb', line 29 def initialize(result) super(result) @thread_times = Hash.new calculate_thread_times end |
Instance Method Details
#calculate_thread_times ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/ruby-prof/graph_printer.rb', line 35 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.sort.last thread_time = 0.01 thread_time = top.total_time if top.total_time > 0 @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.
56 57 58 59 60 |
# File 'lib/ruby-prof/graph_printer.rb', line 56 def print(output = STDOUT, = {}) @output = output () print_threads end |