Module: ActionController::CustomBenchmarking

Defined in:
lib/custom_benchmarks.rb

Overview

:nodoc:

Defined Under Namespace

Modules: ClassMethods

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object

:nodoc:



71
72
73
74
75
76
77
78
# File 'lib/custom_benchmarks.rb', line 71

def self.included(base)
  base.extend(ClassMethods)

  base.class_eval do
    alias_method :perform_action_without_custom_benchmark, :perform_action
    alias_method :perform_action, :perform_action_with_custom_benchmark
  end
end

Instance Method Details

#perform_action_with_custom_benchmarkObject



93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
# File 'lib/custom_benchmarks.rb', line 93

def perform_action_with_custom_benchmark
  unless logger
    perform_action_without_custom_benchmark
  else
    runtime = [Benchmark::measure{ perform_action_without_custom_benchmark }.real, 0.0001].max
    log_message  = "Finished #{controller_class_name}\##{action_name} in #{sprintf("%.5f", runtime)} (#{(1 / runtime).floor} reqs/sec)"
    if Object.const_defined?("ActiveRecord") && ActiveRecord::Base.connected?
      log_message << active_record_runtime(runtime)
    end
    log_message << rendering_runtime(runtime) if @rendering_runtime
    self.class.custom_benchmarks.each do |benchmark|
      log_message << benchmark.call(runtime)
    end
    log_message << " | Time: #{Time.now.to_i}"
    log_message << " | #{headers["Status"]}"
    log_message << " [#{complete_request_uri rescue "unknown"}]"
    logger.info(log_message)
  end
end