Class: RubyProf::AbstractPrinter

Inherits:
Object
  • Object
show all
Defined in:
lib/ruby-prof/printers/abstract_printer.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(result) ⇒ AbstractPrinter

Create a new printer.

result should be the output generated from a profiling run



8
9
10
11
# File 'lib/ruby-prof/printers/abstract_printer.rb', line 8

def initialize(result)
  @result = result
  @output = nil
end

Class Method Details

.needs_dir?Boolean

whether this printer need a :path option pointing to a directory

Returns:

  • (Boolean)


100
101
102
# File 'lib/ruby-prof/printers/abstract_printer.rb', line 100

def self.needs_dir?
  false
end

Instance Method Details

#editor_uriObject



49
50
51
52
53
54
55
56
57
# File 'lib/ruby-prof/printers/abstract_printer.rb', line 49

def editor_uri
  if ENV.key?('RUBY_PROF_EDITOR_URI')
    ENV['RUBY_PROF_EDITOR_URI'] || false
  elsif @options.key?(:editor_uri)
    @options[:editor_uri]
  else
    RUBY_PLATFORM =~ /darwin/ ? 'txmt' : false
  end
end

#method_name(method) ⇒ Object



59
60
61
62
63
64
65
# File 'lib/ruby-prof/printers/abstract_printer.rb', line 59

def method_name(method)
  name = method.full_name
  if print_file
    name += " (#{method.source_file}:#{method.line}}"
  end
  name
end

#min_percentObject



37
38
39
# File 'lib/ruby-prof/printers/abstract_printer.rb', line 37

def min_percent
  @options[:min_percent] || 0
end

Print a profiling report to the provided output.

output - Any IO object, including STDOUT or a file. The default value is STDOUT.

options - Hash of print options. See #setup_options for more information. Note that each printer can define its own set of options.



75
76
77
78
79
# File 'lib/ruby-prof/printers/abstract_printer.rb', line 75

def print(output = STDOUT, options = {})
  @output = output
  setup_options(options)
  print_threads
end


41
42
43
# File 'lib/ruby-prof/printers/abstract_printer.rb', line 41

def print_file
  @options[:print_file] || false
end


96
97
# File 'lib/ruby-prof/printers/abstract_printer.rb', line 96

def print_footer(thread)
end


93
94
# File 'lib/ruby-prof/printers/abstract_printer.rb', line 93

def print_header(thread)
end


87
88
89
90
91
# File 'lib/ruby-prof/printers/abstract_printer.rb', line 87

def print_thread(thread)
  print_header(thread)
  print_methods(thread)
  print_footer(thread)
end


81
82
83
84
85
# File 'lib/ruby-prof/printers/abstract_printer.rb', line 81

def print_threads
  @result.threads.each do |thread|
    print_thread(thread)
  end
end

#setup_options(options = {}) ⇒ Object

Specify print options.

options - Hash table

:min_percent - Number 0 to 100 that specifes the minimum
               %self (the methods self time divided by the
               overall total time) that a method must take
               for it to be printed out in the report.
               Default value is 0.

:print_file  - True or false. Specifies if a method's source
               file should be printed.  Default value if false.

:sort_method - Specifies method used for sorting method infos.
               Available values are :total_time, :self_time,
               :wait_time, :children_time
               Default value is :total_time
 :editor_uri - Specifies editor uri scheme used for opening files
               e.g. :atm or :mvim. For OS X default is :txmt.
               Pass false to print bare filenames.
               Use RUBY_PROF_EDITOR_URI environment variable to override.


33
34
35
# File 'lib/ruby-prof/printers/abstract_printer.rb', line 33

def setup_options(options = {})
  @options = options
end

#sort_methodObject



45
46
47
# File 'lib/ruby-prof/printers/abstract_printer.rb', line 45

def sort_method
  @options[:sort_method] || :total_time
end