diff options
author | Yehuda Katz + Carl Lerche <ykatz+clerche@engineyard.com> | 2009-05-18 16:15:43 -0700 |
---|---|---|
committer | Yehuda Katz + Carl Lerche <ykatz+clerche@engineyard.com> | 2009-05-18 17:33:45 -0700 |
commit | 07f733c6315980bde120c98c6b8a25e2773ee6bf (patch) | |
tree | 2b6fce7621af540ee6b4b07388c58cacd3a83481 /actionpack/lib/action_controller/abstract/benchmarker.rb | |
parent | ee5520a0a5ea83843ce88f6b9550e3c36b8cdd49 (diff) | |
download | rails-07f733c6315980bde120c98c6b8a25e2773ee6bf.tar.gz rails-07f733c6315980bde120c98c6b8a25e2773ee6bf.tar.bz2 rails-07f733c6315980bde120c98c6b8a25e2773ee6bf.zip |
Ported simple benchmarking in new base
Diffstat (limited to 'actionpack/lib/action_controller/abstract/benchmarker.rb')
-rw-r--r-- | actionpack/lib/action_controller/abstract/benchmarker.rb | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/actionpack/lib/action_controller/abstract/benchmarker.rb b/actionpack/lib/action_controller/abstract/benchmarker.rb new file mode 100644 index 0000000000..9f5889c704 --- /dev/null +++ b/actionpack/lib/action_controller/abstract/benchmarker.rb @@ -0,0 +1,28 @@ +module AbstractController + module Benchmarker + extend ActiveSupport::DependencyModule + + depends_on Logger + + module ClassMethods + def benchmark(title, log_level = ::Logger::DEBUG, use_silence = true) + if logger && logger.level >= log_level + result = nil + ms = Benchmark.ms { result = use_silence ? silence { yield } : yield } + logger.add(log_level, "#{title} (#{('%.1f' % ms)}ms)") + result + else + yield + end + end + + # Silences the logger for the duration of the block. + def silence + old_logger_level, logger.level = logger.level, ::Logger::ERROR if logger + yield + ensure + logger.level = old_logger_level if logger + end + end + end +end
\ No newline at end of file |