获取收到的消息的时间 [英] Getting the time of the received message
问题描述
我想根据接收到的消息的频率来计算某些内容给gen_server。
p>例如消息1,有一段时间,消息2有一段时间。
得到消息之间的时间。
谢谢
您可以使用 statistics(wall_clock)
,每次收到消息。
它返回的元组的第二个成员将是两个接收之间的时间(以毫秒为单位)。
编辑:
作为rvirding在他的评论中提到,你也可以使用 now()
,然后相应地计算时差。看看你的Erlang / $的$ code $ $ ERL_TOP / lib / stdlib / src / 目录中的 supervisor.erl
OTP分发。该模块的最后一行( addRestart
, inPeriod
和差异
)使用 now()
计算重新启动的频率。
How does one get the time of the received message in Erlang?
I want to calculate something according to the frequency of the received messages to the gen_server.
e.g. message 1, some time, message 2 some time. get the time between messages.
Thanks
You can use statistics(wall_clock)
each time you receive a message.
The second member of the tuple it returns will be the time between the two receives (in milliseconds).
Edit:
As rvirding mentions in his comment, you can also use now()
and then calculate the time difference accordingly. Take a look at supervisor.erl
found in the $ERL_TOP/lib/stdlib/src/
directory of your Erlang/OTP distribution. The last lines of that module (functions addRestart
, inPeriod
and difference
) calculate the frequency of restarts using now()
.
这篇关于获取收到的消息的时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!