Getting gen_server/gen_fsm state for debugging
There is actually a function that returns the state directly: sys:get_state/1,2
. It accepts pid or name of the process and can optionally be given a timeout.
Use sys:get_status/1,2
function. It's definition is:
get_status(Name,Timeout) ->
{status, Pid, {module, Mod}, [PDict, SysState, Parent, Dbg, Misc]}
SysState
will contain state of the process. It works for all processes using OTP behaviors and other processes implementing proc_lib
and sys
requirements.