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
Private Instance Methods
aggregate_requests?()
click to toggle source
# File lib/ruby-prof/rack.rb, line 159 def aggregate_requests? !@max_requests.nil? end
delete_profiler!()
click to toggle source
# File lib/ruby-prof/rack.rb, line 150 def delete_profiler! if aggregate_requests? @@_shared_profiler.print! if @@_shared_profiler @@_shared_profiler = nil else @_profiler = nil end end
paths_match?(path, paths)
click to toggle source
# File lib/ruby-prof/rack.rb, line 169 def paths_match?(path, paths) paths.any? { |skip_path| skip_path =~ path } end
profiler()
click to toggle source
# File lib/ruby-prof/rack.rb, line 142 def profiler if aggregate_requests? @@_shared_profiler ||= RackProfiler.new(@options) else @_profiler ||= RackProfiler.new(@options) end end
should_profile?(path)
click to toggle source
# File lib/ruby-prof/rack.rb, line 163 def should_profile?(path) return false if paths_match?(path, @skip_paths) @only_paths ? paths_match?(path, @only_paths) : true end