Skip to content

Commit

Permalink
Add Erlang/OTP 27 Process label support (#446)
Browse files Browse the repository at this point in the history
  • Loading branch information
KernelMadness authored Aug 15, 2024
1 parent 72573aa commit c1f57b8
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 3 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ jobs:
- pair:
elixir: 1.15.6
otp: 26.0.2
- pair:
elixir: 1.17.2
otp: 27.0.1
lint: lint
steps:
- uses: actions/checkout@v2
Expand Down
14 changes: 13 additions & 1 deletion lib/phoenix/live_dashboard/system_info.ex
Original file line number Diff line number Diff line change
Expand Up @@ -801,7 +801,12 @@ defmodule Phoenix.LiveDashboard.SystemInfo do
case Process.info(pid, [:initial_call, :dictionary, :registered_name]) do
[{:initial_call, initial_call}, {:dictionary, dictionary}, {:registered_name, name}] ->
initial_call = Keyword.get(dictionary, :"$initial_call", initial_call)
name = if is_atom(name), do: inspect(name), else: format_initial_call(initial_call)

name =
format_process_label(Keyword.get(dictionary, :"$process_label")) ||
format_registered_name(name) ||
format_initial_call(initial_call)

{name, initial_call}

_ ->
Expand All @@ -820,6 +825,13 @@ defmodule Phoenix.LiveDashboard.SystemInfo do
|> to_process_details()
end

defp format_process_label(nil), do: nil
defp format_process_label(label) when is_binary(label), do: label
defp format_process_label(label), do: inspect(label)

defp format_registered_name([]), do: nil
defp format_registered_name(name), do: inspect(name)

defp format_initial_call({:supervisor, mod, arity}), do: Exception.format_mfa(mod, :init, arity)
defp format_initial_call({m, f, a}), do: Exception.format_mfa(m, f, a)
defp format_initial_call(nil), do: nil
Expand Down
19 changes: 17 additions & 2 deletions test/phoenix/live_dashboard/system_info_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,29 @@ defmodule Phoenix.LiveDashboard.SystemInfoTest do
end

test "all with search" do
process = if System.otp_release() == "26", do: :user_drv_writer, else: :user
process =
if System.otp_release() |> String.to_integer() >= 26, do: :user_drv_writer, else: :user

{pids, _count, _} = SystemInfo.fetch_processes(node(), inspect(process), :memory, :asc, 100)

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

if System.otp_release() |> String.to_integer() >= 27 do
test "all with search by label" do
{:ok, agent_pid} = Agent.start_link(fn -> Process.set_label("test label") end)

{pids, _count, _} =
SystemInfo.fetch_processes(node(), "test label", :memory, :asc, 100)

assert [[pid, name | _]] = pids
assert pid == {:pid, agent_pid}
assert name == {:name_or_initial_call, "test label"}
end
end

test "allows previous reductions param" do
{_pids, _count, state} =
SystemInfo.fetch_processes(node(), ":user", :reductions_diff, :asc, 100)
Expand All @@ -60,7 +75,7 @@ defmodule Phoenix.LiveDashboard.SystemInfoTest do
assert is_integer(info[:message_queue_len])

expected =
if System.otp_release() == "26",
if System.otp_release() |> String.to_integer() >= 26,
do: {:group, :server, 4},
else: {:erlang, :apply, 2}

Expand Down

0 comments on commit c1f57b8

Please sign in to comment.