[erlang-questions] Node uptime

Chandru chandrashekhar.mullaparthi@REDACTED
Tue Mar 16 14:47:13 CET 2010


On 16 March 2010 13:25, Ulf Wiger <ulf.wiger@REDACTED> wrote:

> On Tue, 16 Mar 2010 14:09:51 +0100, Håkan Huss <huss01@REDACTED> wrote:
>
>  Check out erlang:statistics(wall_clock).
>>
>> /Håkan
>>
>
> statistics(wall_clock) wraps after ca 37 hours.
>
> From overload.erl:
>
> %% Mask equal to 2^27 - 1, used below.
> -define(mask27, 16#7ffffff).
>
> %% Returns number of milliseconds in the range [0, 2^27 - 1]. Must have
> %% this since statistics(wall_clock) wraps. Having 2^27 -1 as the max
> %% assures that we always get non-negative integers. 2^27 milliseconds
> %% are approx. 37.28 hours.
> get_now() ->
>    element(1, statistics(wall_clock)) band ?mask27.
>
> This means that unless you get in from the start and continuously
> sample statistics(wall_clock), it can't be relied upon.
>
>
Is that correct? Here is the output from one of our nodes.

34> util:uptime().
"55 days, 11 hours, 58 minutes and 3 seconds"

35> erlang:statistics(wall_clock).
{4795096445,13307}

uptime/0 is implemented as:
uptime() ->
    {UpTime, _} = erlang:statistics(wall_clock),
    {D, {H, M, S}} = calendar:seconds_to_daystime(UpTime div 1000),
    lists:flatten(io_lib:format("~p days, ~p hours, ~p minutes and ~p
seconds", [D,H,M,S])).

cheers
Chandru


More information about the erlang-questions mailing list