module PlainApm module Extensions module ActiveSupport module Event def start! super @thread_allocation_count_start = now_thread_allocations @gc_time_start = now_gc_time @gc_major_count_start = now_gc_major_count @gc_minor_count_start = now_gc_minor_count end def finish! super @thread_allocation_count_finish = now_thread_allocations @gc_time_finish = now_gc_time @gc_major_count_finish = now_gc_major_count @gc_minor_count_finish = now_gc_minor_count end def thread_allocations @thread_allocation_count_finish - @thread_allocation_count_start end def gc_time @gc_time_finish - @gc_time_start end def gc_major_count @gc_major_count_finish - @gc_major_count_start end def gc_minor_count @gc_minor_count_finish - @gc_minor_count_start end private # Per thread GC counter def now_thread_allocations PlainApm::ObjectTracing.total_thread_allocated_objects end if GC.stat.key?(:major_gc_count) def now_gc_major_count GC.stat(:major_gc_count) end else def now_gc_major_count 0 end end if GC.stat.key?(:minor_gc_count) def now_gc_minor_count GC.stat(:minor_gc_count) end else def now_gc_minor_count 0 end end # Time in ms spent in GC if GC.stat.key?(:time) def now_gc_time GC.stat(:time) end else def now_gc_time 0 end end end end end end