From cb9c86bc8316a9b63599b989df6db6becb4fcb3b Mon Sep 17 00:00:00 2001 From: Vishal Telangre Date: Tue, 16 Apr 2019 03:26:16 +0530 Subject: Fix: #cpu_time doesn't work for a `ActiveSupport::Notifications::Fanout::Subscribers::Timed` subscriber --- activesupport/lib/active_support/notifications/instrumenter.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'activesupport/lib') diff --git a/activesupport/lib/active_support/notifications/instrumenter.rb b/activesupport/lib/active_support/notifications/instrumenter.rb index a03e7e483e..1940b33799 100644 --- a/activesupport/lib/active_support/notifications/instrumenter.rb +++ b/activesupport/lib/active_support/notifications/instrumenter.rb @@ -69,8 +69,8 @@ module ActiveSupport @end = ending @children = [] @duration = nil - @cpu_time_start = nil - @cpu_time_finish = nil + @cpu_time_start = 0 + @cpu_time_finish = 0 @allocation_count_start = 0 @allocation_count_finish = 0 end -- cgit v1.2.3 From f2a80db56b9e8d5b33127356036602431dc08cd5 Mon Sep 17 00:00:00 2001 From: Vishal Telangre Date: Tue, 16 Apr 2019 03:30:24 +0530 Subject: Use monotonic time to record `started` and `finished` time values for an event subscribed by a `ActiveSupport::Notifications::Fanout::Subscribers::Timed` subscriber --- activesupport/lib/active_support/notifications/fanout.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'activesupport/lib') diff --git a/activesupport/lib/active_support/notifications/fanout.rb b/activesupport/lib/active_support/notifications/fanout.rb index c506b35b1e..8812b67f63 100644 --- a/activesupport/lib/active_support/notifications/fanout.rb +++ b/activesupport/lib/active_support/notifications/fanout.rb @@ -180,13 +180,13 @@ module ActiveSupport def start(name, id, payload) timestack = Thread.current[:_timestack] ||= [] - timestack.push Time.now + timestack.push Concurrent.monotonic_time end def finish(name, id, payload) timestack = Thread.current[:_timestack] started = timestack.pop - @delegate.call(name, started, Time.now, id, payload) + @delegate.call(name, started, Concurrent.monotonic_time, id, payload) end end -- cgit v1.2.3 From 547ebcb91e955a1d114c827737c9eb6845a8ca97 Mon Sep 17 00:00:00 2001 From: Vishal Telangre Date: Tue, 16 Apr 2019 03:45:39 +0530 Subject: Remove @duration instance variable since we're not maintaining instances variables such as @cpu_time, @idle_time and @allocations; this reduces one allocation --- activesupport/lib/active_support/notifications/instrumenter.rb | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'activesupport/lib') diff --git a/activesupport/lib/active_support/notifications/instrumenter.rb b/activesupport/lib/active_support/notifications/instrumenter.rb index 1940b33799..12546511a8 100644 --- a/activesupport/lib/active_support/notifications/instrumenter.rb +++ b/activesupport/lib/active_support/notifications/instrumenter.rb @@ -68,7 +68,6 @@ module ActiveSupport @transaction_id = transaction_id @end = ending @children = [] - @duration = nil @cpu_time_start = 0 @cpu_time_finish = 0 @allocation_count_start = 0 @@ -125,7 +124,7 @@ module ActiveSupport # # @event.duration # => 1000.138 def duration - @duration ||= 1000.0 * (self.end - time) + 1000.0 * (self.end - time) end def <<(event) -- cgit v1.2.3