module Profiler

Nested Classes and Modules

class Capture

Represents a running profiler capture.

module ForkHandler

Private module that hooks into Process._fork to handle fork events.

module ThreadLocalProfiler

Manages the active profiler so it can be stopped after a fork.

class Watchdog

Samples stacks while a fiber runs without switching back to the event loop.

Definitions

::Thread.attr_accessor :fiber_profiler_capture

Thread-local storage for the active profiler, shared by both implementations.

def self.default

The default profiler to use, if any.

Set FIBER_PROFILER to watchdog, capture, or false. When unset, the legacy FIBER_PROFILER_CAPTURE=true setting enables capture mode.

Signature

returns Capture | Watchdog | Nil
raises ArgumentError

If the requested mode is unknown.

Implementation

def self.default
	case mode = ENV["FIBER_PROFILER"]
	when nil
		Capture.default
	when "capture"
		Capture.new
	when "watchdog"
		require_relative "profiler/watchdog"
		Watchdog.default
	when "false"
		nil
	else
		raise ArgumentError, "Unknown FIBER_PROFILER mode: #{mode.inspect} (expected watchdog, capture, or false)"
	end
end

def self.capture

Execute the given block with the Fiber::Profiler.default profiler, if any.

Signature

yields {...}

The block to execute.

Implementation

def self.capture
	if capture = self.default
		begin
			capture.start
			
			yield
		ensure
			capture.stop
		end
	else
		yield
	end
end