Skip to content

Commit 5f38d35

Browse files
authored
Display process label in application and process views (#479)
1 parent 296c2a9 commit 5f38d35

File tree

3 files changed

+33
-14
lines changed

3 files changed

+33
-14
lines changed

lib/phoenix/live_dashboard/info/process_info_component.ex

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ defmodule Phoenix.LiveDashboard.ProcessInfoComponent do
66
@info_keys [
77
:initial_call,
88
:registered_name,
9+
:label,
910
:current_function,
1011
:status,
1112
:message_queue_len,
@@ -37,6 +38,7 @@ defmodule Phoenix.LiveDashboard.ProcessInfoComponent do
3738
<%= if @alive do %>
3839
<Phoenix.LiveDashboard.PageBuilder.label_value_list>
3940
<:elem label="Registered name"><%= @registered_name %></:elem>
41+
<:elem label="Label"><%= @label %></:elem>
4042
<:elem label="Current function"><%= @current_function %></:elem>
4143
<:elem label="Initial call"><%= @initial_call %></:elem>
4244
<:elem label="Status"><%= @status %></:elem>

lib/phoenix/live_dashboard/system_info.ex

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -345,34 +345,39 @@ defmodule Phoenix.LiveDashboard.SystemInfo do
345345

346346
{:ok,
347347
info
348-
|> Enum.map(&process_info_callback_key/1)
348+
|> Enum.flat_map(&process_info_callback_key/1)
349349
|> Keyword.put(:initial_call, details.initial_call)}
350350
end
351351
end
352352

353353
defp process_info_callback_key({:links, links}),
354-
do: {:links, Enum.map(links, &pid_or_port_details/1)}
354+
do: [{:links, Enum.map(links, &pid_or_port_details/1)}]
355355

356356
defp process_info_callback_key({:monitors, monitors}) do
357-
{:monitors,
358-
monitors
359-
|> Enum.map(fn {_label, pid_or_port} -> pid_or_port end)
360-
|> Enum.map(&pid_or_port_details/1)}
357+
[
358+
{:monitors,
359+
monitors
360+
|> Enum.map(fn {_label, pid_or_port} -> pid_or_port end)
361+
|> Enum.map(&pid_or_port_details/1)}
362+
]
361363
end
362364

363365
defp process_info_callback_key({:monitored_by, monitored_by}),
364-
do: {:monitored_by, Enum.map(monitored_by, &pid_or_port_details/1)}
366+
do: [{:monitored_by, Enum.map(monitored_by, &pid_or_port_details/1)}]
365367

366368
defp process_info_callback_key({:group_leader, group_leader}),
367-
do: {:group_leader, pid_or_port_details(group_leader)}
369+
do: [{:group_leader, pid_or_port_details(group_leader)}]
368370

369371
defp process_info_callback_key({:dictionary, dictionary}) do
370-
{:ancestors,
371-
Keyword.get(dictionary, :"$ancestors", [])
372-
|> Enum.map(&pid_or_port_details/1)}
372+
[
373+
{:ancestors,
374+
Keyword.get(dictionary, :"$ancestors", [])
375+
|> Enum.map(&pid_or_port_details/1)},
376+
{:label, Keyword.get(dictionary, :"$process_label")}
377+
]
373378
end
374379

375-
defp process_info_callback_key({key, value}), do: {key, value}
380+
defp process_info_callback_key({key, value}), do: [{key, value}]
376381

377382
## Applications callbacks
378383

@@ -496,8 +501,12 @@ defmodule Phoenix.LiveDashboard.SystemInfo do
496501
end
497502

498503
defp to_wrapped_node(type, pid, children) do
499-
case Process.info(pid, :registered_name) do
500-
{:registered_name, registered_name} ->
504+
case Process.info(pid, [:registered_name, :dictionary]) do
505+
[{:registered_name, []}, {:dictionary, dictionary}] ->
506+
label = Keyword.get(dictionary, :"$process_label", [])
507+
[{{type, pid, label}, children}]
508+
509+
[{:registered_name, registered_name}, _] ->
501510
[{{type, pid, registered_name}, children}]
502511

503512
_ ->

test/phoenix/live_dashboard/system_info_test.exs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,14 @@ defmodule Phoenix.LiveDashboard.SystemInfoTest do
9999
assert info[:registered_name] == Phoenix.LiveDashboard.DynamicSupervisor
100100
assert info[:initial_call] == {:supervisor, Supervisor.Default, 1}
101101
end
102+
103+
if System.otp_release() |> String.to_integer() >= 27 do
104+
test "info with label" do
105+
{:ok, agent_pid} = Agent.start_link(fn -> Process.set_label("test label") end)
106+
{:ok, info} = SystemInfo.fetch_process_info(agent_pid)
107+
assert info[:label] == "test label"
108+
end
109+
end
102110
end
103111

104112
describe "ports" do

0 commit comments

Comments
 (0)