class Rack::RubyProf::RackProfiler
Public Class Methods
new(options)
click to toggle source
# File lib/ruby-prof/rack.rb, line 52 def initialize(options) @options = options @profile = ::RubyProf::Profile.new(profiling_options) @profile.start @profile.pause @printer_klasses = options[:printers] || default_printers @tmpdir = options[:path] @max_requests = options[: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
Public Instance Methods
max_requests_reached?()
click to toggle source
# File lib/ruby-prof/rack.rb, line 82 def max_requests_reached? @requests_count >= @max_requests end
pause()
click to toggle source
# File lib/ruby-prof/rack.rb, line 77 def pause @profile.pause @requests_count += 1 end
print!(prefix = nil)
click to toggle source
# File lib/ruby-prof/rack.rb, line 86 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()
click to toggle source
# File lib/ruby-prof/rack.rb, line 73 def resume @profile.resume end