Sha256: 581b862d16c0dffb8a9edd49da3417381665f2d532e3994a5b025b740a20c6ee

Contents?: true

Size: 1.91 KB

Versions: 1

Compression:

Stored size: 1.91 KB

Contents

module PlainApm
  module Extensions
    module ActiveSupport
      module Event
        def start!
          super
          @utc_start = utc_now
          @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

        def utc_time
          @utc_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

        def utc_now
          Time.now.to_f
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
plain_apm-0.10.2 lib/plain_apm/extensions/active_support/event.rb