class Rack::RubyProf::RackProfiler

Public Class Methods

new(options) click to toggle source
# File lib/ruby-prof/rack.rb, line 53
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 83
def max_requests_reached?
  @requests_count >= @max_requests
end
pause() click to toggle source
# File lib/ruby-prof/rack.rb, line 78
def pause
  @profile.pause
  @requests_count += 1
end
print!(prefix = nil) click to toggle source
resume() click to toggle source
# File lib/ruby-prof/rack.rb, line 74
def resume
  @profile.resume
end

Private Instance Methods

default_printers() click to toggle source
# File lib/ruby-prof/rack.rb, line 135
def default_printers
  {::RubyProf::FlatPrinter => 'flat.txt',
   ::RubyProf::GraphPrinter => 'graph.txt',
   ::RubyProf::GraphHtmlPrinter => 'graph.html',
   ::RubyProf::CallStackPrinter => 'call_stack.html'}
end
profiling_options() click to toggle source
# File lib/ruby-prof/rack.rb, line 117
def profiling_options
  options = {}
  options[:measure_mode] = ::RubyProf.measure_mode
  options[:exclude_threads] =
    if @options[:ignore_existing_threads]
      Thread.list.select{|t| t != Thread.current}
    else
      ::RubyProf.exclude_threads
    end
  if @options[:request_thread_only]
    options[:include_threads] = [Thread.current]
  end
  if @options[:merge_fibers]
    options[:merge_fibers] = true
  end
  options
end