Skip to content

Commit c1f57b8

Browse files
Add Erlang/OTP 27 Process label support (#446)
1 parent 72573aa commit c1f57b8

File tree

3 files changed

+33
-3
lines changed

3 files changed

+33
-3
lines changed

.github/workflows/ci.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@ jobs:
3939
- pair:
4040
elixir: 1.15.6
4141
otp: 26.0.2
42+
- pair:
43+
elixir: 1.17.2
44+
otp: 27.0.1
4245
lint: lint
4346
steps:
4447
- uses: actions/checkout@v2

lib/phoenix/live_dashboard/system_info.ex

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -801,7 +801,12 @@ defmodule Phoenix.LiveDashboard.SystemInfo do
801801
case Process.info(pid, [:initial_call, :dictionary, :registered_name]) do
802802
[{:initial_call, initial_call}, {:dictionary, dictionary}, {:registered_name, name}] ->
803803
initial_call = Keyword.get(dictionary, :"$initial_call", initial_call)
804-
name = if is_atom(name), do: inspect(name), else: format_initial_call(initial_call)
804+
805+
name =
806+
format_process_label(Keyword.get(dictionary, :"$process_label")) ||
807+
format_registered_name(name) ||
808+
format_initial_call(initial_call)
809+
805810
{name, initial_call}
806811

807812
_ ->
@@ -820,6 +825,13 @@ defmodule Phoenix.LiveDashboard.SystemInfo do
820825
|> to_process_details()
821826
end
822827

828+
defp format_process_label(nil), do: nil
829+
defp format_process_label(label) when is_binary(label), do: label
830+
defp format_process_label(label), do: inspect(label)
831+
832+
defp format_registered_name([]), do: nil
833+
defp format_registered_name(name), do: inspect(name)
834+
823835
defp format_initial_call({:supervisor, mod, arity}), do: Exception.format_mfa(mod, :init, arity)
824836
defp format_initial_call({m, f, a}), do: Exception.format_mfa(m, f, a)
825837
defp format_initial_call(nil), do: nil

test/phoenix/live_dashboard/system_info_test.exs

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,29 @@ defmodule Phoenix.LiveDashboard.SystemInfoTest do
3838
end
3939

4040
test "all with search" do
41-
process = if System.otp_release() == "26", do: :user_drv_writer, else: :user
41+
process =
42+
if System.otp_release() |> String.to_integer() >= 26, do: :user_drv_writer, else: :user
43+
4244
{pids, _count, _} = SystemInfo.fetch_processes(node(), inspect(process), :memory, :asc, 100)
4345

4446
assert [[pid, name | _]] = pids
4547
assert pid == {:pid, Process.whereis(process)}
4648
assert name == {:name_or_initial_call, inspect(process)}
4749
end
4850

51+
if System.otp_release() |> String.to_integer() >= 27 do
52+
test "all with search by label" do
53+
{:ok, agent_pid} = Agent.start_link(fn -> Process.set_label("test label") end)
54+
55+
{pids, _count, _} =
56+
SystemInfo.fetch_processes(node(), "test label", :memory, :asc, 100)
57+
58+
assert [[pid, name | _]] = pids
59+
assert pid == {:pid, agent_pid}
60+
assert name == {:name_or_initial_call, "test label"}
61+
end
62+
end
63+
4964
test "allows previous reductions param" do
5065
{_pids, _count, state} =
5166
SystemInfo.fetch_processes(node(), ":user", :reductions_diff, :asc, 100)
@@ -60,7 +75,7 @@ defmodule Phoenix.LiveDashboard.SystemInfoTest do
6075
assert is_integer(info[:message_queue_len])
6176

6277
expected =
63-
if System.otp_release() == "26",
78+
if System.otp_release() |> String.to_integer() >= 26,
6479
do: {:group, :server, 4},
6580
else: {:erlang, :apply, 2}
6681

0 commit comments

Comments
 (0)