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 @options = options 9 @options[:min_percent] ||= 1 10 11 @tmpdir = options[:path] || Dir.tmpdir 12 FileUtils.mkdir_p(@tmpdir) 13 14 @printer_klasses = @options[:printers] || {::RubyProf::FlatPrinter => 'flat.txt', 15 ::RubyProf::GraphPrinter => 'graph.txt', 16 ::RubyProf::GraphHtmlPrinter => 'graph.html', 17 ::RubyProf::CallStackPrinter => 'call_stack.html'} 18 19 @skip_paths = options[:skip_paths] || [%r{^/assets}, %r{\.(css|js|png|jpeg|jpg|gif)$}] 20 @only_paths = options[:only_paths] 21 end
Public Instance Methods
call(env)
click to toggle source
# File lib/ruby-prof/rack.rb 23 def call(env) 24 request = Rack::Request.new(env) 25 26 if should_profile?(request.path) 27 begin 28 result = nil 29 data = ::RubyProf::Profile.profile(profiling_options) do 30 result = @app.call(env) 31 end 32 33 path = request.path.gsub('/', '-') 34 path.slice!(0) 35 36 print(data, path) 37 result 38 end 39 else 40 @app.call(env) 41 end 42 end