Skip to content

Commit

Permalink
Change API name to [s|g]et_label/1
Browse files Browse the repository at this point in the history
After a long intenal name debate,
we reverted the function names :-)
  • Loading branch information
dgud committed Oct 17, 2023
1 parent 62101ab commit abea240
Show file tree
Hide file tree
Showing 9 changed files with 70 additions and 57 deletions.
4 changes: 2 additions & 2 deletions lib/kernel/test/logger_legacy_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -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,_},
Expand All @@ -204,7 +204,7 @@ sasl_reports(Config) ->
{reductions,_}],
[{neighbour,[{pid,Neighbour},
{registered_name,_},
{process_description, undefined},
{process_label, undefined},
{initial_call,_},
{current_function,_},
{ancestors,_},
Expand Down
2 changes: 1 addition & 1 deletion lib/observer/doc/src/observer_ug.xml
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@
<tag>Pid</tag>
<item><p>The process identifier.</p></item>
<tag>Description</tag>
<item><p>Registered name, process description or initial function.</p></item>
<item><p>Registered name, <seemfa marker="stdlib:proclib#set_label/1">process label</seemfa> or initial function.</p></item>
<tag>Reds</tag>
<item><p>The number of reductions executed on the process.
This can be presented as accumulated values or as values since the last update.</p></item>
Expand Down
2 changes: 1 addition & 1 deletion lib/observer/src/observer_procinfo.erl
Original file line number Diff line number Diff line change
Expand Up @@ -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 ->
Expand Down
2 changes: 1 addition & 1 deletion lib/runtime_tools/src/appmon_info.erl
Original file line number Diff line number Diff line change
Expand Up @@ -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) ->
Expand Down
22 changes: 15 additions & 7 deletions lib/runtime_tools/src/observer_backend.erl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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}
] ->
Expand Down
27 changes: 13 additions & 14 deletions lib/stdlib/doc/src/proc_lib.xml
Original file line number Diff line number Diff line change
Expand Up @@ -160,12 +160,12 @@
</func>

<func>
<name name="get_process_description" arity="1" since="OTP 26.2"/>
<fsummary>Returns the user set process description.</fsummary>
<name name="get_label" arity="1" since="OTP 26.2"/>
<fsummary>Returns the user-set process label.</fsummary>
<desc>
<p>Returns <c>undefined</c> or the description for the process
<anno>Pid</anno> set with <seemfa marker="#set_process_description/1">
<c>proc_lib:set_process_description/1</c></seemfa>.
<p>Returns either <c>undefined</c> or the label for the process
<anno>Pid</anno> set with <seemfa marker="#set_label/1">
<c>proc_lib:set_label/1</c></seemfa>.
</p>
</desc>
</func>
Expand Down Expand Up @@ -341,19 +341,18 @@ init(Parent) ->
</func>

<func>
<name name="set_process_description" arity="1" since="OTP 26.2"/>
<fsummary>Set process description.</fsummary>
<name name="set_label" arity="1" since="OTP 26.2"/>
<fsummary>Set process label.</fsummary>
<desc>
<p>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
<p>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 <c>{worker_process, 1..N}</c>.
The process label can be any term, for example <c>{worker_process, 1..N}</c>.
</p>
<p>
Use <seemfa marker="#get_process_description/1">
<c>proc_lib:get_process_description/1</c></seemfa> to lookup the
a process description.
Use <seemfa marker="#get_label/1">
<c>proc_lib:get_label/1</c></seemfa> to lookup the process description.
</p>
</desc>
</func>
Expand Down
8 changes: 4 additions & 4 deletions lib/stdlib/src/c.erl
Original file line number Diff line number Diff line change
Expand Up @@ -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) ->
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down
37 changes: 19 additions & 18 deletions lib/stdlib/src/proc_lib.erl
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -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)];
Expand Down Expand Up @@ -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'}],

Expand All @@ -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, []),
Expand Down Expand Up @@ -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) ->
Expand Down Expand Up @@ -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)|
Expand Down
23 changes: 14 additions & 9 deletions lib/stdlib/test/proc_lib_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -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]).

Expand Down Expand Up @@ -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),

Expand Down Expand Up @@ -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()
Expand Down

0 comments on commit abea240

Please sign in to comment.