feat(sys_mon): Add proc_lib:initial_call/1 and current_stacktrace (4.3)
(Same as #6289 ) This adds the information from `proc_lib:initial_call/1` and the current stacktrace from the process info to `emqx_sys_mon:procinfo/1` to aid in debugging some warnings with no context such as the following: ``` 2021-11-23T12:33:59.387818+00:00 [warning] info: [{old_heap_block_size,45988046},{heap_block_size,22177879},{mbuf_size,0},{stack_size,40},{old_heap_size,22354134},{heap_size,7106339}], line: 130, mfa: emqx_sys_mon:handle_info/2, msg: large_heap, procinfo: [{pid,<0.2667.0>},{memory,579763664},{total_heap_size,68510672},{heap_size,22177879},{stack_size,40},{min_heap_size,233},{initial_call,{proc_lib,init_p,5}},{current_function,{gen,do_call,4}},{registered_name,[]},{status,running},{message_queue_len,360945},{group_leader,<0.1660.0>},{priority,normal},{trap_exit,false},{reductions,16493271},{last_calls,false},{catchlevel,4},{trace,0},{suspending,[]},{sequential_trace_token,[]},{error_handler,error_handler}] ```
This commit is contained in:
parent
18a9c0e177
commit
0260db6640
|
@ -182,7 +182,15 @@ procinfo(Pid) ->
|
||||||
case {emqx_vm:get_process_info(Pid), emqx_vm:get_process_gc_info(Pid)} of
|
case {emqx_vm:get_process_info(Pid), emqx_vm:get_process_gc_info(Pid)} of
|
||||||
{undefined, _} -> undefined;
|
{undefined, _} -> undefined;
|
||||||
{_, undefined} -> undefined;
|
{_, undefined} -> undefined;
|
||||||
{Info, GcInfo} -> Info ++ GcInfo
|
{Info, GcInfo} -> get_proc_lib_initial_call(Pid) ++ GcInfo ++ Info
|
||||||
|
end.
|
||||||
|
|
||||||
|
get_proc_lib_initial_call(Pid) ->
|
||||||
|
case proc_lib:initial_call(Pid) of
|
||||||
|
false ->
|
||||||
|
[];
|
||||||
|
InitialCall ->
|
||||||
|
[{proc_lib_initial_call, InitialCall}]
|
||||||
end.
|
end.
|
||||||
|
|
||||||
safe_publish(Event, WarnMsg) ->
|
safe_publish(Event, WarnMsg) ->
|
||||||
|
|
|
@ -62,7 +62,7 @@
|
||||||
]).
|
]).
|
||||||
|
|
||||||
-define(PROCESS_INFO_KEYS, [initial_call,
|
-define(PROCESS_INFO_KEYS, [initial_call,
|
||||||
current_function,
|
current_stacktrace,
|
||||||
registered_name,
|
registered_name,
|
||||||
status,
|
status,
|
||||||
message_queue_len,
|
message_queue_len,
|
||||||
|
|
|
@ -70,23 +70,51 @@ init_per_testcase(t_sys_mon2, Config) ->
|
||||||
(_) -> ok
|
(_) -> ok
|
||||||
end),
|
end),
|
||||||
Config;
|
Config;
|
||||||
|
init_per_testcase(t_procinfo, Config) ->
|
||||||
|
emqx_ct_helpers:boot_modules(all),
|
||||||
|
emqx_ct_helpers:start_apps([]),
|
||||||
|
ok = meck:new(emqx_vm, [passthrough, no_history]),
|
||||||
|
Config;
|
||||||
init_per_testcase(_, Config) ->
|
init_per_testcase(_, Config) ->
|
||||||
emqx_ct_helpers:boot_modules(all),
|
emqx_ct_helpers:boot_modules(all),
|
||||||
emqx_ct_helpers:start_apps([]),
|
emqx_ct_helpers:start_apps([]),
|
||||||
Config.
|
Config.
|
||||||
|
|
||||||
|
end_per_testcase(t_procinfo, _Config) ->
|
||||||
|
ok = meck:unload(emqx_vm),
|
||||||
|
emqx_ct_helpers:stop_apps([]);
|
||||||
end_per_testcase(_, _Config) ->
|
end_per_testcase(_, _Config) ->
|
||||||
emqx_ct_helpers:stop_apps([]).
|
emqx_ct_helpers:stop_apps([]).
|
||||||
|
|
||||||
t_procinfo(_) ->
|
t_procinfo(_) ->
|
||||||
ok = meck:new(emqx_vm, [passthrough, no_history]),
|
|
||||||
ok = meck:expect(emqx_vm, get_process_info, fun(_) -> [] end),
|
ok = meck:expect(emqx_vm, get_process_info, fun(_) -> [] end),
|
||||||
ok = meck:expect(emqx_vm, get_process_gc_info, fun(_) -> [] end),
|
ok = meck:expect(emqx_vm, get_process_gc_info, fun(_) -> [] end),
|
||||||
?assertEqual([], emqx_sys_mon:procinfo([])),
|
?assertEqual([], emqx_sys_mon:procinfo([])),
|
||||||
ok = meck:expect(emqx_vm, get_process_info, fun(_) -> ok end),
|
ok = meck:expect(emqx_vm, get_process_info, fun(_) -> ok end),
|
||||||
ok = meck:expect(emqx_vm, get_process_gc_info, fun(_) -> undefined end),
|
ok = meck:expect(emqx_vm, get_process_gc_info, fun(_) -> undefined end),
|
||||||
?assertEqual(undefined, emqx_sys_mon:procinfo([])),
|
?assertEqual(undefined, emqx_sys_mon:procinfo([])).
|
||||||
ok = meck:unload(emqx_vm).
|
|
||||||
|
t_procinfo_initial_call_and_stacktrace(_) ->
|
||||||
|
SomePid = proc_lib:spawn(?MODULE, some_function, [self(), arg2]),
|
||||||
|
receive
|
||||||
|
{spawned, SomePid} ->
|
||||||
|
ok
|
||||||
|
after 100 ->
|
||||||
|
error(process_not_spawned)
|
||||||
|
end,
|
||||||
|
ProcInfo = emqx_sys_mon:procinfo(SomePid),
|
||||||
|
?assertEqual(
|
||||||
|
{?MODULE, some_function, ['Argument__1','Argument__2']},
|
||||||
|
proplists:get_value(proc_lib_initial_call, ProcInfo)),
|
||||||
|
?assertMatch(
|
||||||
|
[{?MODULE, some_function, 2,
|
||||||
|
[{file, _},
|
||||||
|
{line, _}]},
|
||||||
|
{proc_lib, init_p_do_apply, 3,
|
||||||
|
[{file, _},
|
||||||
|
{line, _}]}],
|
||||||
|
proplists:get_value(current_stacktrace, ProcInfo)),
|
||||||
|
SomePid ! stop.
|
||||||
|
|
||||||
t_sys_mon(_Config) ->
|
t_sys_mon(_Config) ->
|
||||||
lists:foreach(
|
lists:foreach(
|
||||||
|
@ -120,3 +148,10 @@ validate_sys_mon_info(PidOrPort, SysMonName,ValidateInfo, InfoOrPort) ->
|
||||||
concat_str(ValidateInfo, InfoOrPort, Info) ->
|
concat_str(ValidateInfo, InfoOrPort, Info) ->
|
||||||
WarnInfo = io_lib:format(ValidateInfo, [InfoOrPort, Info]),
|
WarnInfo = io_lib:format(ValidateInfo, [InfoOrPort, Info]),
|
||||||
lists:flatten(WarnInfo).
|
lists:flatten(WarnInfo).
|
||||||
|
|
||||||
|
some_function(Parent, _Arg2) ->
|
||||||
|
Parent ! {spawned, self()},
|
||||||
|
receive
|
||||||
|
stop ->
|
||||||
|
ok
|
||||||
|
end.
|
||||||
|
|
Loading…
Reference in New Issue