diff --git a/lib/kernel/test/logger_legacy_SUITE.erl b/lib/kernel/test/logger_legacy_SUITE.erl index 997b47e239a2..2d891eb7f274 100644 --- a/lib/kernel/test/logger_legacy_SUITE.erl +++ b/lib/kernel/test/logger_legacy_SUITE.erl @@ -190,7 +190,7 @@ sasl_reports(Config) -> [[{initial_call,_}, {pid,ChPid}, {registered_name,[]}, - {process_description, undefined}, + {process_label, undefined}, {error_info,{error,{badmatch,b},_}}, {ancestors,_}, {message_queue_len,_}, @@ -204,7 +204,7 @@ sasl_reports(Config) -> {reductions,_}], [{neighbour,[{pid,Neighbour}, {registered_name,_}, - {process_description, undefined}, + {process_label, undefined}, {initial_call,_}, {current_function,_}, {ancestors,_}, diff --git a/lib/observer/doc/src/observer_ug.xml b/lib/observer/doc/src/observer_ug.xml index 413ff20143a7..f6b1ca02df6d 100644 --- a/lib/observer/doc/src/observer_ug.xml +++ b/lib/observer/doc/src/observer_ug.xml @@ -164,7 +164,7 @@ Pid

The process identifier.

Description -

Registered name, process description or initial function.

+

Registered name, process label or initial function.

Reds

The number of reductions executed on the process. This can be presented as accumulated values or as values since the last update.

diff --git a/lib/observer/src/observer_procinfo.erl b/lib/observer/src/observer_procinfo.erl index 09b21df53738..6c828293fdd4 100644 --- a/lib/observer/src/observer_procinfo.erl +++ b/lib/observer/src/observer_procinfo.erl @@ -449,7 +449,7 @@ filter_monitor_info() -> get_name(Pid) -> case observer_wx:try_rpc(node(Pid), erlang, process_info, [Pid, registered_name]) of [] -> - case observer_wx:try_rpc(node(Pid), proc_lib, get_process_description, [Pid]) of + case observer_wx:try_rpc(node(Pid), proc_lib, get_label, [Pid]) of {error, _} -> io_lib:format("~p",[Pid]); undefined -> diff --git a/lib/runtime_tools/src/appmon_info.erl b/lib/runtime_tools/src/appmon_info.erl index 84d96942cdbd..856210f89b4c 100644 --- a/lib/runtime_tools/src/appmon_info.erl +++ b/lib/runtime_tools/src/appmon_info.erl @@ -711,7 +711,7 @@ format(P) when is_pid(P) -> case process_info(P, registered_name) of {registered_name, Name} -> atom_to_list(Name); _ -> - case proc_lib:get_process_description(P) of + case proc_lib:get_label(P) of undefined -> pid_to_list(P); Id when is_binary(Id) -> diff --git a/lib/runtime_tools/src/observer_backend.erl b/lib/runtime_tools/src/observer_backend.erl index 0f935edc0829..a0ed9fc7ba4f 100644 --- a/lib/runtime_tools/src/observer_backend.erl +++ b/lib/runtime_tools/src/observer_backend.erl @@ -169,11 +169,19 @@ get_mnesia_loop(Parent, {Match, Cont}) -> get_port_list() -> ExtraItems = [monitors,monitored_by,parallelism,locking,queue_size,memory], - [begin - [{port_id,P}|erlang:port_info(P)] ++ - port_info(P,ExtraItems) ++ - inet_port_extra(erlang:port_info(P, name), P) - end || P <- erlang:ports()]. + PortInfo = + fun(P, Acc) -> + case erlang:port_info(P) of + undefined -> + Acc; + Info -> + [{port_id,P}|Info] ++ + port_info(P,ExtraItems) ++ + inet_port_extra(erlang:port_info(P, name), P) + end + end, + PIs = lists:foldl(PortInfo, [], erlang:ports()), + lists:reverse(PIs). port_info(P,[Item|Items]) -> case erlang:port_info(P,Item) of @@ -576,14 +584,14 @@ etop_collect([P|Ps], Acc) when P =:= self() -> etop_collect(Ps, Acc); etop_collect([P|Ps], Acc) -> Fs = [registered_name,initial_call, - {dictionary, '$initial_call'}, {dictionary, '$process_description'}, + {dictionary, '$initial_call'}, {dictionary, '$process_label'}, memory,reductions,current_function,message_queue_len], case process_info(P, Fs) of undefined -> etop_collect(Ps, Acc); [{registered_name,Reg},{initial_call,Initial}, {{dictionary, '$initial_call'}, DictInitial}, - {{dictionary, '$process_description'}, ProcId}, + {{dictionary, '$process_label'}, ProcId}, {memory,Mem},{reductions,Reds}, {current_function,Current},{message_queue_len,Qlen} ] -> diff --git a/lib/stdlib/doc/src/proc_lib.xml b/lib/stdlib/doc/src/proc_lib.xml index 9c6cd8a4a301..8d1a466dadd7 100644 --- a/lib/stdlib/doc/src/proc_lib.xml +++ b/lib/stdlib/doc/src/proc_lib.xml @@ -160,12 +160,12 @@ - - Returns the user set process description. + + Returns the user-set process label. -

Returns undefined or the description for the process - Pid set with - proc_lib:set_process_description/1. +

Returns either undefined or the label for the process + Pid set with + proc_lib:set_label/1.

@@ -341,19 +341,18 @@ init(Parent) -> - - Set process description. + + Set process label. -

Set a description for the current process. - The primary use is to aid debugging of non registered processes. - The process description can be used in tools and crash reports to identity processes +

Set a label for the current process. + The primary purpose is to aid in debugging unregistered processes. + The process label can be used in tools and crash reports to identify processes but it doesn't have to be unique or an atom, as a registered name needs to be. - The process description can be any term, for example {worker_process, 1..N}. + The process label can be any term, for example {worker_process, 1..N}.

- Use - proc_lib:get_process_description/1 to lookup the - a process description. + Use + proc_lib:get_label/1 to lookup the process description.

diff --git a/lib/stdlib/src/c.erl b/lib/stdlib/src/c.erl index 152deb6509c0..5c5eb1ee8be9 100644 --- a/lib/stdlib/src/c.erl +++ b/lib/stdlib/src/c.erl @@ -674,7 +674,7 @@ mfa_string(X) -> display_info(Pid) -> PInfo0 = pinfo(Pid, [initial_call, current_function, reductions, message_queue_len, heap_size, stack_size, registered_name, - {dictionary, '$process_description'}, + {dictionary, '$process_label'}, {dictionary, '$initial_call'}]), PInfo = case PInfo0 of PInfo0 when is_list(PInfo0) -> @@ -713,7 +713,7 @@ display_info(Pid) -> end. fetch_name([], Info) -> - case fetch({dictionary, '$process_description'}, Info) of + case fetch({dictionary, '$process_label'}, Info) of undefined -> ""; Id -> format_name(Id) end; @@ -768,9 +768,9 @@ patch_old_pinfo(undefined) -> undefined; patch_old_pinfo(KeyList0) -> {value, {dictionary, Dict}, KeyList} = lists:keytake(dictionary, 1, KeyList0), - PD = proplists:get_value('$process_description', Dict, undefined), + PD = proplists:get_value('$process_label', Dict, undefined), IC = proplists:get_value('$initial_call', Dict, undefined), - [{'$process_description', PD}, {'$initial_call', IC} | KeyList]. + [{'$process_label', PD}, {'$initial_call', IC} | KeyList]. fetch(Key, Info) -> case lists:keyfind(Key, 1, Info) of diff --git a/lib/stdlib/src/proc_lib.erl b/lib/stdlib/src/proc_lib.erl index 74a0f8adf3ac..faa6b0ca9f16 100644 --- a/lib/stdlib/src/proc_lib.erl +++ b/lib/stdlib/src/proc_lib.erl @@ -35,8 +35,7 @@ init_p/3,init_p/5,format/1,format/2,format/3,report_cb/2, initial_call/1, translate_initial_call/1, - set_process_description/1, - get_process_description/1, + set_label/1, get_label/1, stop/1, stop/3]). %% Internal exports. @@ -525,23 +524,25 @@ translate_initial_call(DictOrPid) -> end. %% ----------------------------------------------------- -%% [get] set_process_description/1 +%% [get] set_label/1 %% Add and fetch process id's to aid in debugging %% ----------------------------------------------------- --spec set_process_description(Id :: term()) -> ok. -set_process_description(Id) -> - put('$process_description', Id), +-spec set_label(Label) -> ok when + Label :: term(). +set_label(Label) -> + put('$process_label', Label), ok. --spec get_process_description(Pid :: pid()) -> undefined | term(). -get_process_description(Pid) -> +-spec get_label(Pid) -> undefined | term() when + Pid :: pid(). +get_label(Pid) -> case Pid == self() of true -> - get('$process_description'); + get('$process_label'); false -> - try get_process_info(Pid, {dictionary, '$process_description'}) of - {process_description, Id} -> Id; + try get_process_info(Pid, {dictionary, '$process_label'}) of + {process_label, Id} -> Id; _ -> undefined catch _:_ -> %% Old Node undefined @@ -628,7 +629,7 @@ my_info_1(Class, Reason, Stacktrace) -> {dictionary, Dict} = lists:keyfind(dictionary,1,PInfo), [{pid, self()}, lists:keyfind(registered_name,1,PInfo), - {process_description, get_process_description(self())}, + {process_label, get_label(self())}, {error_info, {Class,Reason,Stacktrace}}, {ancestors, get_ancestors()}, lists:keyfind(message_queue_len,1,PInfo), @@ -683,7 +684,7 @@ clean_dict([{'$ancestors',_}|Dict]) -> clean_dict(Dict); clean_dict([{'$initial_call',_}|Dict]) -> clean_dict(Dict); -clean_dict([{'$process_description',_}|Dict]) -> +clean_dict([{'$process_label',_}|Dict]) -> clean_dict(Dict); clean_dict([E|Dict]) -> [E|clean_dict(Dict)]; @@ -735,7 +736,7 @@ make_neighbour_report(Pid) -> ], ProcInfo = get_process_info(Pid, Keys), - DictKeys = [{dictionary, '$process_description'}, + DictKeys = [{dictionary, '$process_label'}, {dictionary, '$initial_call'}, {dictionary, '$ancestors'}], @@ -748,7 +749,7 @@ make_neighbour_report(Pid) -> false -> [{pid, Pid}, lists:keyfind(registered_name,1,ProcInfo), - dict_find_info('$process_description', DictInfo, undefined), + dict_find_info('$process_label', DictInfo, undefined), get_initial_call(DictInfo, ProcInfo), lists:keyfind(current_function, 1, ProcInfo), dict_find_info('$ancestors', DictInfo, []), @@ -840,8 +841,8 @@ no_trap([]) -> get_process_info(Pid, Tag) -> translate_process_info(Tag, catch proc_info(Pid, Tag)). -translate_process_info({dictionary, '$process_description'} = Tag, {Tag, Value}) -> - {process_description, Value}; +translate_process_info({dictionary, '$process_label'} = Tag, {Tag, Value}) -> + {process_label, Value}; translate_process_info(_ , {'EXIT', _}) -> undefined; translate_process_info(_, Result) -> @@ -1054,7 +1055,7 @@ format_report(Rep, Indent0, Extra, Limit) -> format_rep([{initial_call,InitialCall}|Rep], Indent, Extra, Limit) -> [format_mfa(Indent, InitialCall, Extra, Limit)| format_rep(Rep, Indent, Extra, Limit)]; -format_rep([{process_description,undefined}|Rep], Indent, Extra, Limit) -> +format_rep([{process_label,undefined}|Rep], Indent, Extra, Limit) -> format_rep(Rep, Indent, Extra, Limit); format_rep([{Tag,Data}|Rep], Indent, Extra, Limit) -> [format_tag(Indent, Tag, Data, Extra, Limit)| diff --git a/lib/stdlib/test/proc_lib_SUITE.erl b/lib/stdlib/test/proc_lib_SUITE.erl index 8675f55694ef..f3fafb2bc80d 100644 --- a/lib/stdlib/test/proc_lib_SUITE.erl +++ b/lib/stdlib/test/proc_lib_SUITE.erl @@ -30,8 +30,8 @@ sync_start_monitor/1, sync_start_monitor_link/1, sync_start_timeout/1, sync_start_link_timeout/1, sync_start_monitor_link_timeout/1, - spawn_opt/1, sp1/0, sp2/0, sp3/1, sp4/2, sp5/1, sp6/1, sp7/1, - sp8/1, sp9/1, sp10/1, + spawn_opt/1, sp1/0, sp1_with_label/0, sp2/0, sp3/1, sp4/2, + sp5/1, sp6/1, sp7/1, sp8/1, sp9/1, sp10/1, '\x{447}'/0, hibernate/1, stop/1, t_format/1, t_format_arbitrary/1]). -export([ otp_6345/1, init_dont_hang/1]). @@ -135,17 +135,18 @@ crash_1(_Config) -> ct:sleep(100), {?MODULE,sp2,[]} = proc_lib:initial_call(Pid4), {?MODULE,sp2,0} = proc_lib:translate_initial_call(Pid4), - {test, sp2} = proc_lib:get_process_description(Pid4), + {test, sp2} = proc_lib:get_label(Pid4), %% Check this, if changed fix c.erl and runtime_tools %% which uses the 'internal' dictionary name as an optimization. - {_, {test, sp2}} = process_info(Pid4, {dictionary, '$process_description'}), + {_, {test, sp2}} = process_info(Pid4, {dictionary, '$process_label'}), Pid4 ! die, Exp4 = [{initial_call,{?MODULE,sp2,[]}}, - {process_description, {test, sp2}}, + {process_label, {test, sp2}}, {ancestors,[self()]}, {error_info,{exit,die,{stacktrace}}}], - Links4 = [[{initial_call,{?MODULE,sp1,[]}}, + Links4 = [[{initial_call,{?MODULE,sp1_with_label,[]}}, + {process_label, {test, sp1_with_label}}, {ancestors,[Pid4,self()]}]], analyse_crash(Pid4, Exp4, Links4), @@ -391,11 +392,15 @@ sp1() -> _ -> sp1() end. +sp1_with_label() -> + ok = proc_lib:set_label({test, ?FUNCTION_NAME}), + sp1(). + sp2() -> - ok = proc_lib:set_process_description({test, ?FUNCTION_NAME}), - {test, ?FUNCTION_NAME} = proc_lib:get_process_description(self()), + ok = proc_lib:set_label({test, ?FUNCTION_NAME}), + {test, ?FUNCTION_NAME} = proc_lib:get_label(self()), - _Pid = proc_lib:spawn_link(?MODULE, sp1, []), + _Pid = proc_lib:spawn_link(?MODULE, sp1_with_label, []), receive die -> exit(die); _ -> sp1()