[erlang-questions] System timers, now/0, and instrumentation

Raimo Niskanen raimo+erlang-questions@REDACTED
Wed May 25 11:07:30 CEST 2011


On Tue, May 24, 2011 at 02:32:47AM -0700, Amy Lear wrote:
> On Tue, May 24, 2011 at 2:02 AM, Magnus Henoch <
> magnus.henoch@REDACTED> wrote:
> 
> > ----- "Amy Lear" <octopusfluff@REDACTED> wrote:
> >
> > > The issue here as I understand it is that the system clock itself
> > > can't report things in the microsecond range (msdn states the
> > > granularity is between 10ms and 15ms:
> > >
> > http://msdn.microsoft.com/en-us/library/system.datetimeoffset.utcnow.aspx
> > > ), but the real values are being mangled to provide those guaranteed
> > > unique values. Given that now/0 is the obvious means of doing
> > > measurement for an erlang user -- and in fact the instrumentation
> > > tools that ship with erlang also appear to rely on it -- this results
> > > in puzzling and undesired behavior.
> >
> > Have you tried os:timestamp/0?  It's like now/0 but without the
> > uniqueness guarantee.  I'm not sure what granularity it has on
> > Windows, though.
> >
> > Hope this helps,
> >
> 
> Unfortunately, it appears that the granularity of os:timestamp/0 is no finer
> than 1 ms, and the minimum resolution appears to be machine-dependant. Msdn
> research also suggests that the 1ms resolution timer is slower to access
> than the normal system clock, which could matter in some circumstances.
> Conversely, dropping the uniqueness facet and being higher resolution than
> now/0 does have some potential usefulness, but the erlang documentation
> indicates that the provided profiling tools rely on now/0.

The reason the provided profiling tools rely on now/0 is mostly
that it has been around as long as they, plus the fact that
now/0 never moves backwards, mostly moves forwards kind
of sanely and is fairly lightweight makes it a nice but possibly
somewhat inaccurate compromise for a generic profiling tool.

> 
> My question about instrumentation stands: is there currently a way to do
> high resolution profiling in Erlang on Windows? Is the requisite work of
> setting up sub-ms resolution timers simply not done/too much work to
> attempt?

No. There is currenly nothing better built in than erlang:now/0 and
os:timestamp/0. They could probably be improved on Windows but it
was quite a while since we had anyone requiring (as in providing
resources) us developing Erlang for Windows.

Side note: timer:tc/2,3 is about / has been converted to use
os:timestamp/0 instead.

> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://erlang.org/mailman/listinfo/erlang-questions


-- 

/ Raimo Niskanen, Erlang/OTP, Ericsson AB



More information about the erlang-questions mailing list