aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/lib/active_support/notifications/instrumenter.rb
diff options
context:
space:
mode:
Diffstat (limited to 'activesupport/lib/active_support/notifications/instrumenter.rb')
-rw-r--r--activesupport/lib/active_support/notifications/instrumenter.rb16
1 files changed, 7 insertions, 9 deletions
diff --git a/activesupport/lib/active_support/notifications/instrumenter.rb b/activesupport/lib/active_support/notifications/instrumenter.rb
index 7e89402822..441fefb491 100644
--- a/activesupport/lib/active_support/notifications/instrumenter.rb
+++ b/activesupport/lib/active_support/notifications/instrumenter.rb
@@ -15,14 +15,15 @@ module ActiveSupport
# 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?
+ yield
rescue Exception => e
payload[:exception] = [e.class.name, e.message]
raise e
ensure
- @notifier.publish(name, time, Time.now, @id, payload)
+ @notifier.publish(name, started, Time.now, @id, payload)
end
end
@@ -33,7 +34,7 @@ module ActiveSupport
end
class Event
- attr_reader :name, :time, :end, :transaction_id, :payload
+ attr_reader :name, :time, :end, :transaction_id, :payload, :duration
def initialize(name, start, ending, transaction_id, payload)
@name = name
@@ -41,14 +42,11 @@ module ActiveSupport
@time = start
@transaction_id = transaction_id
@end = ending
- end
-
- def duration
- @duration ||= 1000.0 * (@end - @time)
+ @duration = 1000.0 * (@end - @time)
end
def parent_of?(event)
- start = (self.time - event.time) * 1000
+ start = (time - event.time) * 1000
start <= 0 && (start + duration >= event.duration)
end
end