class Rack::RubyProf

Public Class Methods

new(app, options = {}) click to toggle source
   # File lib/ruby-prof/rack.rb
 6 def initialize(app, options = {})
 7   @app = app
 8 
 9   options[:min_percent] ||= 1
10 
11   options[:path] ||= Dir.tmpdir
12   FileUtils.mkdir_p(options[:path])
13 
14   @skip_paths = options[:skip_paths] || [%r{^/assets}, %r{\.(css|js|png|jpeg|jpg|gif)$}]
15   @only_paths = options[:only_paths]
16 
17   @max_requests = options[:max_requests]
18 
19   @options = options
20 end

Public Instance Methods

call(env) click to toggle source
   # File lib/ruby-prof/rack.rb
22 def call(env)
23   request = Rack::Request.new(env)
24 
25   if should_profile?(request.path)
26     profiler.resume
27     begin
28       result = @app.call(env)
29     ensure
30       profiler.pause
31     end
32 
33     if profiler.max_requests_reached?
34       prefix = if aggregate_requests?
35           nil
36         else
37           request.path.gsub('/', '-')[1..-1]
38         end
39 
40       profiler.print!(prefix)
41       delete_profiler!
42     end
43 
44     result
45   else
46     @app.call(env)
47   end
48 end