class RubyProf::AbstractPrinter
This is the base class for all Printers. It is never used directly.
def self.needs_dir?
def self.needs_dir? false end
def filter_by
def filter_by @options[:filter_by] || :self_time end
def initialize(result)
Create a new printer.
def initialize(result) @result = result @output = nil end
def max_percent
def max_percent @options[:max_percent] || 100 end
def method_href(thread, method)
def method_href(thread, method) h(method.full_name.gsub(/[><#\.\?=:]/,"_") + "_" + thread.fiber_id.to_s) end
def method_location(method)
def method_location(method) if method.source_file "#{method.source_file}:#{method.line}" end end
def min_percent
def min_percent @options[:min_percent] || 0 end
def open_asset(file)
def open_asset(file) path = File.join(File.expand_path('../../assets', __FILE__), file) File.open(path, 'rb').read end
def print(output = STDOUT, options = {})
:wait_time, :children_time
Available values are :total_time, :self_time,
:sort_method - Specifies method used for sorting method infos.
Default value is 0.
for it to be printed out in the report.
overall total time) that a method must take
%self (the methods self time divided by the
:min_percent - Number 0 to 100 that specifies the minimum
define its own set of options.
options - Hash of print options. Note that each printer can
The default value is STDOUT.
output - Any IO object, including STDOUT or a file.
Prints a report to the provided output.
def print(output = STDOUT, options = {}) @output = output setup_options(options) print_threads end
def print_column_headers
def print_column_headers end
def print_footer(thread)
def print_footer(thread) @output << <<~EOT * recursively called methods Columns are: %self - The percentage of time spent in this method, derived from self_time/total_time. total - The time spent in this method and its children. self - The time spent in this method. wait - The amount of time this method waited for other threads. child - The time spent in this method's children. calls - The number of times this method was called. name - The name of the method. location - The location of the method. The interpretation of method names is: * MyObject#test - An instance method "test" of the class "MyObject" * <Object:MyObject>#test - The <> characters indicate a method on a singleton class. EOT end
def print_header(thread)
def print_header(thread) @output << "Measure Mode: %s\n" % @result.measure_mode_string @output << "Thread ID: %d\n" % thread.id @output << "Fiber ID: %d\n" % thread.fiber_id unless thread.id == thread.fiber_id @output << "Total: %0.6f\n" % thread.total_time @output << "Sort by: #{sort_method}\n" @output << "\n" print_column_headers end
def print_thread(thread)
def print_thread(thread) print_header(thread) print_methods(thread) print_footer(thread) end
def print_threads
def print_threads @result.threads.each do |thread| print_thread(thread) end end
def setup_options(options = {})
def setup_options(options = {}) @options = options end
def sort_method
def sort_method @options[:sort_method] end
def time_format
def time_format '%A, %B %-d at %l:%M:%S %p (%Z)' end