Sha256: 8514b0df46ec72442dc9f7f51f56f8c85714a38123882fdb441ef68e74054b4b

Contents?: true

Size: 1.82 KB

Versions: 5

Compression:

Stored size: 1.82 KB

Contents

# typed: true
module Datadog
  module Core
    module Environment
      # Reports Ruby VM cache performance statistics.
      # This currently encompasses cache invalidation counters and is CRuby-specific.
      #
      # JRuby emulates some CRuby global cache statistics, but they are synthetic and don't
      # provide actionable performance information in the same way CRuby does.
      # @see https://github.com/jruby/jruby/issues/4384#issuecomment-267069314
      #
      # TruffleRuby does not have a global runtime cache invalidation cache.
      # @see http://archive.today/2021.09.10-205702/https://medium.com/graalvm/precise-method-and-constant-invalidation-in-truffleruby-4dd56c6bac1a
      module VMCache
        module_function

        # Global constant cache "generation" counter.
        #
        # Whenever a constant creation busts the global constant cache
        # this value is incremented. This has a measurable performance impact
        # and thus show be avoided after application warm up.
        def global_constant_state
          ::RubyVM.stat[:global_constant_state]
        end

        # Global method cache "generation" counter.
        #
        # Whenever a method creation busts the global method cache
        # this value is incremented. This has a measurable performance impact
        # and thus show be avoided after application warm up.
        #
        # Since Ruby 3.0, the method class is kept on a per-class basis,
        # largely mitigating global method cache busting. `global_method_state`
        # is thus not available since Ruby 3.0.
        # @see https://bugs.ruby-lang.org/issues/16614
        def global_method_state
          ::RubyVM.stat[:global_method_state]
        end

        def available?
          defined?(::RubyVM) && ::RubyVM.respond_to?(:stat)
        end
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
ddtrace-1.0.0.beta1 lib/datadog/core/environment/vm_cache.rb
ddtrace-0.54.2 lib/datadog/core/environment/vm_cache.rb
ddtrace-0.54.1 lib/datadog/core/environment/vm_cache.rb
ddtrace-0.54.0 lib/datadog/core/environment/vm_cache.rb
ddtrace-0.53.0 lib/datadog/core/environment/vm_cache.rb