erlang记录何时进程开始? [英] Does erlang record when a process started?
问题描述
我正在监控Erlang应用程序,目前正在尝试确定特定PID运行多长时间。绝对时间戳或持续时间对我来说是有效的,但是我没有看到process_info或sys模块中的任何一个数据。有没有办法从Erlang VM中获取这些信息?
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?
我可以从ps命令获取整个VM的开始时间,但是没有任何可见性的单个Erlang进程。
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.
编辑:
我注意到,当VM崩溃时,erl_crash.dump包含一个开始的时间戳对于每个过程,所以我知道它在那里!
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!
推荐答案
tl; dr:是的,但你不能
如果您在 https://github.com/erlang/otp ,您会发现(通过搜索erl_crash),负责编写崩溃转储的文件称为 erts / emulator / beam / break.c
。
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
.
搜索该文件为开始(这是一个很好的猜测,这是出现的在崩溃转储)将会让你到第248-249行(基于OTP-18.3.1标签的所有行号),如下所示:
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));
搜索其余的源代码约_started
显示它在 erts / emulator / beam / erl_process.h
中声明为 struct process
的成员。在 erts / emulator / beam / erl_process.c
中写入。 只有的位置是 在 break.c
中写入崩溃转储。
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.
所以,是的,Erlang 记录一个进程开始的(大概)时间。但是,不,你不能得到它。
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".
这篇关于erlang记录何时进程开始?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!