Created
August 5, 2021 18:31
-
-
Save rlipscombe/15fd66afc80064f00e44994cb742aa91 to your computer and use it in GitHub Desktop.
Processes to graphviz
This file contains 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
def to_dot(pid, path) do | |
# Starting with the given process, find all of the processes that it's linked to/from, and that it's monitoring/monitored; put them in the dot file. | |
f = File.open!(path, [:write]) | |
IO.write(f, "digraph G {\n") | |
IO.write(f, "concentrate=true") | |
seen = MapSet.new() | |
to_dot(pid, f, seen) | |
IO.write(f, "}\n") | |
File.close(f) | |
end | |
defp to_dot(pid, f, seen) do | |
if MapSet.member?(seen, pid) do | |
:ok | |
else | |
seen = MapSet.put(seen, pid) | |
IO.write(f, "\"#{inspect(pid)}\"\n") | |
info = Process.info(pid, [:links, :monitors, :monitored_by]) | |
for link when is_pid(link) <- info[:links] do | |
IO.write(f, "\"#{inspect(pid)}\" -> \"#{inspect(link)}\"\n") | |
to_dot(link, f, seen) | |
end | |
for {:process, m} <- info[:monitors] do | |
IO.write(f, "\"#{inspect(pid)}\" -> \"#{inspect(m)}\" [style=dashed]\n") | |
to_dot(m, f, seen) | |
end | |
# for {:process, m} <- info[:monitored_by] do | |
# IO.write(f, "\"#{inspect(m)}\" -> \"#{inspect(pid)}\" [style=dashed]\n") | |
# to_dot(m, f, seen) | |
# end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment