Wanting a quick and easy way to get the state of all workers managed by a supervisor process – use case is for debugging a live running application.
Poked around a bit, and worked this up:
def get_worker_states(supervisor) do
Enum.each(Supervisor.which_children(supervisor), fn({_id, pid, type, _modules}) ->
if type == :worker do
IO.puts "----------------------------------"
IO.puts inspect(:sys.get_state(pid, 1000))
IO.puts "----------------------------------"
end
end)
end
Seems to work OK.
Wondering if anybody has thoughts on a better/more elegant approach?