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:, allocation_type_enabled: true) ⇒ 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
# File 'lib/datadog/profiling/collectors/thread_context.rb', line 17

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

Class Method Details

._native_initializeObject



170
171
172
173
174
175
176
177
178
179
# File 'ext/datadog_profiling_native_extension/collectors_thread_context.c', line 170

static VALUE _native_initialize(
  VALUE self,
  VALUE collector_instance,
  VALUE recorder_instance,
  VALUE max_frames,
  VALUE tracer_context_key,
  VALUE endpoint_collection_enabled,
  VALUE timeline_enabled,
  VALUE allocation_type_enabled
);

._native_inspectObject



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

static VALUE _native_inspect(VALUE self, VALUE collector_instance);

._native_reset_after_forkObject



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

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

Instance Method Details

#inspectObject



37
38
39
40
41
42
# File 'lib/datadog/profiling/collectors/thread_context.rb', line 37

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



44
45
46
# File 'lib/datadog/profiling/collectors/thread_context.rb', line 44

def reset_after_fork
  self.class._native_reset_after_fork(self)
end