aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack
diff options
context:
space:
mode:
authorJeremy Kemper <jeremy@bitsweat.net>2008-05-30 02:39:00 -0700
committerJeremy Kemper <jeremy@bitsweat.net>2008-05-30 02:39:00 -0700
commit946f51449a2531b8c1a92035b4482ae633d56894 (patch)
treeca7b92a109e231ba21ec0380bb30c71d85cc53fc /actionpack
parent131dd0e912f4ba1880eb53dfbf2f9add277a183e (diff)
downloadrails-946f51449a2531b8c1a92035b4482ae633d56894.tar.gz
rails-946f51449a2531b8c1a92035b4482ae633d56894.tar.bz2
rails-946f51449a2531b8c1a92035b4482ae633d56894.zip
Require ruby-prof 0.6.1 or later. Use resume/pause to omit extraneous machinery from profile.
Diffstat (limited to 'actionpack')
-rwxr-xr-xactionpack/lib/action_controller/request_profiler.rb25
1 files changed, 17 insertions, 8 deletions
diff --git a/actionpack/lib/action_controller/request_profiler.rb b/actionpack/lib/action_controller/request_profiler.rb
index 8a18d194bd..a6471d0c08 100755
--- a/actionpack/lib/action_controller/request_profiler.rb
+++ b/actionpack/lib/action_controller/request_profiler.rb
@@ -17,13 +17,13 @@ module ActionController
reset!
end
- def benchmark(n)
+ def benchmark(n, profiling = false)
@quiet = true
print ' '
result = Benchmark.realtime do
n.times do |i|
- run
+ run(profiling)
print_progress(i)
end
end
@@ -43,8 +43,15 @@ module ActionController
script = File.read(script_path)
source = <<-end_source
- def run
- #{script}
+ def run(profiling = false)
+ if profiling
+ RubyProf.resume do
+ #{script}
+ end
+ else
+ #{script}
+ end
+
old_request_count = request_count
reset!
self.request_count = old_request_count
@@ -91,21 +98,22 @@ module ActionController
def profile(sandbox)
load_ruby_prof
- results = RubyProf.profile { benchmark(sandbox) }
+ benchmark(sandbox, true)
+ results = RubyProf.stop
show_profile_results results
results
end
- def benchmark(sandbox)
+ def benchmark(sandbox, profiling = false)
sandbox.request_count = 0
- elapsed = sandbox.benchmark(options[:n]).to_f
+ elapsed = sandbox.benchmark(options[:n], profiling).to_f
count = sandbox.request_count.to_i
puts '%.2f sec, %d requests, %d req/sec' % [elapsed, count, count / elapsed]
end
def warmup(sandbox)
- Benchmark.realtime { sandbox.run }
+ Benchmark.realtime { sandbox.run(false) }
end
def default_options
@@ -136,6 +144,7 @@ module ActionController
protected
def load_ruby_prof
begin
+ gem 'ruby-prof', '>= 0.6.1'
require 'ruby-prof'
if mode = options[:measure]
RubyProf.measure_mode = RubyProf.const_get(mode.upcase)