Skip to content
This repository
Browse code

Require ruby-prof 0.6.1 or later. Use resume/pause to omit extraneous…

… machinery from profile.
  • Loading branch information...
commit 946f51449a2531b8c1a92035b4482ae633d56894 1 parent 131dd0e
Jeremy Kemper jeremy authored

Showing 1 changed file with 17 additions and 8 deletions. Show diff stats Hide diff stats

  1. +17 8 actionpack/lib/action_controller/request_profiler.rb
25 actionpack/lib/action_controller/request_profiler.rb
@@ -17,13 +17,13 @@ def initialize(script_path)
17 17 reset!
18 18 end
19 19
20   - def benchmark(n)
  20 + def benchmark(n, profiling = false)
21 21 @quiet = true
22 22 print ' '
23 23
24 24 result = Benchmark.realtime do
25 25 n.times do |i|
26   - run
  26 + run(profiling)
27 27 print_progress(i)
28 28 end
29 29 end
@@ -43,8 +43,15 @@ def define_run_method(script_path)
43 43 script = File.read(script_path)
44 44
45 45 source = <<-end_source
46   - def run
47   - #{script}
  46 + def run(profiling = false)
  47 + if profiling
  48 + RubyProf.resume do
  49 + #{script}
  50 + end
  51 + else
  52 + #{script}
  53 + end
  54 +
48 55 old_request_count = request_count
49 56 reset!
50 57 self.request_count = old_request_count
@@ -91,21 +98,22 @@ def run
91 98 def profile(sandbox)
92 99 load_ruby_prof
93 100
94   - results = RubyProf.profile { benchmark(sandbox) }
  101 + benchmark(sandbox, true)
  102 + results = RubyProf.stop
95 103
96 104 show_profile_results results
97 105 results
98 106 end
99 107
100   - def benchmark(sandbox)
  108 + def benchmark(sandbox, profiling = false)
101 109 sandbox.request_count = 0
102   - elapsed = sandbox.benchmark(options[:n]).to_f
  110 + elapsed = sandbox.benchmark(options[:n], profiling).to_f
103 111 count = sandbox.request_count.to_i
104 112 puts '%.2f sec, %d requests, %d req/sec' % [elapsed, count, count / elapsed]
105 113 end
106 114
107 115 def warmup(sandbox)
108   - Benchmark.realtime { sandbox.run }
  116 + Benchmark.realtime { sandbox.run(false) }
109 117 end
110 118
111 119 def default_options
@@ -136,6 +144,7 @@ def parse_options(args)
136 144 protected
137 145 def load_ruby_prof
138 146 begin
  147 + gem 'ruby-prof', '>= 0.6.1'
139 148 require 'ruby-prof'
140 149 if mode = options[:measure]
141 150 RubyProf.measure_mode = RubyProf.const_get(mode.upcase)

1 comment on commit 946f514

Jeremy Kemper
Owner

Doh, 0.6.1 isn’t actually released as a gem yet.

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