erlang:system_info( start_time ) as date_time?

Rickard Green rickard@REDACTED
Tue Apr 7 14:37:15 CEST 2020


On Tue, Apr 7, 2020 at 1:02 PM Сергей Прохоров <seriy.pr@REDACTED> wrote:
>
> I have a snippet with a couple of ways to calculate the node uptime:
>
> https://gist.github.com/seriyps/db52ff310021ee243d1e4b7fe48a3442


> %% @doc uptime in native time units
> uptime() ->
>     Now = erlang:system_time(),
>    StartTime = erlang:time_offset() + erlang:system_info(start_time), Now
- StartTime.

You don't want to go via system time in order to calculate uptime. You will
just introduce a potential error since time offset can change if using
singe/multi time warp mode and make the calculation more expensive than it
needs to be. Use monotonic time directly instead:

uptime() ->
    erlang:monotonic_time() - erlang:system_info(start_time).

Regards,
Rickard
--
Rickard Green, Erlang/OTP, Ericsson AB
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20200407/bdb14bf5/attachment.htm>


More information about the erlang-questions mailing list