I'm working with monitoring an Erlang application and I'm currently trying to determine how long a specific PID has been running. Absolute timestamp or duration would work for me, but I do not see either of those bits of data in process_info or via the sys module. Is there a way to get this information from within the Erlang VM?
I can get the start time of the overall VM from the ps command, but that doesn't have any visibility of individual Erlang processes.
Edit:
I've noticed that when the VM crashes, the erl_crash.dump contains a started timestamp for each process, so I know it's in there!
I was looking in toolbar:start(). the process monitor and don't look time alive or time init, but it is easy to make. In dictionary of process you can save a value when init and that this process can respond to other process about this value.
For read value in dictionary process you can use get/1 and for save use put/2 (first key and second value).
Respond to other process about this value is same that others responses, etc.
Write a process which manages this. Since you can find the PID of the given process, you can also set a
monitor
on the process. Then, if the process errors out, you will get a message in your mailbox.I would guess this could form the basis for a solution for you.
tl;dr: yes, but you can't get to it.
If you dig into the OTP source code at https://github.com/erlang/otp, you'll find (by searching for "erl_crash") that the file responsible for writing the crash dump is called
erts/emulator/beam/break.c
.Searching that file for "started" (it's both a good guess, and it's what appears in the crash dump) will get you to lines 248-249 (all line numbers based on the OTP-18.3.1 tag), which look like this:
Searching the rest of the source code for
approx_started
shows it being declared inerts/emulator/beam/erl_process.h
as a member ofstruct process
. It is written inerts/emulator/beam/erl_process.c
. The only place it is read is inbreak.c
, when writing the crash dump.So, yes, Erlang does record the (approximate) time that a process was started. But, no, you can't get to it.
I have no idea why it's "approximate".