Getting the time of the received message

删除回忆录丶 提交于 2019-12-21 02:52:08

问题


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


回答1:


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().



来源:https://stackoverflow.com/questions/4281251/getting-the-time-of-the-received-message

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!