[erlang-questions] About erlang:statistics/1 and timeout values

Oscar Hellström <>
Thu Apr 23 16:33:17 CEST 2009


Oscar Hellström wrote:
> mats cronqvist wrote:
>   
>> Oscar Hellström <> writes:
>>
>>   
>>     
>>> Hi,
>>>
>>> I was looking at statistics in the erlang module and found that
>>> statistics(runtime) and statistics(wall_clock) returns something called
>>> Time_Sinse_Last_Call. I assume that this is "since last call by the
>>> calling process" and not a globally kept value. 
>>>     
>>>       
>>   AFAIK, time since last call is per emulator, not per process. Thus,
>>   it is worse than useless.
>>
>>   mats
>>   
>>     
> Yes, you're right. The call from the spawned process probably happened
> after the call from the shell process. This shows the actual behaviour:
> 29> spawn(fun() -> statistics(wall_clock) end), timer:sleep(10),
> statistics(wall_clock).
> {1363798390,14}
>
> This is sad though, since it really does make it worse than useless. So,
> back to (part of) the original question, how would we go about
> decrementing a timeout value between blocking calls. I could use now
> diffs, or erlang:start_timer/3... are there better ways?
>
> BTW, what is the difference between erlang:start_timer/3 and
> erlang:send_after/3. The documentation looks identical except a weird
> detail in the type specification:
> erlang:send_after(Time, Dest, Msg) -> TimerRef
> ...
> Dest = pid() | RegName
> LocalPid = pid() (of a process, alive or dead, on the local node)
>
> Here LocalPid is never mentioned before...
>
> erlang:start_timer(Time, Dest, Msg) -> TimerRef
> ...
> Dest = LocalPid | RegName
> LocalPid = pid() (of a process, alive or dead, on the local node)
>
> This seems to want to say the same thing, but does it correctly.
>   
Well, start_timer(Time, Dest, Msg) sends the message: {timeout,
TimerRef, Msg}
while send_after(Time, Dest, Msg) sends the message: Msg

It however be useful to be able to start a timer which doesn't send a
message, but makes it possible to know how many ms (or us) has passed
since the timer was started (maybe this isn't really a timer, but a
counter). Wall clock etc. is a bit risky I guess, since time could change.
> Thanks
>
>   

Best regards

-- 
Oscar Hellström, 
Office: +44 20 7655 0337
Mobile: +44 798 45 44 773
Erlang Training and Consulting Ltd
http://www.erlang-consulting.com/




More information about the erlang-questions mailing list