Sha256: 2193f2b9073c5dea1bc0119da068bd8a4c75424f451be0c9d5c04ee8fd1b8a63

Contents?: true

Size: 1.41 KB

Versions: 13

Compression:

Stored size: 1.41 KB

Contents

module Datadog
  module Profiling
    # Profiling entry point, which coordinates the worker and scheduler threads
    class Profiler
      include Datadog::Core::Utils::Forking

      private

      attr_reader :worker, :scheduler

      public

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

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

        worker.start(on_failure_proc: proc { component_failed(:worker) })
        scheduler.start(on_failure_proc: proc { component_failed(:scheduler) })
      end

      def shutdown!
        Datadog.logger.debug('Shutting down profiler')

        stop_worker
        stop_scheduler
      end

      private

      def stop_worker
        worker.stop
      end

      def stop_scheduler
        scheduler.enabled = false
        scheduler.stop(true)
      end

      def component_failed(failed_component)
        Datadog.logger.warn(
          "Detected issue with profiler (#{failed_component} component), stopping profiling. " \
          'See previous log messages for details.'
        )

        if failed_component == :worker
          stop_scheduler
        elsif failed_component == :scheduler
          stop_worker
        else
          raise ArgumentError, "Unexpected failed_component: #{failed_component.inspect}"
        end
      end
    end
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
ddtrace-1.23.3 lib/datadog/profiling/profiler.rb
ddtrace-1.23.2 lib/datadog/profiling/profiler.rb
ddtrace-1.23.1 lib/datadog/profiling/profiler.rb
ddtrace-1.22.0 lib/datadog/profiling/profiler.rb
ddtrace-1.21.1 lib/datadog/profiling/profiler.rb
ddtrace-1.21.0 lib/datadog/profiling/profiler.rb
ddtrace-1.20.0 lib/datadog/profiling/profiler.rb
ddtrace-1.19.0 lib/datadog/profiling/profiler.rb
ddtrace-1.18.0 lib/datadog/profiling/profiler.rb
ddtrace-1.17.0 lib/datadog/profiling/profiler.rb
ddtrace-1.16.2 lib/datadog/profiling/profiler.rb
ddtrace-1.16.1 lib/datadog/profiling/profiler.rb
ddtrace-1.16.0 lib/datadog/profiling/profiler.rb