Class: Async::Service::Supervisor::WorkerController

Inherits:
Bus::Controller
  • Object
show all
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

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

#garbage_profile_startObject

Start garbage collection profiling.

Enables the GC profiler to track garbage collection performance.



87
88
89
90
# File 'lib/async/service/supervisor/worker_controller.rb', line 87

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.



97
98
99
100
101
102
103
# File 'lib/async/service/supervisor/worker_controller.rb', line 97

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) ⇒ Object

Dump the entire object space to a file.

This is a heavyweight operation that dumps all objects in the heap.



60
61
62
63
64
65
66
# File 'lib/async/service/supervisor/worker_controller.rb', line 60

def memory_dump(path: nil)
	require "objspace"
	
	dump(path: path, buffer: false) do |file|
		ObjectSpace.dump_all(output: file)
	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.



114
115
116
# File 'lib/async/service/supervisor/worker_controller.rb', line 114

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.



73
74
75
76
77
78
79
80
# File 'lib/async/service/supervisor/worker_controller.rb', line 73

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