Class: Async::Service::Supervisor::WorkerController
- Inherits:
-
Bus::Controller
- Object
- Bus::Controller
- Async::Service::Supervisor::WorkerController
- Defined in:
- lib/async/service/supervisor/worker_controller.rb
Overview
Controller for worker operations.
Handles diagnostic operations like memory dumps, thread dumps, scheduler dumps, etc.
Instance Method Summary collapse
-
#allocation_trace_start ⇒ Object
Start recording object allocation metadata.
-
#allocation_trace_stop(path:, shapes: true) ⇒ Object
Stop recording allocations, dump the traced heap, and clear the metadata.
-
#garbage_profile_start ⇒ Object
Start garbage collection profiling.
-
#garbage_profile_stop(path: nil) ⇒ Object
Stop garbage collection profiling and return results.
-
#initialize(worker) ⇒ WorkerController
constructor
Initialize the worker controller for the worker.
-
#memory_dump(path: nil, shapes: true) ⇒ Object
Dump the entire object space to a file.
-
#scheduler_dump(path: nil, log: nil) ⇒ Object
Dump the current fiber scheduler hierarchy.
-
#setup_utilization_observer(path, size, offset) ⇒ Object
Setup utilization observer for this worker.
-
#thread_dump(path: nil) ⇒ Object
Dump information about all running threads.
Constructor Details
#initialize(worker) ⇒ WorkerController
Initialize the worker controller for the worker.
17 18 19 |
# File 'lib/async/service/supervisor/worker_controller.rb', line 17 def initialize(worker) @worker = worker end |
Instance Method Details
#allocation_trace_start ⇒ Object
Start recording object allocation metadata.
Allocation tracing is process-global and can add significant overhead.
72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/async/service/supervisor/worker_controller.rb', line 72 def allocation_trace_start require "objspace" raise "Object allocation tracing was already started by this controller!" if @allocation_trace_active raise "Object allocation tracing is already active!" if ObjectSpace.allocation_sourcefile(Object.new) ObjectSpace.trace_object_allocations_start @allocation_trace_active = true return {started: true} end |
#allocation_trace_stop(path:, shapes: true) ⇒ Object
Stop recording allocations, dump the traced heap, and clear the metadata.
88 89 90 91 92 93 94 95 96 97 98 99 100 101 |
# File 'lib/async/service/supervisor/worker_controller.rb', line 88 def allocation_trace_stop(path:, shapes: true) require "objspace" stopped = false raise "Object allocation tracing was not started by this controller!" unless @allocation_trace_active ObjectSpace.trace_object_allocations_stop stopped = true @allocation_trace_active = false memory_dump(path: path, shapes: shapes) ensure ObjectSpace.trace_object_allocations_clear if stopped end |
#garbage_profile_start ⇒ Object
Start garbage collection profiling.
Enables the GC profiler to track garbage collection performance.
122 123 124 125 |
# File 'lib/async/service/supervisor/worker_controller.rb', line 122 def garbage_profile_start GC::Profiler.enable return {started: true} end |
#garbage_profile_stop(path: nil) ⇒ Object
Stop garbage collection profiling and return results.
Disables the GC profiler and returns collected profiling data.
132 133 134 135 136 137 138 |
# File 'lib/async/service/supervisor/worker_controller.rb', line 132 def garbage_profile_stop(path: nil) dump(path: path) do |file| file.puts GC::Profiler.result end ensure GC::Profiler.disable end |
#memory_dump(path: nil, shapes: true) ⇒ Object
Dump the entire object space to a file.
This is a heavyweight operation that dumps all objects in the heap.
61 62 63 64 65 66 67 |
# File 'lib/async/service/supervisor/worker_controller.rb', line 61 def memory_dump(path: nil, shapes: true) require "objspace" dump(path: path, buffer: false) do |file| ObjectSpace.dump_all(output: file, shapes: shapes) end end |
#scheduler_dump(path: nil, log: nil) ⇒ Object
Dump the current fiber scheduler hierarchy.
Generates a hierarchical view of all running fibers and their relationships.
49 50 51 52 53 |
# File 'lib/async/service/supervisor/worker_controller.rb', line 49 def scheduler_dump(path: nil, log: nil) dump(path: path, log: log) do |file| Fiber.scheduler.print_hierarchy(file) end end |
#setup_utilization_observer(path, size, offset) ⇒ Object
Setup utilization observer for this worker.
Delegates to the worker to map the shared memory file and configure its utilization registry. Called by the supervisor via RPC.
149 150 151 |
# File 'lib/async/service/supervisor/worker_controller.rb', line 149 def setup_utilization_observer(path, size, offset) @worker.setup_utilization_observer(path, size, offset) end |
#thread_dump(path: nil) ⇒ Object
Dump information about all running threads.
Includes thread inspection and backtraces for debugging.
108 109 110 111 112 113 114 115 |
# File 'lib/async/service/supervisor/worker_controller.rb', line 108 def thread_dump(path: nil) dump(path: path) do |file| Thread.list.each do |thread| file.puts(thread.inspect) file.puts(thread.backtrace) end end end |