Module: FiberAudit::Runtime::SchedulerSnapshotCapture

Defined in:
lib/fiber_audit/runtime/scheduler_snapshot.rb

Overview

Captures immutable scheduler snapshot at the current point in time. This is called at operation start to provide immutable context.

Class Method Summary collapse

Class Method Details

.captureObject



64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# File 'lib/fiber_audit/runtime/scheduler_snapshot.rb', line 64

def capture
  scheduler = Fiber.scheduler
  scheduler_present = !scheduler.nil?

  current_fiber = Fiber.current
  fiber_blocking = current_fiber.respond_to?(:blocking?) ? current_fiber.blocking? : nil

  # Query scheduler capabilities if present
  io_select_supported = nil
  process_wait_supported = nil
  address_resolve_supported = nil

  if scheduler_present
    io_select_supported = scheduler.respond_to?(:io_select)
    process_wait_supported = scheduler.respond_to?(:process_wait)
    address_resolve_supported = scheduler.respond_to?(:address_resolve)
  end

  SchedulerSnapshot.new(
    scheduler_present: scheduler_present,
    fiber_blocking: fiber_blocking,
    scheduler_io_select_supported: io_select_supported,
    scheduler_process_wait_supported: process_wait_supported,
    scheduler_address_resolve_supported: address_resolve_supported
  )
rescue StandardError
  # Fail open without inventing scheduler or Fiber state.
  SchedulerSnapshot.new(scheduler_present: nil, fiber_blocking: nil)
end