lib/active_support/notifications/instrumenter.rb in activesupport-7.1.5 vs lib/active_support/notifications/instrumenter.rb in activesupport-7.2.0.beta1

- old
+ new

@@ -115,10 +115,12 @@ @end = ending ? ending.to_f * 1_000.0 : ending @cpu_time_start = 0.0 @cpu_time_finish = 0.0 @allocation_count_start = 0 @allocation_count_finish = 0 + @gc_time_start = 0 + @gc_time_finish = 0 end def time @time / 1000.0 if @time end @@ -142,16 +144,18 @@ # Record information at the time this event starts def start! @time = now @cpu_time_start = now_cpu + @gc_time_start = now_gc @allocation_count_start = now_allocations end # Record information at the time this event finishes def finish! @cpu_time_finish = now_cpu + @gc_time_finish = now_gc @end = now @allocation_count_finish = now_allocations end # Returns the CPU time (in milliseconds) passed between the call to @@ -171,32 +175,21 @@ # the call to #finish!. def allocations @allocation_count_finish - @allocation_count_start end - def children # :nodoc: - ActiveSupport.deprecator.warn <<~EOM - ActiveSupport::Notifications::Event#children is deprecated and will - be removed in Rails 7.2. - EOM - [] + # Returns the time spent in GC (in milliseconds) between the call to #start! + # and the call to #finish! + def gc_time + (@gc_time_finish - @gc_time_start) / 1_000_000.0 end - def parent_of?(event) # :nodoc: - ActiveSupport.deprecator.warn <<~EOM - ActiveSupport::Notifications::Event#parent_of? is deprecated and will - be removed in Rails 7.2. - EOM - start = (time - event.time) * 1000 - start <= 0 && (start + duration >= event.duration) - end - # Returns the difference in milliseconds between when the execution of the # event started and when it ended. # - # ActiveSupport::Notifications.subscribe('wait') do |*args| - # @event = ActiveSupport::Notifications::Event.new(*args) + # ActiveSupport::Notifications.subscribe('wait') do |event| + # @event = event # end # # ActiveSupport::Notifications.instrument('wait') do # sleep 1 # end @@ -216,11 +209,21 @@ def now_cpu Process.clock_gettime(Process::CLOCK_THREAD_CPUTIME_ID, :float_millisecond) end rescue - def now_cpu # rubocop:disable Lint/DuplicateMethods + def now_cpu 0.0 + end + end + + if GC.respond_to?(:total_time) + def now_gc + GC.total_time + end + else + def now_gc + 0 end end if GC.stat.key?(:total_allocated_objects) def now_allocations