From 202fb79e8686ee127fe49497c979cfc9c9d985d5 Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Mon, 19 Jul 2010 13:44:11 -0700 Subject: reusing the time instrumentation from the instrumenter rather than Benchmark. [#5098 state:open] --- .../lib/active_support/notifications/instrumenter.rb | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'activesupport') diff --git a/activesupport/lib/active_support/notifications/instrumenter.rb b/activesupport/lib/active_support/notifications/instrumenter.rb index 34bccb83d0..ff2b19bc65 100644 --- a/activesupport/lib/active_support/notifications/instrumenter.rb +++ b/activesupport/lib/active_support/notifications/instrumenter.rb @@ -9,23 +9,30 @@ 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={}) - time = Time.now + @started = Time.now begin yield(payload) if block_given? rescue Exception => e payload[:exception] = [e.class.name, e.message] raise e ensure - @notifier.publish(name, time, Time.now, @id, payload) + @finished = Time.now + @notifier.publish(name, @started, @finished, @id, payload) end end + def elapsed + 1000.0 * @finished.to_f - @started.to_f + end + private def unique_id SecureRandom.hex(10) -- cgit v1.2.3