Skip to content

Commit

Permalink
feat: display process label when otp 27 (#104)
Browse files Browse the repository at this point in the history
* ci: use github badge build status

* feat: display process lable when otp 27
  • Loading branch information
zhongwencool authored Oct 20, 2024
1 parent 4b21dba commit 505b3ac
Show file tree
Hide file tree
Showing 15 changed files with 160 additions and 91 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/erlang.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Erlang CI
name: ci

on: push

Expand All @@ -8,7 +8,7 @@ jobs:
name: Erlang/OTP ${{matrix.otp}} / rebar3 ${{matrix.rebar3}}
strategy:
matrix:
otp: ['26', '25', '24']
otp: ['27', '26', '25', '24']
rebar3: ['3.22']
steps:
- uses: actions/checkout@v4
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
.eunit
.tool-versions
_build
deps
elvis
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

# observer_cli

[![Build Status](https://travis-ci.org/zhongwencool/observer_cli.svg?branch=master)](https://travis-ci.org/zhongwencool/observer_cli)
[![Build Status](https://github.com/zhongwencool/observer_cli/workflows/ci/badge.svg)](https://github.com/zhongwencool/observer_cli/actions)
[![GitHub tag](https://img.shields.io/github/tag/zhongwencool/observer_cli.svg)](https://github.com/zhongwencool/observer_cli)
[![MIT License](https://img.shields.io/hexpm/l/observer_cli.svg)](https://hex.pm/packages/observer_cli)
[![Hex.pm Version](https://img.shields.io/hexpm/v/observer_cli.svg)](https://hex.pm/packages/observer_cli)
Expand Down
77 changes: 52 additions & 25 deletions rebar.config
Original file line number Diff line number Diff line change
@@ -1,40 +1,67 @@
{erl_opts, [{src_dirs, ["src", "test"]},
warn_unused_vars,
warn_export_all,
warn_shadow_vars,
warn_unused_import,
warn_unused_function,
warn_bif_clash,
warn_unused_record,
warn_deprecated_function,
warn_obsolete_guard,
strict_validation,
warn_export_vars,
warn_exported_vars,
warn_missing_spec,
warn_untyped_record, debug_info]}.
{erl_opts, [
{src_dirs, ["src", "test"]},
warn_unused_vars,
warn_export_all,
warn_shadow_vars,
warn_unused_import,
warn_unused_function,
warn_bif_clash,
warn_unused_record,
warn_deprecated_function,
warn_obsolete_guard,
strict_validation,
warn_export_vars,
warn_exported_vars,
warn_missing_spec,
warn_untyped_record,
debug_info
]}.
{deps_dir, "deps"}.
{deps, [recon]}.
{deps, [
recon,
{eqwalizer_support,
{git_subdir, "https://github.com/whatsapp/eqwalizer.git", {branch, "main"},
"eqwalizer_support"}}
]}.

{project_plugins, [
rebar3_format,
erlfmt,
{eqwalizer_rebar3,
{git_subdir, "https://github.com/whatsapp/eqwalizer.git", {branch, "main"},
"eqwalizer_rebar3"}}
]}.

{escript_main_app, observer_cli}.
{escript_emu_args, "%%! -escript main observer_cli_escriptize -hidden +sbtu +A0 -elixir ansi_enabled true\n"}.
{escript_emu_args,
"%%! -escript main observer_cli_escriptize -hidden +sbtu +A0 -elixir ansi_enabled true\n"}.
{escript_incl_apps, [recon]}.

{dialyzer_opts, [{warnings, [unmatched_returns, error_handling, race_conditions, behaviours]}]}.
{edoc_opts, [{report_missing_types, true}, {source_path, ["src"]}, {report_missing_types, true}, {todo, true}, {packages, false}, {subpackages, false}]}.
{edoc_opts, [
{report_missing_types, true},
{source_path, ["src"]},
{report_missing_types, true},
{todo, true},
{packages, false},
{subpackages, false}
]}.
{xref_checks, [undefined_function_calls]}.
{xref_ignores, [{proc_lib, get_label, 1}]}.
{cover_enabled, true}.
{post_hooks, [{"(linux|darwin|solaris)", edoc, "escript doc/docsite.erl"}]}.

{profiles, [
{inet6, [
{escript_emu_args, "%%! -escript main observer_cli_escriptize -hidden -proto_dist inet6_tcp +sbtu +A0 -elixir ansi_enabled true\n"}
]}
{inet6, [
{escript_emu_args,
"%%! -escript main observer_cli_escriptize -hidden -proto_dist inet6_tcp +sbtu +A0 -elixir ansi_enabled true\n"}
]}
]}.

{project_plugins, [rebar3_format, erlfmt]}.
{format, [
{files, ["src/*.erl", "include/*.hrl"]},
{formatter, erlfmt_formatter}, %% The erlfmt formatter interface.
{options, #{print_width => 100, ignore_pragma => true}} %% ...or no options at all.
{files, ["src/*.erl", "include/*.hrl"]},
%% The erlfmt formatter interface.
{formatter, erlfmt_formatter},
%% ...or no options at all.
{options, #{print_width => 100, ignore_pragma => true}}
]}.
7 changes: 6 additions & 1 deletion rebar.lock
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
{"1.2.0",
[{<<"recon">>,{pkg,<<"recon">>,<<"2.5.5">>},0}]}.
[{<<"eqwalizer_support">>,
{git_subdir,"https://github.com/whatsapp/eqwalizer.git",
{ref,"0c099bbfa2fba1869d60e239c9b2cf2b6fb31ea9"},
"eqwalizer_support"},
0},
{<<"recon">>,{pkg,<<"recon">>,<<"2.5.5">>},0}]}.
[
{pkg_hash,[
{<<"recon">>, <<"C108A4C406FA301A529151A3BB53158CADC4064EC0C5F99B03DDB8C0E4281BDF">>}]},
Expand Down
84 changes: 56 additions & 28 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,8 +529,8 @@ 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, " Reductions", 21),
?W(?GRAY_BG, "Name|>Lable|>Initial Call", 45),
?W(?GRAY_BG, " Reductions", 14),
?W(?GRAY_BG, " MsgQueue", 10),
?W(?GRAY_BG, "Current Function", 32)
]),
Expand Down Expand Up @@ -557,8 +559,8 @@ render_top_n_view(binary_memory, MemoryList, Num, Pages, Page) ->
Title = ?render([
?W2(?GRAY_BG, "No | Pid", 16),
?W2(?RED_BG, " BinMemory", 14),
?W(?GRAY_BG, "Name or Initial Call", 38),
?W(?GRAY_BG, " Reductions", 21),
?W(?GRAY_BG, "Name|>Lable|>Initial Call", 45),
?W(?GRAY_BG, " Reductions", 14),
?W(?GRAY_BG, " MsgQueue", 10),
?W(?GRAY_BG, "Current Function", 32)
]),
Expand Down Expand Up @@ -586,8 +588,8 @@ render_top_n_view(binary_memory, MemoryList, Num, Pages, Page) ->
render_top_n_view(reductions, ReductionList, Num, Pages, Page) ->
Title = ?render([
?W2(?GRAY_BG, "No | Pid", 16),
?W2(?RED_BG, " Reductions", 21),
?W(?GRAY_BG, "Name or Initial Call", 38),
?W2(?RED_BG, " Reductions", 15),
?W(?GRAY_BG, "Name|>Lable|>Initial Call", 45),
?W(?GRAY_BG, " Memory", 13),
?W(?GRAY_BG, " MsgQueue", 10),
?W(?GRAY_BG, "Current Function", 33)
Expand Down Expand Up @@ -617,8 +619,8 @@ render_top_n_view(total_heap_size, HeapList, Num, Pages, Page) ->
Title = ?render([
?W2(?GRAY_BG, "No | Pid", 16),
?W2(?RED_BG, " TotalHeapSize", 14),
?W(?GRAY_BG, "Name or Initial Call", 38),
?W(?GRAY_BG, " Reductions", 21),
?W(?GRAY_BG, "Name|>Lable|>Initial Call", 45),
?W(?GRAY_BG, " Reductions", 14),
?W(?GRAY_BG, " MsgQueue", 10),
?W(?GRAY_BG, "Current Function", 32)
]),
Expand Down Expand Up @@ -647,9 +649,9 @@ render_top_n_view(message_queue_len, MQLenList, Num, Pages, Page) ->
Title = ?render([
?W2(?GRAY_BG, "No | Pid", 16),
?W2(?RED_BG, " MsgQueue", 11),
?W(?GRAY_BG, "Name or Initial Call", 37),
?W(?GRAY_BG, "Name|>Lable|>Initial Call", 44),
?W(?GRAY_BG, " Memory", 13),
?W(?GRAY_BG, " Reductions", 21),
?W(?GRAY_BG, " Reductions", 14),
?W(?GRAY_BG, "Current Function", 33)
]),
{Start, ChoosePos} = observer_cli_lib:get_pos(Page, Num, Pages, erlang:length(MQLenList)),
Expand Down Expand Up @@ -682,19 +684,19 @@ notify_pause_status() ->
?output("\e[31;1m PAUSE INPUT (p, r/rr, b/bb, h/hh, m/mm) to resume or q to quit \e[0m~n").

get_memory_format(Pos, Pos) ->
"|\e[42m~-3.3w|~-12.12s|~13.13s |~-38.38s|~21.21s| ~-9.9s|~-33.33s\e[49m|~n";
"|\e[42m~-3.3w|~-12.12s|~13.13s |~-45.45s|~14.14s| ~-9.9s|~-33.33s\e[49m|~n";
get_memory_format(_Pos, _RankPos) ->
"|~-3.3w|~-12.12s|~13.13s |~-38.38s|~21.21s| ~-9.9s|~-33.33s|~n".
"|~-3.3w|~-12.12s|~13.13s |~-45.45s|~14.14s| ~-9.9s|~-33.33s|~n".

get_reduction_format(Pos, Pos) ->
"|\e[42m~-3.3w|~-12.12s|~-21.21s|~-38.38s|~13.13s| ~-9.9s|~-34.34s\e[49m|~n";
"|\e[42m~-3.3w|~-12.12s|~-15.15s|~-45.45s|~12.12s| ~-9.9s|~-34.34s\e[49m|~n";
get_reduction_format(_Pos, _RankPos) ->
"|~-3.3w|~-12.12s|~-21.21s|~-38.38s|~13.13s| ~-9.9s|~-34.34s|~n".
"|~-3.3w|~-12.12s|~-15.15s|~-45.45s|~12.12s| ~-9.9s|~-34.34s|~n".

get_message_queue_format(Pos, Pos) ->
"|\e[42m~-3.3w|~-12.12s|~-11.11s|~-37.37s|~13.13s| ~-20.20s|~-34.34s\e[49m|~n";
"|\e[42m~-3.3w|~-12.12s|~-11.11s|~-44.44s|~13.13s| ~-13.13s|~-34.34s\e[49m|~n";
get_message_queue_format(_Pos, _RankPos) ->
"|~-3.3w|~-12.12s|~-11.11s|~-37.37s|~13.13s| ~-20.20s|~-34.34s|~n".
"|~-3.3w|~-12.12s|~-11.11s|~-44.44s|~13.13s| ~-13.13s|~-34.34s|~n".

refresh_next_time(proc_count, Type, Interval) ->
erlang:send_after(Interval, self(), {proc_count, Type});
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
2 changes: 1 addition & 1 deletion src/observer_cli_application.erl
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ render_app_info(Row, CurPage, {Type, N}) ->
begin
{0, {element(N, I), S}, [App, C, M, R, Q, S, V]}
end
|| {App, I = {C, M, R, Q, S, V}} <- maps:to_list(app_info())
|| {App, I = {C, M, R, Q, S, V}} <- maps:to_list(app_info())
],
{StartPos, SortList} = observer_cli_lib:sublist(List, Row, CurPage),
InitColor = [
Expand Down
2 changes: 1 addition & 1 deletion src/observer_cli_escriptize.erl
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ remote_load(Node) ->
begin
recon:remote_load([Node], Mod)
end
|| Mod <- ?BEAM_MODS
|| Mod <- ?BEAM_MODS
].

random_local_node_name() ->
Expand Down
4 changes: 2 additions & 2 deletions src/observer_cli_ets.erl
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ render_ets_info(Rows, CurPage, Attr) ->
begin
get_ets_info(Tab, Attr)
end
|| Tab <- ets:all()
|| Tab <- ets:all()
],
WordSize = erlang:system_info(wordsize),
{_StartPos, SortEts} = observer_cli_lib:sublist(AllEts, Rows, CurPage),
Expand Down Expand Up @@ -123,7 +123,7 @@ render_ets_info(Rows, CurPage, Attr) ->
?W(Owner, 14)
])
end
|| {_, _, Ets} <- SortEts
|| {_, _, Ets} <- SortEts
],
[Title | RowView].

Expand Down
8 changes: 5 additions & 3 deletions src/observer_cli_inet.erl
Original file line number Diff line number Diff line change
Expand Up @@ -129,12 +129,14 @@ render_io_rows({LastIn, LastOut}) ->
render_inet_rows([], Rows, #inet{func = inet_count, type = Type}) ->
{[], io_lib:format("\e[32;1mGet nothing for recon:inet_count(~p, ~p)\e[0m~n", [Type, Rows])};
render_inet_rows([], Rows, #inet{func = inet_window, type = Type, interval = Interval}) ->
{[],
{
[],
io_lib:format("\e[32;1mGet nothing for recon:inet_window(~p, ~p, ~p)\e[0m~n", [
Type,
Rows,
Interval
])};
])
};
render_inet_rows(InetList, Num, #inet{
type = Type,
pages = Pages,
Expand Down Expand Up @@ -294,7 +296,7 @@ get_remote_ip(P) ->
begin
erlang:integer_to_list(A)
end
|| A <- erlang:tuple_to_list(Addr)
|| A <- erlang:tuple_to_list(Addr)
],
string:join(AddrList, ".") ++ ":" ++ erlang:integer_to_list(Port);
{error, Err} ->
Expand Down
Loading

0 comments on commit 505b3ac

Please sign in to comment.