Sha256: 493d428eed83f598051c90b1b416f6b741209cb8d543730f170140c1d46ac3e4

Contents?: true

Size: 1.35 KB

Versions: 6

Compression:

Stored size: 1.35 KB

Contents

# frozen_string_literal: true

module InstrumentAllTheThings
  module Instrumentors
    DEFAULT_GC_STATS_OPTIONS = {
      diffed_stats: %i[
        total_allocated_pages
        total_allocated_objects
        count
      ].freeze
    }.freeze

    # This is to make it easier to spec since other
    # gems may call this
    GC_STAT_GETTER = -> { GC.stat }

    GC_STATS_WRAPPER = lambda do |opts, context|
      opts = if opts == true
               DEFAULT_GC_STATS_OPTIONS
             else
               DEFAULT_GC_STATS_OPTIONS.merge(opts)
            end

      report_value = proc do |klass, stat_name, value|
        InstrumentAllTheThings.stat_reporter.histogram(
          context.stats_name(klass) + ".#{stat_name}_change",
          value
        )
      end

      lambda do |klass, next_blk, actual_code|
        starting_values = GC_STAT_GETTER.call.slice(*opts[:diffed_stats])
        next_blk.call(klass, actual_code).tap do
          new_values = GC_STAT_GETTER.call.slice(*opts[:diffed_stats])

          diff = new_values.merge(starting_values) do |_, new_value, starting_value|
            new_value - starting_value
          end

          if (span = InstrumentAllTheThings.tracer.active_span)
            span.set_tag('gc_stats', diff)
          end

          diff.each { |s, v| report_value.call(klass, s, v) }
        end
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
instrument_all_the_things-1.2.0 lib/instrument_all_the_things/instrumentors/gc_stats.rb
instrument_all_the_things-1.1.1 lib/instrument_all_the_things/instrumentors/gc_stats.rb
instrument_all_the_things-1.1.0 lib/instrument_all_the_things/instrumentors/gc_stats.rb
instrument_all_the_things-1.0.4 lib/instrument_all_the_things/instrumentors/gc_stats.rb
instrument_all_the_things-1.0.3 lib/instrument_all_the_things/instrumentors/gc_stats.rb
instrument_all_the_things-1.0.2 lib/instrument_all_the_things/instrumentors/gc_stats.rb