Skip to content

Commit 505b3ac

Browse files
authored
feat: display process label when otp 27 (#104)
* ci: use github badge build status * feat: display process lable when otp 27
1 parent 4b21dba commit 505b3ac

15 files changed

+160
-91
lines changed

.github/workflows/erlang.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Erlang CI
1+
name: ci
22

33
on: push
44

@@ -8,7 +8,7 @@ jobs:
88
name: Erlang/OTP ${{matrix.otp}} / rebar3 ${{matrix.rebar3}}
99
strategy:
1010
matrix:
11-
otp: ['26', '25', '24']
11+
otp: ['27', '26', '25', '24']
1212
rebar3: ['3.22']
1313
steps:
1414
- uses: actions/checkout@v4

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
.eunit
2+
.tool-versions
23
_build
34
deps
45
elvis

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
# observer_cli
44

5-
[![Build Status](https://travis-ci.org/zhongwencool/observer_cli.svg?branch=master)](https://travis-ci.org/zhongwencool/observer_cli)
5+
[![Build Status](https://github.com/zhongwencool/observer_cli/workflows/ci/badge.svg)](https://github.com/zhongwencool/observer_cli/actions)
66
[![GitHub tag](https://img.shields.io/github/tag/zhongwencool/observer_cli.svg)](https://github.com/zhongwencool/observer_cli)
77
[![MIT License](https://img.shields.io/hexpm/l/observer_cli.svg)](https://hex.pm/packages/observer_cli)
88
[![Hex.pm Version](https://img.shields.io/hexpm/v/observer_cli.svg)](https://hex.pm/packages/observer_cli)

rebar.config

Lines changed: 52 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,67 @@
1-
{erl_opts, [{src_dirs, ["src", "test"]},
2-
warn_unused_vars,
3-
warn_export_all,
4-
warn_shadow_vars,
5-
warn_unused_import,
6-
warn_unused_function,
7-
warn_bif_clash,
8-
warn_unused_record,
9-
warn_deprecated_function,
10-
warn_obsolete_guard,
11-
strict_validation,
12-
warn_export_vars,
13-
warn_exported_vars,
14-
warn_missing_spec,
15-
warn_untyped_record, debug_info]}.
1+
{erl_opts, [
2+
{src_dirs, ["src", "test"]},
3+
warn_unused_vars,
4+
warn_export_all,
5+
warn_shadow_vars,
6+
warn_unused_import,
7+
warn_unused_function,
8+
warn_bif_clash,
9+
warn_unused_record,
10+
warn_deprecated_function,
11+
warn_obsolete_guard,
12+
strict_validation,
13+
warn_export_vars,
14+
warn_exported_vars,
15+
warn_missing_spec,
16+
warn_untyped_record,
17+
debug_info
18+
]}.
1619
{deps_dir, "deps"}.
17-
{deps, [recon]}.
20+
{deps, [
21+
recon,
22+
{eqwalizer_support,
23+
{git_subdir, "https://github.com/whatsapp/eqwalizer.git", {branch, "main"},
24+
"eqwalizer_support"}}
25+
]}.
26+
27+
{project_plugins, [
28+
rebar3_format,
29+
erlfmt,
30+
{eqwalizer_rebar3,
31+
{git_subdir, "https://github.com/whatsapp/eqwalizer.git", {branch, "main"},
32+
"eqwalizer_rebar3"}}
33+
]}.
1834

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

2340
{dialyzer_opts, [{warnings, [unmatched_returns, error_handling, race_conditions, behaviours]}]}.
24-
{edoc_opts, [{report_missing_types, true}, {source_path, ["src"]}, {report_missing_types, true}, {todo, true}, {packages, false}, {subpackages, false}]}.
41+
{edoc_opts, [
42+
{report_missing_types, true},
43+
{source_path, ["src"]},
44+
{report_missing_types, true},
45+
{todo, true},
46+
{packages, false},
47+
{subpackages, false}
48+
]}.
2549
{xref_checks, [undefined_function_calls]}.
50+
{xref_ignores, [{proc_lib, get_label, 1}]}.
2651
{cover_enabled, true}.
2752
{post_hooks, [{"(linux|darwin|solaris)", edoc, "escript doc/docsite.erl"}]}.
2853

2954
{profiles, [
30-
{inet6, [
31-
{escript_emu_args, "%%! -escript main observer_cli_escriptize -hidden -proto_dist inet6_tcp +sbtu +A0 -elixir ansi_enabled true\n"}
32-
]}
55+
{inet6, [
56+
{escript_emu_args,
57+
"%%! -escript main observer_cli_escriptize -hidden -proto_dist inet6_tcp +sbtu +A0 -elixir ansi_enabled true\n"}
58+
]}
3359
]}.
3460

35-
{project_plugins, [rebar3_format, erlfmt]}.
3661
{format, [
37-
{files, ["src/*.erl", "include/*.hrl"]},
38-
{formatter, erlfmt_formatter}, %% The erlfmt formatter interface.
39-
{options, #{print_width => 100, ignore_pragma => true}} %% ...or no options at all.
62+
{files, ["src/*.erl", "include/*.hrl"]},
63+
%% The erlfmt formatter interface.
64+
{formatter, erlfmt_formatter},
65+
%% ...or no options at all.
66+
{options, #{print_width => 100, ignore_pragma => true}}
4067
]}.

rebar.lock

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
{"1.2.0",
2-
[{<<"recon">>,{pkg,<<"recon">>,<<"2.5.5">>},0}]}.
2+
[{<<"eqwalizer_support">>,
3+
{git_subdir,"https://github.com/whatsapp/eqwalizer.git",
4+
{ref,"0c099bbfa2fba1869d60e239c9b2cf2b6fb31ea9"},
5+
"eqwalizer_support"},
6+
0},
7+
{<<"recon">>,{pkg,<<"recon">>,<<"2.5.5">>},0}]}.
38
[
49
{pkg_hash,[
510
{<<"recon">>, <<"C108A4C406FA301A529151A3BB53158CADC4064EC0C5F99B03DDB8C0E4281BDF">>}]},

src/observer_cli.erl

Lines changed: 56 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -302,8 +302,10 @@ render_memory_process_line(MemSum, PortParallelism, Interval) ->
302302
{erlang:integer_to_list(RunQ), "RunQueue"};
303303
Pid ->
304304
{_, Q} = process_info(Pid, message_queue_len),
305-
{[erlang:integer_to_list(RunQ), "/", erlang:integer_to_list(Q)],
306-
"RunQueue/ErrorLoggerQueue"}
305+
{
306+
[erlang:integer_to_list(RunQ), "/", erlang:integer_to_list(Q)],
307+
"RunQueue/ErrorLoggerQueue"
308+
}
307309
end,
308310
ProcMemPercent = observer_cli_lib:to_percent(ProcMem / TotalMem),
309311
AtomMemPercent = observer_cli_lib:to_percent(AtomMem / TotalMem),
@@ -390,7 +392,7 @@ render_scheduler_usage(SchedulerUsage, SchedulerNum) when SchedulerNum < 8 ->
390392
CPU2
391393
])
392394
end
393-
|| Seq1 <- lists:seq(1, Column)
395+
|| Seq1 <- lists:seq(1, Column)
394396
],
395397
{Column, CPU};
396398
%% 100 >= scheduler >= 8 split 4 part
@@ -434,7 +436,7 @@ render_scheduler_usage(SchedulerUsage, SchedulerNum) when SchedulerNum =< 100 ->
434436
CPU4
435437
])
436438
end
437-
|| Seq1 <- lists:seq(1, Column)
439+
|| Seq1 <- lists:seq(1, Column)
438440
],
439441
{Column, CPU};
440442
%% scheduler > 100 don't show process bar.
@@ -512,7 +514,7 @@ render_scheduler_usage(SchedulerUsage, SchedulerNum) ->
512514
CPU10
513515
])
514516
end
515-
|| Seq1 <- lists:seq(1, Column)
517+
|| Seq1 <- lists:seq(1, Column)
516518
],
517519
{Column, CPU}.
518520

@@ -527,8 +529,8 @@ render_top_n_view(memory, MemoryList, Num, Pages, Page) ->
527529
Title = ?render([
528530
?W2(?GRAY_BG, "No | Pid", 16),
529531
?W2(?RED_BG, " Memory", 14),
530-
?W(?GRAY_BG, "Name or Initial Call", 38),
531-
?W(?GRAY_BG, " Reductions", 21),
532+
?W(?GRAY_BG, "Name|>Lable|>Initial Call", 45),
533+
?W(?GRAY_BG, " Reductions", 14),
532534
?W(?GRAY_BG, " MsgQueue", 10),
533535
?W(?GRAY_BG, "Current Function", 32)
534536
]),
@@ -557,8 +559,8 @@ render_top_n_view(binary_memory, MemoryList, Num, Pages, Page) ->
557559
Title = ?render([
558560
?W2(?GRAY_BG, "No | Pid", 16),
559561
?W2(?RED_BG, " BinMemory", 14),
560-
?W(?GRAY_BG, "Name or Initial Call", 38),
561-
?W(?GRAY_BG, " Reductions", 21),
562+
?W(?GRAY_BG, "Name|>Lable|>Initial Call", 45),
563+
?W(?GRAY_BG, " Reductions", 14),
562564
?W(?GRAY_BG, " MsgQueue", 10),
563565
?W(?GRAY_BG, "Current Function", 32)
564566
]),
@@ -586,8 +588,8 @@ render_top_n_view(binary_memory, MemoryList, Num, Pages, Page) ->
586588
render_top_n_view(reductions, ReductionList, Num, Pages, Page) ->
587589
Title = ?render([
588590
?W2(?GRAY_BG, "No | Pid", 16),
589-
?W2(?RED_BG, " Reductions", 21),
590-
?W(?GRAY_BG, "Name or Initial Call", 38),
591+
?W2(?RED_BG, " Reductions", 15),
592+
?W(?GRAY_BG, "Name|>Lable|>Initial Call", 45),
591593
?W(?GRAY_BG, " Memory", 13),
592594
?W(?GRAY_BG, " MsgQueue", 10),
593595
?W(?GRAY_BG, "Current Function", 33)
@@ -617,8 +619,8 @@ render_top_n_view(total_heap_size, HeapList, Num, Pages, Page) ->
617619
Title = ?render([
618620
?W2(?GRAY_BG, "No | Pid", 16),
619621
?W2(?RED_BG, " TotalHeapSize", 14),
620-
?W(?GRAY_BG, "Name or Initial Call", 38),
621-
?W(?GRAY_BG, " Reductions", 21),
622+
?W(?GRAY_BG, "Name|>Lable|>Initial Call", 45),
623+
?W(?GRAY_BG, " Reductions", 14),
622624
?W(?GRAY_BG, " MsgQueue", 10),
623625
?W(?GRAY_BG, "Current Function", 32)
624626
]),
@@ -647,9 +649,9 @@ render_top_n_view(message_queue_len, MQLenList, Num, Pages, Page) ->
647649
Title = ?render([
648650
?W2(?GRAY_BG, "No | Pid", 16),
649651
?W2(?RED_BG, " MsgQueue", 11),
650-
?W(?GRAY_BG, "Name or Initial Call", 37),
652+
?W(?GRAY_BG, "Name|>Lable|>Initial Call", 44),
651653
?W(?GRAY_BG, " Memory", 13),
652-
?W(?GRAY_BG, " Reductions", 21),
654+
?W(?GRAY_BG, " Reductions", 14),
653655
?W(?GRAY_BG, "Current Function", 33)
654656
]),
655657
{Start, ChoosePos} = observer_cli_lib:get_pos(Page, Num, Pages, erlang:length(MQLenList)),
@@ -682,19 +684,19 @@ notify_pause_status() ->
682684
?output("\e[31;1m PAUSE INPUT (p, r/rr, b/bb, h/hh, m/mm) to resume or q to quit \e[0m~n").
683685

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

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

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

699701
refresh_next_time(proc_count, Type, Interval) ->
700702
erlang:send_after(Interval, self(), {proc_count, Type});
@@ -756,15 +758,39 @@ process_bar_format_style(Percents, IsLastLine) ->
756758
get_top_n_info(Item) ->
757759
{Pid, Val, Call = [IsName | _]} = Item,
758760
{CurFun, InitialCall} = get_current_initial_call(Call),
759-
NameOrCall = display_name_or_initial_call(IsName, InitialCall, Pid),
760-
{Pid, Val, CurFun, NameOrCall}.
761+
Flag = display_unique_flag(IsName, InitialCall, Pid),
762+
{Pid, Val, CurFun, Flag}.
763+
764+
display_unique_flag(IsName, Call, Pid) ->
765+
case choose_name(IsName) of
766+
undefined ->
767+
case choose_lable(Pid) of
768+
undefined -> choose_call(Call, Pid);
769+
Lable -> Lable
770+
end;
771+
Name ->
772+
Name
773+
end.
761774

762-
display_name_or_initial_call(IsName, _Call, _Pid) when is_atom(IsName) ->
775+
choose_name(IsName) when is_atom(IsName) ->
763776
atom_to_list(IsName);
764-
display_name_or_initial_call(_IsName, {proc_lib, init_p, 5}, Pid) ->
777+
choose_name(_) ->
778+
undefined.
779+
780+
choose_lable(Pid) ->
781+
case
782+
erlang:function_exported(proc_lib, get_label, 1) andalso
783+
proc_lib:get_label(Pid)
784+
of
785+
false -> undefined;
786+
undefined -> undefined;
787+
Lable -> io_lib:format("~p", [Lable])
788+
end.
789+
790+
choose_call({proc_lib, init_p, 5}, Pid) ->
765791
%% translate gen_xxx behavior
766792
observer_cli_lib:mfa_to_list(proc_lib:translate_initial_call(Pid));
767-
display_name_or_initial_call(_IsName, Call, _Pid) ->
793+
choose_call(Call, _Pid) ->
768794
observer_cli_lib:mfa_to_list(Call).
769795

770796
get_refresh_prompt(proc_count, Type, Interval, Rows) ->
@@ -775,14 +801,16 @@ get_refresh_prompt(proc_window, Type, Interval, Rows) ->
775801
get_stable_system_info() ->
776802
OtpRelease = erlang:system_info(otp_release),
777803
SysVersion = erlang:system_info(system_version) -- "\n",
778-
{[
804+
{
805+
[
779806
OtpRelease,
780807
SysVersion,
781808
erlang:system_info(process_limit),
782809
erlang:system_info(port_limit),
783810
erlang:system_info(ets_limit)
784811
],
785-
erlang:system_info(port_parallelism)}.
812+
erlang:system_info(port_parallelism)
813+
}.
786814

787815
get_atom_status() ->
788816
try erlang:system_info(atom_limit) of

src/observer_cli_application.erl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ render_app_info(Row, CurPage, {Type, N}) ->
8282
begin
8383
{0, {element(N, I), S}, [App, C, M, R, Q, S, V]}
8484
end
85-
|| {App, I = {C, M, R, Q, S, V}} <- maps:to_list(app_info())
85+
|| {App, I = {C, M, R, Q, S, V}} <- maps:to_list(app_info())
8686
],
8787
{StartPos, SortList} = observer_cli_lib:sublist(List, Row, CurPage),
8888
InitColor = [

src/observer_cli_escriptize.erl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ remote_load(Node) ->
5959
begin
6060
recon:remote_load([Node], Mod)
6161
end
62-
|| Mod <- ?BEAM_MODS
62+
|| Mod <- ?BEAM_MODS
6363
].
6464

6565
random_local_node_name() ->

src/observer_cli_ets.erl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ render_ets_info(Rows, CurPage, Attr) ->
7474
begin
7575
get_ets_info(Tab, Attr)
7676
end
77-
|| Tab <- ets:all()
77+
|| Tab <- ets:all()
7878
],
7979
WordSize = erlang:system_info(wordsize),
8080
{_StartPos, SortEts} = observer_cli_lib:sublist(AllEts, Rows, CurPage),
@@ -123,7 +123,7 @@ render_ets_info(Rows, CurPage, Attr) ->
123123
?W(Owner, 14)
124124
])
125125
end
126-
|| {_, _, Ets} <- SortEts
126+
|| {_, _, Ets} <- SortEts
127127
],
128128
[Title | RowView].
129129

src/observer_cli_inet.erl

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -129,12 +129,14 @@ render_io_rows({LastIn, LastOut}) ->
129129
render_inet_rows([], Rows, #inet{func = inet_count, type = Type}) ->
130130
{[], io_lib:format("\e[32;1mGet nothing for recon:inet_count(~p, ~p)\e[0m~n", [Type, Rows])};
131131
render_inet_rows([], Rows, #inet{func = inet_window, type = Type, interval = Interval}) ->
132-
{[],
132+
{
133+
[],
133134
io_lib:format("\e[32;1mGet nothing for recon:inet_window(~p, ~p, ~p)\e[0m~n", [
134135
Type,
135136
Rows,
136137
Interval
137-
])};
138+
])
139+
};
138140
render_inet_rows(InetList, Num, #inet{
139141
type = Type,
140142
pages = Pages,
@@ -294,7 +296,7 @@ get_remote_ip(P) ->
294296
begin
295297
erlang:integer_to_list(A)
296298
end
297-
|| A <- erlang:tuple_to_list(Addr)
299+
|| A <- erlang:tuple_to_list(Addr)
298300
],
299301
string:join(AddrList, ".") ++ ":" ++ erlang:integer_to_list(Port);
300302
{error, Err} ->

0 commit comments

Comments
 (0)