class Rack::RubyProf - ruby-prof

# 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[:min_percent] ||= 1

      options[:path] ||= Dir.tmpdir
      FileUtils.mkdir_p(options[:path])

      @skip_paths = options[:skip_paths] || [%r{^/assets}, %r{\.(css|js|png|jpeg|jpg|gif)$}]
      @only_paths = options[:only_paths]

      @max_requests = options[:max_requests]

      @options = options
    end

### Public Instance Methods

call(env) click to toggle source

    # File lib/ruby-prof/rack.rb, line 21
    def call(env)
      request = Rack::Request.new(env)

      if should_profile?(request.path)
        profiler.resume
        begin
          result = @app.call(env)
        ensure
          profiler.pause
        end

        if profiler.max_requests_reached?
          prefix = if aggregate_requests?
              nil
            else
              request.path.gsub('/', '-')[1..-1]
            end

          profiler.print!(prefix)
          delete_profiler!
        end

        result
      else
        @app.call(env)
      end
    end