aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/lib/action_controller/request_profiler.rb
diff options
context:
space:
mode:
authorJeremy Kemper <jeremy@bitsweat.net>2007-12-22 04:49:56 +0000
committerJeremy Kemper <jeremy@bitsweat.net>2007-12-22 04:49:56 +0000
commitca812785ec3f339408f825fd27b60f8b081e73a2 (patch)
tree6b9ba057f239605157a9cc3c7e4f9775b826773a /actionpack/lib/action_controller/request_profiler.rb
parentc9d313dc2274007a3457cabd7b627e661d7383cb (diff)
downloadrails-ca812785ec3f339408f825fd27b60f8b081e73a2.tar.gz
rails-ca812785ec3f339408f825fd27b60f8b081e73a2.tar.bz2
rails-ca812785ec3f339408f825fd27b60f8b081e73a2.zip
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
Diffstat (limited to 'actionpack/lib/action_controller/request_profiler.rb')
-rwxr-xr-xactionpack/lib/action_controller/request_profiler.rb13
1 files changed, 6 insertions, 7 deletions
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 }