Permalink
Browse files

Add 'times' option to run the profiled app more than once

  • Loading branch information...
jeremy committed Dec 19, 2008
1 parent 5aeb545 commit af0d3d137bc39f13221bf16130628b007f007cd2
Showing with 8 additions and 4 deletions.
  1. +7 −4 lib/rack/profiler.rb
  2. +1 −0 test/spec_rack_profiler.rb
View
@@ -30,6 +30,7 @@ class Profiler
def initialize(app, options = {})
@app = app
@printer = parse_printer(options[:printer])
+ @times = (options[:times] || 1).to_i
end
def call(env)
@@ -58,10 +59,12 @@ def profiling?(env)
def profile(env, mode)
RubyProf.measure_mode = RubyProf.const_get(mode.upcase)
- result = RubyProf.profile { @app.call(env) }
- headers = headers(@printer, env, mode)
- body = print(@printer, result)
- [200, headers, body]
+
+ result = RubyProf.profile do
+ @times.times { @app.call(env) }
+ end
+
+ [200, headers(@printer, env, mode), print(@printer, result)]
end
def print(printer, result)
@@ -9,6 +9,7 @@
specify 'printer defaults to RubyProf::CallTreePrinter' do
profiler = Rack::Profiler.new(nil)
profiler.instance_variable_get('@printer').should == RubyProf::CallTreePrinter
+ profiler.instance_variable_get('@times').should == 1
end
specify 'CallTreePrinter has correct headers' do

0 comments on commit af0d3d1

Please sign in to comment.