Skip to content

Commit

Permalink
feat: display process lable when otp 27
Browse files Browse the repository at this point in the history
  • Loading branch information
zhongwencool committed Oct 19, 2024
1 parent 4720a98 commit 6b3eb99
Showing 1 changed file with 41 additions and 13 deletions.
54 changes: 41 additions & 13 deletions src/observer_cli.erl
Original file line number Diff line number Diff line change
Expand Up @@ -302,8 +302,10 @@ render_memory_process_line(MemSum, PortParallelism, Interval) ->
{erlang:integer_to_list(RunQ), "RunQueue"};
Pid ->
{_, Q} = process_info(Pid, message_queue_len),
{[erlang:integer_to_list(RunQ), "/", erlang:integer_to_list(Q)],
"RunQueue/ErrorLoggerQueue"}
{
[erlang:integer_to_list(RunQ), "/", erlang:integer_to_list(Q)],
"RunQueue/ErrorLoggerQueue"
}
end,
ProcMemPercent = observer_cli_lib:to_percent(ProcMem / TotalMem),
AtomMemPercent = observer_cli_lib:to_percent(AtomMem / TotalMem),
Expand Down Expand Up @@ -390,7 +392,7 @@ render_scheduler_usage(SchedulerUsage, SchedulerNum) when SchedulerNum < 8 ->
CPU2
])
end
|| Seq1 <- lists:seq(1, Column)
|| Seq1 <- lists:seq(1, Column)
],
{Column, CPU};
%% 100 >= scheduler >= 8 split 4 part
Expand Down Expand Up @@ -434,7 +436,7 @@ render_scheduler_usage(SchedulerUsage, SchedulerNum) when SchedulerNum =< 100 ->
CPU4
])
end
|| Seq1 <- lists:seq(1, Column)
|| Seq1 <- lists:seq(1, Column)
],
{Column, CPU};
%% scheduler > 100 don't show process bar.
Expand Down Expand Up @@ -512,7 +514,7 @@ render_scheduler_usage(SchedulerUsage, SchedulerNum) ->
CPU10
])
end
|| Seq1 <- lists:seq(1, Column)
|| Seq1 <- lists:seq(1, Column)
],
{Column, CPU}.

Expand All @@ -527,7 +529,7 @@ render_top_n_view(memory, MemoryList, Num, Pages, Page) ->
Title = ?render([
?W2(?GRAY_BG, "No | Pid", 16),
?W2(?RED_BG, " Memory", 14),
?W(?GRAY_BG, "Name or Initial Call", 38),
?W(?GRAY_BG, "Name|>Lable|>Initial Call", 38),
?W(?GRAY_BG, " Reductions", 21),
?W(?GRAY_BG, " MsgQueue", 10),
?W(?GRAY_BG, "Current Function", 32)
Expand Down Expand Up @@ -756,15 +758,39 @@ process_bar_format_style(Percents, IsLastLine) ->
get_top_n_info(Item) ->
{Pid, Val, Call = [IsName | _]} = Item,
{CurFun, InitialCall} = get_current_initial_call(Call),
NameOrCall = display_name_or_initial_call(IsName, InitialCall, Pid),
{Pid, Val, CurFun, NameOrCall}.
Flag = display_unique_flag(IsName, InitialCall, Pid),
{Pid, Val, CurFun, Flag}.

display_unique_flag(IsName, Call, Pid) ->
case choose_name(IsName) of
undefined ->
case choose_lable(Pid) of
undefined -> choose_call(Call, Pid);
Lable -> Lable
end;
Name ->
Name
end.

display_name_or_initial_call(IsName, _Call, _Pid) when is_atom(IsName) ->
choose_name(IsName) when is_atom(IsName) ->
atom_to_list(IsName);
display_name_or_initial_call(_IsName, {proc_lib, init_p, 5}, Pid) ->
choose_name(_) ->
undefined.

choose_lable(Pid) ->
case
erlang:function_exported(proc_lib, get_label, 1) andalso
proc_lib:get_label(Pid)
of
false -> undefined;
undefined -> undefined;
Lable -> io_lib:format("~p", [Lable])
end.

choose_call({proc_lib, init_p, 5}, Pid) ->
%% translate gen_xxx behavior
observer_cli_lib:mfa_to_list(proc_lib:translate_initial_call(Pid));
display_name_or_initial_call(_IsName, Call, _Pid) ->
choose_call(Call, _Pid) ->
observer_cli_lib:mfa_to_list(Call).

get_refresh_prompt(proc_count, Type, Interval, Rows) ->
Expand All @@ -775,14 +801,16 @@ get_refresh_prompt(proc_window, Type, Interval, Rows) ->
get_stable_system_info() ->
OtpRelease = erlang:system_info(otp_release),
SysVersion = erlang:system_info(system_version) -- "\n",
{[
{
[
OtpRelease,
SysVersion,
erlang:system_info(process_limit),
erlang:system_info(port_limit),
erlang:system_info(ets_limit)
],
erlang:system_info(port_parallelism)}.
erlang:system_info(port_parallelism)
}.

get_atom_status() ->
try erlang:system_info(atom_limit) of
Expand Down

0 comments on commit 6b3eb99

Please sign in to comment.