diff options
author | David Heinemeier Hansson <david@loudthinking.com> | 2008-09-05 14:22:10 +0200 |
---|---|---|
committer | David Heinemeier Hansson <david@loudthinking.com> | 2008-09-05 14:22:57 +0200 |
commit | de0e7507de826bf77fd57cc2a51e27388cb62ff7 (patch) | |
tree | 60d923008716ef32943bb6caef4b6faf504a0970 /actionpack/lib/action_controller | |
parent | cf0467c6425a528acfe2cb14709253a8a4a99b37 (diff) | |
download | rails-de0e7507de826bf77fd57cc2a51e27388cb62ff7.tar.gz rails-de0e7507de826bf77fd57cc2a51e27388cb62ff7.tar.bz2 rails-de0e7507de826bf77fd57cc2a51e27388cb62ff7.zip |
Changed all benchmarking reports to be in milliseconds
Diffstat (limited to 'actionpack/lib/action_controller')
-rw-r--r-- | actionpack/lib/action_controller/benchmarking.rb | 60 |
1 files changed, 36 insertions, 24 deletions
diff --git a/actionpack/lib/action_controller/benchmarking.rb b/actionpack/lib/action_controller/benchmarking.rb index 98b0325ba3..a2bd61889f 100644 --- a/actionpack/lib/action_controller/benchmarking.rb +++ b/actionpack/lib/action_controller/benchmarking.rb @@ -24,7 +24,7 @@ module ActionController #:nodoc: if logger && logger.level == log_level result = nil seconds = Benchmark.realtime { result = use_silence ? silence { yield } : yield } - logger.add(log_level, "#{title} (#{'%.5f' % seconds})") + logger.add(log_level, "#{title} (#{('%.2f' % (seconds * 1000))}ms)") result else yield @@ -42,53 +42,65 @@ module ActionController #:nodoc: protected def render_with_benchmark(options = nil, extra_options = {}, &block) - unless logger - render_without_benchmark(options, extra_options, &block) - else - db_runtime = ActiveRecord::Base.connection.reset_runtime if Object.const_defined?("ActiveRecord") && ActiveRecord::Base.connected? + if logger + if Object.const_defined?("ActiveRecord") && ActiveRecord::Base.connected? + db_runtime = ActiveRecord::Base.connection.reset_runtime + end render_output = nil - @rendering_runtime = Benchmark::realtime{ render_output = render_without_benchmark(options, extra_options, &block) } + @view_runtime = Benchmark::realtime { render_output = render_without_benchmark(options, extra_options, &block) } 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 + @view_runtime -= @db_rt_after_render end render_output + else + render_without_benchmark(options, extra_options, &block) end end private def perform_action_with_benchmark - unless logger - perform_action_without_benchmark - else - runtime = [ Benchmark::measure{ perform_action_without_benchmark }.real, 0.0001 ].max + if logger + seconds = [ Benchmark::measure{ perform_action_without_benchmark }.real, 0.0001 ].max + logging_view = defined?(@view_runtime) + logging_active_record = Object.const_defined?("ActiveRecord") && ActiveRecord::Base.connected? + + log_message = "Completed in #{sprintf("%.2f", seconds * 1000)}ms" + + if logging_view || logging_active_record + log_message << " (" + log_message << view_runtime if logging_view + + if logging_active_record + log_message << ", " + active_record_runtime + ")" + else + ")" + end + end - log_message = "Completed in #{sprintf("%.5f", runtime)} (#{(1 / runtime).floor} reqs/sec)" - log_message << rendering_runtime(runtime) if defined?(@rendering_runtime) - log_message << active_record_runtime(runtime) if Object.const_defined?("ActiveRecord") && ActiveRecord::Base.connected? log_message << " | #{headers["Status"]}" log_message << " [#{complete_request_uri rescue "unknown"}]" logger.info(log_message) - response.headers["X-Runtime"] = sprintf("%.5f", runtime) + response.headers["X-Runtime"] = "#{sprintf("%.2f", seconds * 1000)}ms" + else + perform_action_without_benchmark end end - def rendering_runtime(runtime) - percentage = @rendering_runtime * 100 / runtime - " | Rendering: %.5f (%d%%)" % [@rendering_runtime, percentage.to_i] + def view_runtime + "View: %.2f" % (@view_runtime * 1000) end - def active_record_runtime(runtime) - db_runtime = ActiveRecord::Base.connection.reset_runtime - db_runtime += @db_rt_before_render if @db_rt_before_render - db_runtime += @db_rt_after_render if @db_rt_after_render - db_percentage = db_runtime * 100 / runtime - " | DB: %.5f (%d%%)" % [db_runtime, db_percentage.to_i] + def active_record_runtime + db_runtime = ActiveRecord::Base.connection.reset_runtime + db_runtime += @db_rt_before_render if @db_rt_before_render + db_runtime += @db_rt_after_render if @db_rt_after_render + "DB: %.2f" % (db_runtime * 1000) end end end |