Sha256: e635707e36085167b3f99363a0a16d0ec1c0dbd220acf01dd3fac4edd24d4ee7

Contents?: true

Size: 1.71 KB

Versions: 2

Compression:

Stored size: 1.71 KB

Contents

# encoding: utf-8
# This file is distributed under New Relic's license terms.
# See https://github.com/newrelic/rpm/blob/master/LICENSE for complete details.

module Performance
  module Instrumentation
    class MRIGCStats < Instrumentor
      platforms :mri_20, :mri_21, :mri_22, :mri_23, :mri_24
      on_by_default

      def before(*)
        @stats_before = GC.stat
      end

      def after(*)
        @stats_after = GC.stat
      end

      def results
        heap_live_before = @stats_before[:heap_live_slots] || @stats_before[:heap_live_num] || @stats_before[:heap_live_slot]
        heap_live_after  = @stats_after[:heap_live_slots]  || @stats_after[:heap_live_num]  || @stats_after[:heap_live_slot]

        res = {
          :gc_runs      => @stats_after[:count] - @stats_before[:count],
          :live_objects => heap_live_after      - heap_live_before
        }
        allocs_before = @stats_before[:total_allocated_objects] || @stats_before[:total_allocated_object]
        allocs_after  = @stats_after[:total_allocated_objects]  || @stats_after[:total_allocated_object]
        res[:allocations] = allocs_after - allocs_before
        res
      end
    end

    class REEGCStats < Instrumentor
      platforms :ree
      on_by_default

      def before(*)
        @allocations_before = ObjectSpace.allocated_objects
        @live_objects_before = ObjectSpace.live_objects
      end

      def after(*)
        @allocations_after = ObjectSpace.allocated_objects
        @live_objects_after = ObjectSpace.live_objects
      end

      def results
        {
          :allocations => @allocations_after - @allocations_before,
          :live_objects => @live_objects_after - @live_objects_before,
        }
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
newrelic_rpm-4.1.0.333 test/performance/lib/performance/instrumentation/gc_stats.rb
newrelic_rpm-4.0.0.332 test/performance/lib/performance/instrumentation/gc_stats.rb