From 6635f8a69c5881e4d48db9df2847eb42aac11dab Mon Sep 17 00:00:00 2001 From: Diaan Engelbrecht Date: Sat, 22 Jun 2024 14:48:59 +0200 Subject: [PATCH 1/2] Added intial call to node text --- lib/kino/process.ex | 4 ++-- test/kino/process_test.exs | 35 ++++++++++++++++++++++++++++------- 2 files changed, 30 insertions(+), 9 deletions(-) diff --git a/lib/kino/process.ex b/lib/kino/process.ex index e091f57f..4a466eee 100644 --- a/lib/kino/process.ex +++ b/lib/kino/process.ex @@ -751,7 +751,7 @@ defmodule Kino.Process do "#{idx}[(\"`#{module_or_atom_to_string(id)}\n**_#{protection}_**`\")]:::ets" end - defp graph_node(%{idx: idx, pid: pid, type: type}) do + defp graph_node(%{idx: idx, id: id, pid: pid, type: type}) do type = if idx == 0 do :root @@ -763,7 +763,7 @@ defmodule Kino.Process do case process_info(pid, :registered_name) do {:registered_name, []} -> case get_label(pid) do - :undefined -> inspect(pid) + :undefined -> format_for_mermaid_graph_node(pid, id) process_label -> format_for_mermaid_graph_node(pid, process_label) end diff --git a/test/kino/process_test.exs b/test/kino/process_test.exs index e6b32e68..e4936545 100644 --- a/test/kino/process_test.exs +++ b/test/kino/process_test.exs @@ -20,9 +20,13 @@ defmodule Kino.ProcessTest do ] = Supervisor.which_children(pid) content = pid |> Kino.Process.sup_tree(render_ets_tables: true) |> mermaid() + agent_pid_text = :erlang.pid_to_list(agent_pid) |> List.to_string() + assert content =~ "0(supervisor_parent):::root ---> 1(ets_owner):::worker" assert content =~ "0(supervisor_parent):::root ---> 2(ets_heir):::worker" - assert content =~ "0(supervisor_parent):::root ---> 3(#{inspect(agent_pid)}):::worker" + + assert content =~ + "0(supervisor_parent):::root ---> 3(\"Agent
#{agent_pid_text}\"):::worker" assert content =~ "1(ets_owner):::worker -- owner --> 4[(\"`test_ets_table\n**_protected_**`\")]:::ets" @@ -33,7 +37,9 @@ defmodule Kino.ProcessTest do content = :supervisor_parent |> Kino.Process.sup_tree(render_ets_tables: true) |> mermaid() assert content =~ "0(supervisor_parent):::root ---> 1(ets_owner):::worker" assert content =~ "0(supervisor_parent):::root ---> 2(ets_heir):::worker" - assert content =~ "0(supervisor_parent):::root ---> 3(#{inspect(agent_pid)}):::worker" + + assert content =~ + "0(supervisor_parent):::root ---> 3(\"Agent
#{agent_pid_text}\"):::worker" assert content =~ "1(ets_owner):::worker -- owner --> 4[(\"`test_ets_table\n**_protected_**`\")]:::ets" @@ -52,15 +58,22 @@ defmodule Kino.ProcessTest do ] = Supervisor.which_children(pid) content = pid |> Kino.Process.sup_tree() |> mermaid() + agent_pid_text = :erlang.pid_to_list(agent_pid) |> List.to_string() assert content =~ "0(supervisor_parent):::root ---> 1(ets_owner):::worker" assert content =~ "0(supervisor_parent):::root ---> 2(ets_heir):::worker" - assert content =~ "0(supervisor_parent):::root ---> 3(#{inspect(agent_pid)}):::worker" + + assert content =~ + "0(supervisor_parent):::root ---> 3(\"Agent
#{agent_pid_text}\"):::worker" + refute content =~ ":::ets" content = :supervisor_parent |> Kino.Process.sup_tree() |> mermaid() assert content =~ "0(supervisor_parent):::root ---> 1(ets_owner):::worker" assert content =~ "0(supervisor_parent):::root ---> 2(ets_heir):::worker" - assert content =~ "0(supervisor_parent):::root ---> 3(#{inspect(agent_pid)}):::worker" + + assert content =~ + "0(supervisor_parent):::root ---> 3(\"Agent
#{agent_pid_text}\"):::worker" + refute content =~ ":::ets" end @@ -81,14 +94,19 @@ defmodule Kino.ProcessTest do }) [_, {_, agent, _, _}] = Supervisor.which_children(pid) + agent_pid_text = :erlang.pid_to_list(agent) |> List.to_string() content = Kino.Process.sup_tree(pid) |> mermaid() assert content =~ "0(supervisor_parent):::root ---> 1(agent_child):::worker" - assert content =~ "0(supervisor_parent):::root ---> 2(#{inspect(agent)}):::worker" + + assert content =~ + "0(supervisor_parent):::root ---> 2(\"Agent
#{agent_pid_text}\"):::worker" content = Kino.Process.sup_tree(:supervisor_parent) |> mermaid() assert content =~ "0(supervisor_parent):::root ---> 1(agent_child):::worker" - assert content =~ "0(supervisor_parent):::root ---> 2(#{inspect(agent)}):::worker" + + assert content =~ + "0(supervisor_parent):::root ---> 2(\"Agent
#{agent_pid_text}\"):::worker" end test "shows supervision tree with children alongside non-started children" do @@ -108,10 +126,13 @@ defmodule Kino.ProcessTest do }) [{:not_started, :undefined, _, _}, {_, agent, _, _}] = Supervisor.which_children(pid) + agent_pid_text = :erlang.pid_to_list(agent) |> List.to_string() content = Kino.Process.sup_tree(pid) |> mermaid() assert content =~ "0(supervisor_parent):::root ---> 1(id: :not_started):::notstarted" - assert content =~ "0(supervisor_parent):::root ---> 2(#{inspect(agent)}):::worker" + + assert content =~ + "0(supervisor_parent):::root ---> 2(\"Agent
#{agent_pid_text}\"):::worker" end # TODO: remove once we require Elixir v1.17.0 From 65c28993e7b85727f68d4b9a81350dc92be72119 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Mon, 24 Jun 2024 12:14:56 +0200 Subject: [PATCH 2/2] Update lib/kino/process.ex MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Jonatan KÅ‚osko --- lib/kino/process.ex | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/lib/kino/process.ex b/lib/kino/process.ex index 4a466eee..e3e7abd3 100644 --- a/lib/kino/process.ex +++ b/lib/kino/process.ex @@ -763,8 +763,16 @@ defmodule Kino.Process do case process_info(pid, :registered_name) do {:registered_name, []} -> case get_label(pid) do - :undefined -> format_for_mermaid_graph_node(pid, id) - process_label -> format_for_mermaid_graph_node(pid, process_label) + :undefined -> + if idx == 0 do + inspect(pid) + else + # Use worker/supervisor id as label + format_for_mermaid_graph_node(pid, id) + end + + process_label -> + format_for_mermaid_graph_node(pid, process_label) end {:registered_name, name} ->