class Rack::RubyProf

Public Class Methods

new(app, options = {}) click to toggle source
# File lib/ruby-prof/rack.rb, line 5
def initialize(app, options = {})
  @app = app
  @options = options
  @options[:min_percent] ||= 1
  @tmpdir = options[:path] || Dir.tmpdir
  @printer_klasses = @options[:printers]  || {::RubyProf::FlatPrinter => 'flat.txt',
                                              ::RubyProf::GraphPrinter => 'graph.txt',
                                              ::RubyProf::GraphHtmlPrinter => 'graph.html',
                                              ::RubyProf::CallStackPrinter => 'call_stack.html'}

  @skip_paths = options[:skip_paths] || [%r{^/assets}, %r{\.css$}, %r{\.js}, %r{\.png}, %r{\.jpeg}]
end

Public Instance Methods

call(env) click to toggle source
# File lib/ruby-prof/rack.rb, line 18
def call(env)
  request = Rack::Request.new(env)

  if @skip_paths.any? {|skip_path| skip_path =~ request.path}
    @app.call(env)
  else
    result = nil
    data = ::RubyProf::Profile.profile do
      result = @app.call(env)
    end

    path = request.path.gsub('/', '-')
    path.slice!(0)

    print(data, path)
    result
  end
end
print(data, path) click to toggle source