diff options
author | José Valim <jose.valim@gmail.com> | 2010-07-25 20:46:42 +0200 |
---|---|---|
committer | José Valim <jose.valim@gmail.com> | 2010-07-25 20:46:42 +0200 |
commit | ff0d842454571d78addd1fe9d4f232b600881b1a (patch) | |
tree | a9c07676d888d14ab5f2298dfe676fbb0ab3eb26 /activesupport | |
parent | 0d0e79398308e6147e59d99a48c7e6d952e5848c (diff) | |
download | rails-ff0d842454571d78addd1fe9d4f232b600881b1a.tar.gz rails-ff0d842454571d78addd1fe9d4f232b600881b1a.tar.bz2 rails-ff0d842454571d78addd1fe9d4f232b600881b1a.zip |
Revert the previous three commits.
* AS::Notifications#instrument should not measure anything, it is not its responsibility;
* Adding another argument to AS::Notifications#instrument API needs to be properly discussed;
Diffstat (limited to 'activesupport')
-rw-r--r-- | activesupport/lib/active_support/notifications.rb | 16 | ||||
-rw-r--r-- | activesupport/lib/active_support/notifications/instrumenter.rb | 11 | ||||
-rw-r--r-- | activesupport/test/notifications_test.rb | 9 |
3 files changed, 7 insertions, 29 deletions
diff --git a/activesupport/lib/active_support/notifications.rb b/activesupport/lib/active_support/notifications.rb index d65431a943..886d7183eb 100644 --- a/activesupport/lib/active_support/notifications.rb +++ b/activesupport/lib/active_support/notifications.rb @@ -47,21 +47,11 @@ module ActiveSupport attr_writer :notifier delegate :publish, :unsubscribe, :to => :notifier - def instrument(name, payload = {}, info = nil) + def instrument(name, payload = {}) if @instrumenters[name] - instrumenter.instrument(name, payload, info) { - yield payload if block_given? - } + instrumenter.instrument(name, payload) { yield payload if block_given? } else - value = nil - if block_given? - if info - info[:elapsed] = Benchmark.ms { value = yield payload } - else - value = yield payload - end - end - value + yield payload if block_given? end end diff --git a/activesupport/lib/active_support/notifications/instrumenter.rb b/activesupport/lib/active_support/notifications/instrumenter.rb index 4fc446fb2b..441fefb491 100644 --- a/activesupport/lib/active_support/notifications/instrumenter.rb +++ b/activesupport/lib/active_support/notifications/instrumenter.rb @@ -14,19 +14,16 @@ module ActiveSupport # Instrument the given block by measuring the time taken to execute it # and publish it. Notice that events get sent even if an error occurs # in the passed-in block - def instrument(name, payload={}, info = nil) + def instrument(name, payload={}) + started = Time.now + begin - started = Time.now yield rescue Exception => e payload[:exception] = [e.class.name, e.message] raise e ensure - finished = Time.now - if info - info[:elapsed] = 1000.0 * (finished.to_f - started.to_f) - end - @notifier.publish(name, started, finished, @id, payload) + @notifier.publish(name, started, Time.now, @id, payload) end end diff --git a/activesupport/test/notifications_test.rb b/activesupport/test/notifications_test.rb index 41e8ca4ae7..9faa11efbc 100644 --- a/activesupport/test/notifications_test.rb +++ b/activesupport/test/notifications_test.rb @@ -172,15 +172,6 @@ module Notifications :exception => ["RuntimeError", "FAIL"]], @events.last.payload end - def test_elapsed - instrument(:something) do - sleep(0.001) - end - - # Elapsed returns duration in ms - assert_in_delta 1, ActiveSupport::Notifications.instrumenter.elapsed, 100 - end - def test_event_is_pushed_even_without_block instrument(:awesome, :payload => "notifications") assert_equal 1, @events.size |