Class: Datadog::Profiling::Profiler

Inherits:
Object
  • Object
show all
Includes:
Core::Utils::Forking
Defined in:
lib/datadog/profiling/profiler.rb

Overview

Profiling entry point, which coordinates the worker and scheduler threads

Instance Method Summary collapse

Methods included from Core::Utils::Forking

#after_fork!, extended, #fork_pid, #forked?, included, #update_fork_pid!

Constructor Details

#initialize(worker:, scheduler:) ⇒ Profiler

Returns a new instance of Profiler.



15
16
17
18
# File 'lib/datadog/profiling/profiler.rb', line 15

def initialize(worker:, scheduler:)
  @worker = worker
  @scheduler = scheduler
end

Instance Method Details

#enabled?Boolean

Returns:

  • (Boolean)


20
21
22
# File 'lib/datadog/profiling/profiler.rb', line 20

def enabled?
  scheduler.running?
end

#shutdown!(report_last_profile: true) ⇒ Object



39
40
41
42
43
44
45
# File 'lib/datadog/profiling/profiler.rb', line 39

def shutdown!(report_last_profile: true)
  Datadog.logger.debug("Shutting down profiler")

  stop_worker
  scheduler.disable_reporting unless report_last_profile
  stop_scheduler
end

#startObject



24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/datadog/profiling/profiler.rb', line 24

def start
  after_fork! do
    worker.reset_after_fork
    scheduler.reset_after_fork
  end

  worker.start(
    on_failure_proc: ->(log_failure: true) do
      # @type var log_failure: bool
      component_failed(:worker, log_failure: log_failure)
    end
  )
  scheduler.start(on_failure_proc: proc { component_failed(:scheduler) })
end