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:



78
79
80
81
82
83
84
85
86
87
# File 'lib/custom_benchmarks.rb', line 78

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

  #if ENV['RAILS_ENV'] != "test"
    base.class_eval do
      alias_method :perform_action_without_custom_benchmark, :perform_action
      alias_method :perform_action, :perform_action_with_custom_benchmark
    end
  #end
end

Instance Method Details

#perform_action_with_custom_benchmarkObject



104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
# File 'lib/custom_benchmarks.rb', line 104

def perform_action_with_custom_benchmark
  unless logger
    perform_action_without_custom_benchmark
  else
    t1 = Time.now
    perform_action_without_custom_benchmark
    runtime = Time.now - t1

    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
    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.join(' '))
  end
end