diff options
author | José Valim <jose.valim@gmail.com> | 2010-01-13 22:28:18 +0100 |
---|---|---|
committer | José Valim <jose.valim@gmail.com> | 2010-01-14 01:07:03 +0100 |
commit | 7c3573f32757e9c4c6b6140499a3e7dfe2d335b1 (patch) | |
tree | 957230806ab62a1875a789c285337817cb610c79 /activesupport/lib/active_support | |
parent | 2a6bc1263e99060897b53a8c806916d198eab572 (diff) | |
download | rails-7c3573f32757e9c4c6b6140499a3e7dfe2d335b1.tar.gz rails-7c3573f32757e9c4c6b6140499a3e7dfe2d335b1.tar.bz2 rails-7c3573f32757e9c4c6b6140499a3e7dfe2d335b1.zip |
Add instrument! to notifications which adds the result to the payload.
Diffstat (limited to 'activesupport/lib/active_support')
-rw-r--r-- | activesupport/lib/active_support/notifications.rb | 2 | ||||
-rw-r--r-- | activesupport/lib/active_support/notifications/instrumenter.rb | 10 |
2 files changed, 10 insertions, 2 deletions
diff --git a/activesupport/lib/active_support/notifications.rb b/activesupport/lib/active_support/notifications.rb index 3e96decb8c..a1383bb478 100644 --- a/activesupport/lib/active_support/notifications.rb +++ b/activesupport/lib/active_support/notifications.rb @@ -45,7 +45,7 @@ module ActiveSupport class << self attr_writer :notifier delegate :publish, :subscribe, :to => :notifier - delegate :instrument, :to => :instrumenter + delegate :instrument, :instrument!, :to => :instrumenter def notifier @notifier ||= Notifier.new 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) |