diff options
author | José Valim <jose.valim@gmail.com> | 2010-07-24 10:22:22 +0200 |
---|---|---|
committer | José Valim <jose.valim@gmail.com> | 2010-07-24 10:22:22 +0200 |
commit | 834bd23a07a84ff631da1ded37c643a3a371cb9a (patch) | |
tree | ae538e553341baa1bb310e9686a2f07ed319e1c1 /activesupport | |
parent | 85980852a03f8e01c4079e21a429589380cf0d64 (diff) | |
download | rails-834bd23a07a84ff631da1ded37c643a3a371cb9a.tar.gz rails-834bd23a07a84ff631da1ded37c643a3a371cb9a.tar.bz2 rails-834bd23a07a84ff631da1ded37c643a3a371cb9a.zip |
Get rid of instrumenter.elapsed.
Diffstat (limited to 'activesupport')
-rw-r--r-- | activesupport/lib/active_support/notifications/instrumenter.rb | 12 | ||||
-rw-r--r-- | activesupport/test/notifications_test.rb | 9 |
2 files changed, 3 insertions, 18 deletions
diff --git a/activesupport/lib/active_support/notifications/instrumenter.rb b/activesupport/lib/active_support/notifications/instrumenter.rb index 713d5a5f25..441fefb491 100644 --- a/activesupport/lib/active_support/notifications/instrumenter.rb +++ b/activesupport/lib/active_support/notifications/instrumenter.rb @@ -9,30 +9,24 @@ module ActiveSupport def initialize(notifier) @id = unique_id @notifier = notifier - @started = nil - @finished = nil end # 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={}) + started = Time.now + begin - @started = Time.now yield rescue Exception => e payload[:exception] = [e.class.name, e.message] raise e ensure - @finished = Time.now - @notifier.publish(name, @started, @finished, @id, payload) + @notifier.publish(name, started, Time.now, @id, payload) end end - def elapsed - 1000.0 * (@finished.to_f - @started.to_f) - end - private def unique_id SecureRandom.hex(10) 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 |