From c74c78c88d94a2e3362f9cb55a8a86b2760cfa71 Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Fri, 16 Feb 2007 21:13:02 +0000 Subject: Added X-Benchmark to all responses with the same benchmark data as goes into the log [DHH] git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@6156 5ecf4fe2-1ee6-0310-87b1-e25e094e27de --- actionpack/lib/action_controller/benchmarking.rb | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) (limited to 'actionpack/lib') diff --git a/actionpack/lib/action_controller/benchmarking.rb b/actionpack/lib/action_controller/benchmarking.rb index ae0dd3b9be..e9844337af 100644 --- a/actionpack/lib/action_controller/benchmarking.rb +++ b/actionpack/lib/action_controller/benchmarking.rb @@ -63,16 +63,21 @@ module ActionController #:nodoc: unless logger perform_action_without_benchmark else - runtime = [Benchmark::measure{ perform_action_without_benchmark }.real, 0.0001].max + runtime = [ Benchmark::measure{ perform_action_without_benchmark }.real, 0.0001 ].max 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) + + log_message_with_status = log_message.dup + log_message_with_status << " | #{headers["Status"]}" + log_message_with_status << " [#{complete_request_uri rescue "unknown"}]" + + response.headers["X-Benchmark"] = log_message + logger.info(log_message_with_status) end end - + + private def rendering_runtime(runtime) " | Rendering: #{sprintf("%.5f", @rendering_runtime)} (#{sprintf("%d", (@rendering_runtime * 100) / runtime)}%)" -- cgit v1.2.3