Class | RubyProf::GraphPrinter |
In: |
lib/ruby-prof/graph_printer.rb
|
Parent: | AbstractPrinter |
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.
PERCENTAGE_WIDTH | = | 8 |
TIME_WIDTH | = | 10 |
CALL_WIDTH | = | 17 |
Create a GraphPrinter. Result is a RubyProf::Result object generated from a profiling run.
# File lib/ruby-prof/graph_printer.rb, line 29 29: def initialize(result) 30: super(result) 31: @thread_times = Hash.new 32: calculate_thread_times 33: end
# File lib/ruby-prof/graph_printer.rb, line 35 35: def calculate_thread_times 36: # Cache thread times since this is an expensive 37: # operation with the required sorting 38: @result.threads.each do |thread_id, methods| 39: top = methods.sort.last 40: 41: thread_time = 0.01 42: thread_time = top.total_time if top.total_time > 0 43: 44: @thread_times[thread_id] = thread_time 45: end 46: end
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.
# File lib/ruby-prof/graph_printer.rb, line 56 56: def print(output = STDOUT, options = {}) 57: @output = output 58: setup_options(options) 59: print_threads 60: end