Class: Rack::RubyProf
- Inherits:
-
Object
- Object
- Rack::RubyProf
- Defined in:
- lib/ruby-prof/rack.rb
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app, options = {}) ⇒ RubyProf
constructor
A new instance of RubyProf.
Constructor Details
#initialize(app, options = {}) ⇒ RubyProf
Returns a new instance of RubyProf.
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/ruby-prof/rack.rb', line 6 def initialize(app, = {}) @app = app @options = @options[:min_percent] ||= 1 @tmpdir = [: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 = [:skip_paths] || [%r{^/assets}, %r{\.(css|js|png|jpeg|jpg|gif)$}] @only_paths = [:only_paths] end |
Instance Method Details
#call(env) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/ruby-prof/rack.rb', line 23 def call(env) request = Rack::Request.new(env) if should_profile?(request.path) begin result = nil data = ::RubyProf::Profile.profile() do result = @app.call(env) end path = request.path.gsub('/', '-') path.slice!(0) print(data, path) result end else @app.call(env) end end |