Skip to content

Instantly share code, notes, and snippets.

@nicholasjhenry
Created December 9, 2025 21:22
Show Gist options
  • Select an option

  • Save nicholasjhenry/1ca48970c60dc92952984453f96a28d1 to your computer and use it in GitHub Desktop.

Select an option

Save nicholasjhenry/1ca48970c60dc92952984453f96a28d1 to your computer and use it in GitHub Desktop.
defmodule SupervisionTreeViz do
def to_dot(supervisor) do
edges = build_edges(supervisor, [])
"""
digraph supervision_tree {
node [shape=box, style=rounded];
#{Enum.join(edges, "\n ")}
}
"""
end
defp build_edges(supervisor, acc) do
children = Supervisor.which_children(supervisor)
Enum.reduce(children, acc, fn {id, pid, type, _modules}, edges ->
parent_name = inspect(supervisor)
child_name = "#{id}_#{inspect(pid)}"
edge = ~s("#{parent_name}" -> "#{child_name}";)
case type do
:supervisor when is_pid(pid) ->
build_edges(pid, [edge | edges])
_ ->
[edge | edges]
end
end)
end
end
# Usage in IEx:
File.write!("sup_tree.dot", SupervisionTreeViz.to_dot(YourApp.Supervisor))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment