Sha256: 0fd7a7423c1cfd2e6ce29bf983967ae25118ab2a73d13017e98e2d20b49b76b6

Contents?: true

Size: 1.88 KB

Versions: 19

Compression:

Stored size: 1.88 KB

Contents

# frozen_string_literal: true

module Datadog
  module Profiling
    module Collectors
      # Used to trigger sampling of threads, based on external "events", such as:
      # * periodic timer for cpu-time and wall-time
      # * VM garbage collection events
      # * VM object allocation events
      # Triggering of this component (e.g. watching for the above "events") is implemented by
      # 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_thread_context.c`
      class ThreadContext
        def initialize(
          recorder:,
          max_frames:,
          tracer:,
          endpoint_collection_enabled:,
          timeline_enabled:,
          allocation_type_enabled: true
        )
          tracer_context_key = safely_extract_context_key_from(tracer)
          self.class._native_initialize(
            self,
            recorder,
            max_frames,
            tracer_context_key,
            endpoint_collection_enabled,
            timeline_enabled,
            allocation_type_enabled,
          )
        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

        def reset_after_fork
          self.class._native_reset_after_fork(self)
        end

        private

        def safely_extract_context_key_from(tracer)
          provider = tracer && tracer.respond_to?(:provider) && tracer.provider

          return unless provider

          context = provider.instance_variable_get(:@context)
          context && context.instance_variable_get(:@key)
        end
      end
    end
  end
end

Version data entries

19 entries across 19 versions & 2 rubygems

Version Path
datadog-2.2.0 lib/datadog/profiling/collectors/thread_context.rb
ddtrace-1.23.3 lib/datadog/profiling/collectors/thread_context.rb
ddtrace-1.23.2 lib/datadog/profiling/collectors/thread_context.rb
datadog-2.1.0 lib/datadog/profiling/collectors/thread_context.rb
datadog-2.0.0 lib/datadog/profiling/collectors/thread_context.rb
ddtrace-1.23.1 lib/datadog/profiling/collectors/thread_context.rb
datadog-2.0.0.beta2 lib/datadog/profiling/collectors/thread_context.rb
ddtrace-1.22.0 lib/datadog/profiling/collectors/thread_context.rb
datadog-2.0.0.beta1 lib/datadog/profiling/collectors/thread_context.rb
ddtrace-1.21.1 lib/datadog/profiling/collectors/thread_context.rb
ddtrace-1.21.0 lib/datadog/profiling/collectors/thread_context.rb
ddtrace-1.20.0 lib/datadog/profiling/collectors/thread_context.rb
ddtrace-1.19.0 lib/datadog/profiling/collectors/thread_context.rb
ddtrace-1.18.0 lib/datadog/profiling/collectors/thread_context.rb
ddtrace-1.17.0 lib/datadog/profiling/collectors/thread_context.rb
ddtrace-1.16.2 lib/datadog/profiling/collectors/thread_context.rb
ddtrace-1.16.1 lib/datadog/profiling/collectors/thread_context.rb
ddtrace-1.16.0 lib/datadog/profiling/collectors/thread_context.rb
ddtrace-1.15.0 lib/datadog/profiling/collectors/thread_context.rb