Class: Datadog::Profiling::Collectors::ThreadContext

Inherits:
Object
  • Object
show all
Defined in:
lib/datadog/profiling/collectors/thread_context.rb,
ext/datadog_profiling_native_extension/collectors_thread_context.c

Overview

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`

Defined Under Namespace

Modules: Testing

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(recorder:, max_frames:, tracer:, endpoint_collection_enabled:, timeline_enabled:, waiting_for_gvl_threshold_ns:, otel_context_enabled:) ⇒ ThreadContext

Returns a new instance of ThreadContext.



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/datadog/profiling/collectors/thread_context.rb', line 17

def initialize(
  recorder:,
  max_frames:,
  tracer:,
  endpoint_collection_enabled:,
  timeline_enabled:,
  waiting_for_gvl_threshold_ns:,
  otel_context_enabled:
)
  tracer_context_key = safely_extract_context_key_from(tracer)
  self.class._native_initialize(
    self_instance: self,
    recorder: recorder,
    max_frames: max_frames,
    tracer_context_key: tracer_context_key,
    endpoint_collection_enabled: endpoint_collection_enabled,
    timeline_enabled: timeline_enabled,
    waiting_for_gvl_threshold_ns: waiting_for_gvl_threshold_ns,
    otel_context_enabled: otel_context_enabled,
  )
end

Class Method Details

._native_initializeObject



205
# File 'ext/datadog_profiling_native_extension/collectors_thread_context.c', line 205

static VALUE _native_initialize(int argc, VALUE *argv, DDTRACE_UNUSED VALUE _self);

._native_inspectObject



237
# File 'ext/datadog_profiling_native_extension/collectors_thread_context.c', line 237

static VALUE _native_inspect(VALUE self, VALUE collector_instance);

._native_reset_after_forkObject



257
# File 'ext/datadog_profiling_native_extension/collectors_thread_context.c', line 257

static VALUE _native_reset_after_fork(DDTRACE_UNUSED VALUE self, VALUE collector_instance);

.for_testing(recorder:, max_frames: 400, tracer: nil, endpoint_collection_enabled: false, timeline_enabled: false, waiting_for_gvl_threshold_ns: 10_000_000, otel_context_enabled: false, **options) ⇒ Object



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/datadog/profiling/collectors/thread_context.rb', line 39

def self.for_testing(
  recorder:,
  max_frames: 400,
  tracer: nil,
  endpoint_collection_enabled: false,
  timeline_enabled: false,
  waiting_for_gvl_threshold_ns: 10_000_000,
  otel_context_enabled: false,
  **options
)
  new(
    recorder: recorder,
    max_frames: max_frames,
    tracer: tracer,
    endpoint_collection_enabled: endpoint_collection_enabled,
    timeline_enabled: timeline_enabled,
    waiting_for_gvl_threshold_ns: waiting_for_gvl_threshold_ns,
    otel_context_enabled: otel_context_enabled,
    **options,
  )
end

Instance Method Details

#inspectObject



61
62
63
64
65
66
# File 'lib/datadog/profiling/collectors/thread_context.rb', line 61

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

#reset_after_forkObject



68
69
70
# File 'lib/datadog/profiling/collectors/thread_context.rb', line 68

def reset_after_fork
  self.class._native_reset_after_fork(self)
end