Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does erlang record when a process started?

Tags:

erlang

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!

like image 794
Joe Avatar asked Jun 12 '13 14:06

Joe


People also ask

Is process alive Erlang?

This is called as is_process_alive(Pid). A Pid must refer to a process at the local node. It returns true if the process exists and is alive i.e., whether it is not exiting and has not exited.

What is process in Erlang?

14.1 Processes Erlang is designed for massive concurrency. Erlang processes are lightweight (grow and shrink dynamically) with small memory footprint, fast to create and terminate, and the scheduling overhead is low.

What is a PID in Erlang?

Each process in erlang has a process identifier ( Pid ) in this format <x.x.x> , x being a natural number. Below is an example of a Pid <0.1252.0> Pid can be used to send messages to the process using 'bang' ( ! ), also Pid can be bounded to a variable, both are shown below. MyProcessId = self().

How do you exit a process in Erlang?

A process can terminate itself by calling one of the BIFs exit(Reason), erlang:error(Reason), erlang:error(Reason, Args), erlang:fault(Reason) or erlang:fault(Reason, Args). The process then terminates with reason Reason for exit/1 or {Reason,Stack} for the others.


2 Answers

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:

approx_started = (time_t) p->approx_started;
erts_print(to, to_arg, "Started: %s", ctime(&approx_started));

Searching the rest of the source code for approx_started shows it being declared in erts/emulator/beam/erl_process.h as a member of struct process. It is written in erts/emulator/beam/erl_process.c. The only place it is read is in break.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".

like image 160
Roger Lipscombe Avatar answered Sep 28 '22 08:09

Roger Lipscombe


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.

like image 30
I GIVE CRAP ANSWERS Avatar answered Sep 28 '22 08:09

I GIVE CRAP ANSWERS