From ca812785ec3f339408f825fd27b60f8b081e73a2 Mon Sep 17 00:00:00 2001 From: Jeremy Kemper Date: Sat, 22 Dec 2007 04:49:56 +0000 Subject: Fold reset! into the run method directly. Make -n options compatible with Ruby 1.9 whose option parser seems to call the block with nil value even when the option is omitted. git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@8477 5ecf4fe2-1ee6-0310-87b1-e25e094e27de --- actionpack/lib/action_controller/request_profiler.rb | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) (limited to 'actionpack/lib/action_controller/request_profiler.rb') diff --git a/actionpack/lib/action_controller/request_profiler.rb b/actionpack/lib/action_controller/request_profiler.rb index 3dcbddd49b..5b92f3740f 100755 --- a/actionpack/lib/action_controller/request_profiler.rb +++ b/actionpack/lib/action_controller/request_profiler.rb @@ -20,13 +20,14 @@ module ActionController def benchmark(n) @quiet = true print ' ' + result = Benchmark.realtime do n.times do |i| run - reset! print_progress(i) end end + puts result ensure @@ -40,7 +41,8 @@ module ActionController private def define_run_method(script_path) script = File.read(script_path) - instance_eval "def run; #{script}; end", script_path, 1 + source = "def run\n#{script}\nreset!\nend" + instance_eval source, script_path, 1 end def print_progress(i) @@ -94,10 +96,7 @@ module ActionController end def warmup(sandbox) - Benchmark.realtime do - sandbox.run - sandbox.reset! - end + Benchmark.realtime { sandbox.run } end def default_options @@ -109,7 +108,7 @@ module ActionController OptionParser.new do |opt| opt.banner = "USAGE: #{$0} [options] [session script path]" - opt.on('-n', '--times [0000]', 'How many requests to process. Defaults to 100.') { |v| options[:n] = v.to_i } + opt.on('-n', '--times [100]', 'How many requests to process. Defaults to 100.') { |v| options[:n] = v.to_i if v } opt.on('-b', '--benchmark', 'Benchmark instead of profiling') { |v| options[:benchmark] = v } opt.on('--open [CMD]', 'Command to open profile results. Defaults to "open %s &"') { |v| options[:open] = v } opt.on('-h', '--help', 'Show this help') { puts opt; exit } -- cgit v1.2.3