Sha256: 4d2220dd7385cd61271bcc483deba3b32b240729315467357e617c45d6f80a4b

Contents?: true

Size: 1.4 KB

Versions: 2

Compression:

Stored size: 1.4 KB

Contents

# typed: false

module Datadog
  module Profiling
    module Collectors
      # Used to periodically sample threads, recording elapsed CPU-time and Wall-time between samples.
      # Triggering of this component (e.g. deciding when to take a sample) is implemented in
      # Collectors::CpuAndWallTimeWorker.
      # The stack collection itself is handled using the Datadog::Profiling::Collectors::Stack.
      # Almost all of this class is implemented as native code.
      #
      # Methods prefixed with _native_ are implemented in `collectors_cpu_and_wall_time.c`
      class CpuAndWallTime
        def initialize(recorder:, max_frames:, tracer:)
          tracer_context_key = safely_extract_context_key_from(tracer)
          self.class._native_initialize(self, recorder, max_frames, tracer_context_key)
        end

        def inspect
          # Compose Ruby's default inspect with our custom inspect for the native parts
          result = super()
          result[-1] = "#{self.class._native_inspect(self)}>"
          result
        end

        private

        def safely_extract_context_key_from(tracer)
          tracer &&
            tracer.respond_to?(:provider) &&
            # NOTE: instance_variable_get always works, even on nil -- it just returns nil if the variable doesn't exist
            tracer.provider.instance_variable_get(:@context).instance_variable_get(:@key)
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
ddtrace-1.6.1 lib/datadog/profiling/collectors/cpu_and_wall_time.rb
ddtrace-1.6.0 lib/datadog/profiling/collectors/cpu_and_wall_time.rb