Does erlang record when a process started?

前端 未结 3 1529
予麋鹿
予麋鹿 2021-01-18 09:22

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 wor

3条回答
  •  臣服心动
    2021-01-18 09:34

    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".

提交回复
热议问题