Class: Datadog::Profiling::Scheduler

Inherits:
Core::Worker show all
Includes:
Core::Workers::Polling
Defined in:
lib/datadog/profiling/scheduler.rb

Overview

Periodically (every DEFAULT_INTERVAL_SECONDS) takes a profile from the ‘Exporter` and reports it using the configured transport. Runs on its own background thread.

Constant Summary collapse

DEFAULT_INTERVAL_SECONDS =
60
MINIMUM_INTERVAL_SECONDS =
0
DEFAULT_FLUSH_JITTER_MAXIMUM_SECONDS =

We sleep for at most this duration seconds before reporting data to avoid multi-process applications all reporting profiles at the exact same time

3

Constants included from Core::Workers::Polling

Core::Workers::Polling::SHUTDOWN_TIMEOUT

Instance Attribute Summary

Attributes inherited from Core::Worker

#task

Instance Method Summary collapse

Methods included from Core::Workers::Polling

#enabled=, #enabled?, included, #stop

Constructor Details

#initialize(exporter:, transport:, fork_policy: Core::Workers::Async::Thread::FORK_POLICY_RESTART, interval: DEFAULT_INTERVAL_SECONDS, enabled: true) ⇒ Scheduler

Returns a new instance of Scheduler.



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/datadog/profiling/scheduler.rb', line 28

def initialize(
  exporter:,
  transport:,
  fork_policy: Core::Workers::Async::Thread::FORK_POLICY_RESTART, # Restart in forks by default
  interval: DEFAULT_INTERVAL_SECONDS,
  enabled: true
)
  @exporter = exporter
  @transport = transport

  # Workers::Async::Thread settings
  self.fork_policy = fork_policy

  # Workers::IntervalLoop settings
  self.loop_base_interval = interval

  # Workers::Polling settings
  self.enabled = enabled
end

Instance Method Details

#loop_wait_before_first_iteration?Boolean

Configure Workers::IntervalLoop to not report immediately when scheduler starts

When a scheduler gets created (or reset), we don’t want it to immediately try to flush; we want it to wait for the loop wait time first. This avoids an issue where the scheduler reported a mostly-empty profile if the application just started but this thread took a bit longer so there’s already profiling data in the exporter.

Returns:

  • (Boolean)


72
73
74
# File 'lib/datadog/profiling/scheduler.rb', line 72

def loop_wait_before_first_iteration?
  true
end

#performObject



52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/datadog/profiling/scheduler.rb', line 52

def perform
  # A profiling flush may be called while the VM is shutting down, to report the last profile. When we do so,
  # we impose a strict timeout. This means this last profile may or may not be sent, depending on if the flush can
  # successfully finish in the strict timeout.
  # This can be somewhat confusing (why did it not get reported?), so let's at least log what happened.
  interrupted = true

  begin
    flush_and_wait
    interrupted = false
  ensure
    Datadog.logger.debug('#flush was interrupted or failed before it could complete') if interrupted
  end
end

#reset_after_forkObject



80
81
82
# File 'lib/datadog/profiling/scheduler.rb', line 80

def reset_after_fork
  exporter.reset_after_fork
end

#startObject



48
49
50
# File 'lib/datadog/profiling/scheduler.rb', line 48

def start
  perform
end

#work_pending?Boolean

Returns:

  • (Boolean)


76
77
78
# File 'lib/datadog/profiling/scheduler.rb', line 76

def work_pending?
  exporter.can_flush?
end