From 7c3573f32757e9c4c6b6140499a3e7dfe2d335b1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Wed, 13 Jan 2010 22:28:18 +0100 Subject: Add instrument! to notifications which adds the result to the payload. --- activesupport/lib/active_support/notifications/instrumenter.rb | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'activesupport/lib/active_support/notifications/instrumenter.rb') diff --git a/activesupport/lib/active_support/notifications/instrumenter.rb b/activesupport/lib/active_support/notifications/instrumenter.rb index af35eb92cb..85c5199946 100644 --- a/activesupport/lib/active_support/notifications/instrumenter.rb +++ b/activesupport/lib/active_support/notifications/instrumenter.rb @@ -11,13 +11,21 @@ module ActiveSupport @notifier = notifier end - def instrument(name, payload={}) + # Instrument the given block by measuring the time taken to execute it + # and publish it. + def instrument(name, payload={}, add_result=false) time = Time.now result = yield if block_given? + payload.merge!(:result => result) if add_result @notifier.publish(name, time, Time.now, @id, payload) result end + # The same as instrument, but adds the result as payload. + def instrument!(name, payload={}, &block) + instrument(name, payload, true, &block) + end + private def unique_id SecureRandom.hex(10) -- cgit v1.2.3