From b7e0408ca922cf51228818edbfdcd5c63e3cb84e Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Sun, 25 Jul 2010 11:11:23 -0700 Subject: use a hash to collect optional statistics about the instrumentation --- activesupport/lib/active_support/notifications.rb | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) (limited to 'activesupport/lib/active_support/notifications.rb') 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 -- cgit v1.2.3