Created
December 9, 2025 21:22
-
-
Save nicholasjhenry/1ca48970c60dc92952984453f96a28d1 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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