diff options
author | Aaron Patterson <aaron.patterson@gmail.com> | 2010-07-25 11:11:23 -0700 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2010-07-25 11:11:23 -0700 |
commit | b7e0408ca922cf51228818edbfdcd5c63e3cb84e (patch) | |
tree | 0313ba10f8f42720b03b51fabc992d84c425d8cb /activesupport/lib/active_support/notifications.rb | |
parent | d02f2d2fb213584ce52a231063c948def856f657 (diff) | |
download | rails-b7e0408ca922cf51228818edbfdcd5c63e3cb84e.tar.gz rails-b7e0408ca922cf51228818edbfdcd5c63e3cb84e.tar.bz2 rails-b7e0408ca922cf51228818edbfdcd5c63e3cb84e.zip |
use a hash to collect optional statistics about the instrumentation
Diffstat (limited to 'activesupport/lib/active_support/notifications.rb')
-rw-r--r-- | activesupport/lib/active_support/notifications.rb | 16 |
1 files changed, 13 insertions, 3 deletions
diff --git a/activesupport/lib/active_support/notifications.rb b/activesupport/lib/active_support/notifications.rb index 886d7183eb..d65431a943 100644 --- a/activesupport/lib/active_support/notifications.rb +++ b/activesupport/lib/active_support/notifications.rb @@ -47,11 +47,21 @@ module ActiveSupport attr_writer :notifier delegate :publish, :unsubscribe, :to => :notifier - def instrument(name, payload = {}) + def instrument(name, payload = {}, info = nil) if @instrumenters[name] - instrumenter.instrument(name, payload) { yield payload if block_given? } + instrumenter.instrument(name, payload, info) { + yield payload if block_given? + } else - yield payload if block_given? + value = nil + if block_given? + if info + info[:elapsed] = Benchmark.ms { value = yield payload } + else + value = yield payload + end + end + value end end |