Module: ActionController::Benchmarking
- Defined in:
- lib/action_controller/benchmarking.rb
Overview
The benchmarking module times the performance of actions and reports to the logger. If the Active Record package has been included, a separate timing section for database calls will be added as well.
Class Method Summary collapse
-
.append_features(base) ⇒ Object
:nodoc:.
Instance Method Summary collapse
- #perform_action_with_benchmark ⇒ Object
- #render_with_benchmark(options = {}, deprecated_status = nil) ⇒ Object
Class Method Details
.append_features(base) ⇒ Object
:nodoc:
7 8 9 10 11 12 13 14 15 16 |
# File 'lib/action_controller/benchmarking.rb', line 7 def self.append_features(base) super base.class_eval { alias_method :perform_action_without_benchmark, :perform_action alias_method :perform_action, :perform_action_with_benchmark alias_method :render_without_benchmark, :render alias_method :render, :render_with_benchmark } end |
Instance Method Details
#perform_action_with_benchmark ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/action_controller/benchmarking.rb', line 37 def perform_action_with_benchmark if logger.nil? perform_action_without_benchmark else runtime = [Benchmark::measure{ perform_action_without_benchmark }.real, 0.0001].max = "Completed in #{sprintf("%.5f", runtime)} (#{(1 / runtime).floor} reqs/sec)" << rendering_runtime(runtime) if @rendering_runtime << active_record_runtime(runtime) if Object.const_defined?("ActiveRecord") && ActiveRecord::Base.connected? << " [#{complete_request_uri}]" logger.info() end end |
#render_with_benchmark(options = {}, deprecated_status = nil) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/action_controller/benchmarking.rb', line 18 def render_with_benchmark( = {}, deprecated_status = nil) if logger.nil? render_without_benchmark(, deprecated_status) else db_runtime = ActiveRecord::Base.connection.reset_runtime if Object.const_defined?("ActiveRecord") && ActiveRecord::Base.connected? render_output = nil @rendering_runtime = Benchmark::measure{ render_output = render_without_benchmark(, deprecated_status) }.real if Object.const_defined?("ActiveRecord") && ActiveRecord::Base.connected? @db_rt_before_render = db_runtime @db_rt_after_render = ActiveRecord::Base.connection.reset_runtime @rendering_runtime -= @db_rt_after_render end render_output end end |