Async::Service::SupervisorSourceAsyncServiceSupervisorWorkerController

class WorkerController

Controller for worker operations.

Handles diagnostic operations like memory dumps, thread dumps, scheduler dumps, etc.

Definitions

def initialize(worker)

Initialize the worker controller for the worker.

Implementation

def initialize(worker)
	@worker = worker
end

def scheduler_dump(path: nil, log: nil)

Dump the current fiber scheduler hierarchy.

Generates a hierarchical view of all running fibers and their relationships.

Signature

parameter path String

Optional file path to save the dump.

parameter log String

Optional log message to output.

Implementation

def scheduler_dump(path: nil, log: nil)
	dump(path: path, log: log) do |file|
		Fiber.scheduler.print_hierarchy(file)
	end
end

def memory_dump(path: nil)

Dump the entire object space to a file.

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

Signature

parameter path String

Optional file path to save the dump.

Implementation

def memory_dump(path: nil)
	require "objspace"
	
	dump(path: path, buffer: false) do |file|
		ObjectSpace.dump_all(output: file)
	end
end

def thread_dump(path: nil)

Dump information about all running threads.

Includes thread inspection and backtraces for debugging.

Signature

parameter path String

Optional file path to save the dump.

Implementation

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

def garbage_profile_start

Start garbage collection profiling.

Enables the GC profiler to track garbage collection performance.

Signature

returns Hash

Confirmation that profiling started.

Implementation

def garbage_profile_start
	GC::Profiler.enable
	return {started: true}
end

def garbage_profile_stop(path: nil)

Stop garbage collection profiling and return results.

Disables the GC profiler and returns collected profiling data.

Signature

parameter path String

Optional file path to save the profile.

Implementation

def garbage_profile_stop(path: nil)
	dump(path: path) do |file|
		file.puts GC::Profiler.result
	end
ensure
	GC::Profiler.disable
end