Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Erlang/OTP 27 Process label support #446

Merged
merged 2 commits into from
Aug 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading