Class: Rack::RubyProf::RackProfiler
- Inherits:
-
Object
- Object
- Rack::RubyProf::RackProfiler
- Defined in:
- lib/ruby-prof/rack.rb
Instance Method Summary collapse
-
#initialize(options) ⇒ RackProfiler
constructor
A new instance of RackProfiler.
- #max_requests_reached? ⇒ Boolean
- #pause ⇒ Object
- #print!(prefix = nil) ⇒ Object
- #resume ⇒ Object
Constructor Details
#initialize(options) ⇒ RackProfiler
Returns a new instance of RackProfiler.
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/ruby-prof/rack.rb', line 53 def initialize() @options = @profile = ::RubyProf::Profile.new() @profile.start @profile.pause @printer_klasses = [:printers] || default_printers @tmpdir = [:path] @max_requests = [:max_requests] || 1 @requests_count = 0 @printed = false # if running across multiple requests, we want to make sure that the # ongoing profile is not lost if the process shuts down before the # max request count is reached ObjectSpace.define_finalizer(self, proc { print! }) end |
Instance Method Details
#max_requests_reached? ⇒ Boolean
83 84 85 |
# File 'lib/ruby-prof/rack.rb', line 83 def max_requests_reached? @requests_count >= @max_requests end |
#pause ⇒ Object
78 79 80 81 |
# File 'lib/ruby-prof/rack.rb', line 78 def pause @profile.pause @requests_count += 1 end |
#print!(prefix = nil) ⇒ Object
87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 |
# File 'lib/ruby-prof/rack.rb', line 87 def print!(prefix = nil) return false if @printed || @requests_count == 0 data = @profile.stop prefix ||= "multi-requests-#{@requests_count}" @printer_klasses.each do |printer_klass, base_name| printer = printer_klass.new(data) if base_name.respond_to?(:call) base_name = base_name.call end if printer_klass == ::RubyProf::MultiPrinter \ || printer_klass == ::RubyProf::CallTreePrinter printer.print(@options.merge(:profile => "#{prefix}-#{base_name}")) else file_name = ::File.join(@tmpdir, "#{prefix}-#{base_name}") ::File.open(file_name, 'wb') do |file| printer.print(file, @options) end end end @printed = true end |
#resume ⇒ Object
74 75 76 |
# File 'lib/ruby-prof/rack.rb', line 74 def resume @profile.resume end |