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.
Defined Under Namespace
Modules: ClassMethods
Class Method Summary collapse
-
.included(base) ⇒ Object
:nodoc:.
Instance Method Summary collapse
- #perform_action_with_benchmark ⇒ Object
- #render_with_benchmark(options = nil, deprecated_status = nil, &block) ⇒ Object
Class Method Details
.included(base) ⇒ Object
:nodoc:
7 8 9 10 11 12 13 14 |
# File 'lib/action_controller/benchmarking.rb', line 7 def self.included(base) base.extend(ClassMethods) base.class_eval do alias_method_chain :perform_action, :benchmark alias_method_chain :render, :benchmark end end |
Instance Method Details
#perform_action_with_benchmark ⇒ Object
62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/action_controller/benchmarking.rb', line 62 def perform_action_with_benchmark unless logger 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 defined?(@rendering_runtime) << active_record_runtime(runtime) if Object.const_defined?("ActiveRecord") && ActiveRecord::Base.connected? << " | #{headers["Status"]}" << " [#{complete_request_uri rescue "unknown"}]" logger.info() end end |
#render_with_benchmark(options = nil, deprecated_status = nil, &block) ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/action_controller/benchmarking.rb', line 43 def render_with_benchmark( = nil, deprecated_status = nil, &block) unless logger render_without_benchmark(, deprecated_status, &block) 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, &block) }.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 |