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

      @tmpdir = options[:path] || Dir.tmpdir
      FileUtils.mkdir_p(@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|js|png|jpeg|jpg|gif)$}]
      @only_paths = options[:only_paths]
    end

### Public Instance Methods

call(env) click to toggle source

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

      if should_profile?(request.path)
        begin
          result = nil
          data = ::RubyProf::Profile.profile(profiling_options) do
            result = @app.call(env)
          end

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

          print(data, path)
          result
        end
      else
        @app.call(env)
      end
    end