aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord
diff options
context:
space:
mode:
authorDavid Heinemeier Hansson <david@loudthinking.com>2005-09-06 16:48:18 +0000
committerDavid Heinemeier Hansson <david@loudthinking.com>2005-09-06 16:48:18 +0000
commit5e8e8d6564b81514870773b3b5de9d5746b1f1e2 (patch)
tree65f8d516212f0fbd632116815c9ffa3449965ff1 /activerecord
parent50debfa96c8e78232b32e4738d60da0c302fe1ef (diff)
downloadrails-5e8e8d6564b81514870773b3b5de9d5746b1f1e2.tar.gz
rails-5e8e8d6564b81514870773b3b5de9d5746b1f1e2.tar.bz2
rails-5e8e8d6564b81514870773b3b5de9d5746b1f1e2.zip
Added use_silence parameter to ActiveRecord::Base.benchmark that can be passed false to include all logging statements during the benchmark block. Added ActionController::Base.benchmark and ActionController::Base.silence to allow for easy benchmarking and turning off the log
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@2140 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activerecord')
-rw-r--r--activerecord/CHANGELOG2
-rwxr-xr-xactiverecord/lib/active_record/base.rb16
2 files changed, 13 insertions, 5 deletions
diff --git a/activerecord/CHANGELOG b/activerecord/CHANGELOG
index be367e52c0..2c60938bda 100644
--- a/activerecord/CHANGELOG
+++ b/activerecord/CHANGELOG
@@ -1,5 +1,7 @@
*SVN*
+* Added use_silence parameter to ActiveRecord::Base.benchmark that can be passed false to include all logging statements during the benchmark block
+
* Make sure the schema_info table is created before querying the current version #1903
* Fixtures ignore table name prefix and suffix #1987 [Jakob S]
diff --git a/activerecord/lib/active_record/base.rb b/activerecord/lib/active_record/base.rb
index 6180f45fed..a6ce28685c 100755
--- a/activerecord/lib/active_record/base.rb
+++ b/activerecord/lib/active_record/base.rb
@@ -714,11 +714,17 @@ module ActiveRecord #:nodoc:
# project.create_manager("name" => "David")
# project.milestones << Milestone.find(:all)
# end
- def benchmark(title)
- result = nil
- seconds = Benchmark.realtime { result = silence { yield } }
- logger.info "#{title} (#{sprintf("%f", seconds)})" if logger
- return result
+ #
+ # The loggings of the multiple statements is turned off unless <tt>use_silence</tt> is set to false.
+ def benchmark(title, use_silence = true)
+ if logger
+ result = nil
+ seconds = Benchmark.realtime { result = use_silence ? silence { yield } : yield }
+ logger.info "#{title} (#{sprintf("%f", seconds)})"
+ result
+ else
+ yield
+ end
end
# Silences the logger for the duration of the block.