Skip to content
Browse files

No need to modify rack env. Remove min_percent setting, just use 0.01.

  • Loading branch information...
1 parent 7a156b1 commit 634f02ffdc300f9059a957a8cec542edbfb1349f @jeremy jeremy committed
Showing with 10 additions and 16 deletions.
  1. +10 −16 lib/rack/profiler.rb
View
26 lib/rack/profiler.rb
@@ -11,48 +11,42 @@ def initialize(app)
end
def call(env)
- if profiling?(env)
- profile(env)
+ if mode = profiling?(env)
+ profile(env, mode)
else
@app.call(env)
end
end
private
- def profile(env)
- RubyProf.measure_mode = RubyProf.const_get(env['rack.profiler.measure_mode'].upcase)
+ def profile(env, mode)
+ RubyProf.measure_mode = RubyProf.const_get(mode.upcase)
result = RubyProf.profile { @app.call(env) }
- [200, calltree_headers(env), calltree_body(env, result)]
+ [200, calltree_headers(env, mode), calltree_body(env, result)]
end
def profiling?(env)
- if RubyProf.running?
- false
- else
+ unless RubyProf.running?
request = Rack::Request.new(env)
if mode = request.params.delete('profile')
if MODES.include?(mode)
- env['rack.profiler.measure_mode'] = mode
- env['rack.profiler.min_precent'] = (request.params.delete('min_percent') || 0.01).to_f
- true
+ mode
else
env['rack.errors'] << "Invalid RubyProf measure_mode: #{mode}. Use one of #{MODES.to_a.join(', ')}"
false
end
- else
- false
end
end
end
- def calltree_headers(env)
+ def calltree_headers(env, mode)
{ 'Content-Type' => 'application/octet-stream',
- 'Content-Disposition' => %(attachment; filename="#{::File.basename(env['PATH_INFO'])}.#{env['rack.profiler.measure_mode']}.tree") }
+ 'Content-Disposition' => %(attachment; filename="#{::File.basename(env['PATH_INFO'])}.#{mode}.tree") }
end
def calltree_body(env, result)
body = StringIO.new
- RubyProf::CallTreePrinter.new(result).print(body, :min_percent => env['rack.profiler.min_percent'])
+ RubyProf::CallTreePrinter.new(result).print(body, :min_percent => 0.01)
body.rewind
body
end

0 comments on commit 634f02f

Please sign in to comment.
Something went wrong with that request. Please try again.