bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: timevar: 3/3: use clock_gettime to get wall clock time


From: Bruno Haible
Subject: Re: timevar: 3/3: use clock_gettime to get wall clock time
Date: Sat, 13 Oct 2018 15:41:23 +0200
User-agent: KMail/5.1.3 (Linux/4.4.0-137-generic; KDE/5.18.0; x86_64; ; )

Hi Akim,

> But it felt weird to use a double, the number of significant decimal digits
> of a float (about 7) seems enough.

This is the line I'm talking about:

  timer->wall += stop->wall - start->wall;

24 bits of precision might be sufficient for timer->wall; for a measured
time, the user won't care about more than 3 decimal places.
But the values start->wall and stop->wall can have many digits with little
difference, depending on the gethrxtime() implementation. If gethrxtime()
is based on gettime(), start->wall and stop->wall will both be around
24.8 * 365.2422 * 24 * 3600 * 1000000000 = 7.8e17, and the resolution you
can capture of it with 24 bits is 7.8e17 / 2^24 = 46 seconds, whereas with
a 'double' you can get a resolution of 7.8e17 / 2^53 = 0.1 microseconds.

> Let’s keep xtime_t for the measurement, and just use floats when
> displaying.  WDYT?

Yes, this is good.

> >> there are no direct link dependencies in timevar, only indirect
> >> ones via the modules it depends upon.  What do you mean?
> > 
> > I mean that in this situation, the user of the module does not want to
> > perform a recursive search across the dependencies of the module, to
> > discover the link dependencies. That’s your job as author of the module.
> 
> Doh.  I was expecting gnulib-tool to do that.  Why doesn’t it?

The 'Includes', as well that the 'Link' field, are part of the contract
between the author of the module and its user. When it changes, the user
has to change their source code (for 'Includes' changes) or their Makefile
(for 'Link' changes). The things that gnulib-tool can compute automatically
are those that the user won't care when they change - like the list of
files, list of Autoconf macros, etc.

> @@ -58,14 +60,14 @@ extern "C" {
>  struct timevar_time_def
>  {
>    /* User time in this process.  */
> -  float user;
> +  xtime_t user;
>  
>    /* System time (if applicable for this host platform) in this
>       process.  */
> -  float sys;
> +  xtime_t sys;
>  
>    /* Wall clock time.  */
> -  float wall;
> +  xtime_t wall;
>  };

For 'user' and 'sys', 'double' would have been OK as well.

> +  sys_s  += rusage.ru_stime.tv_sec + usr_ns / giga;
Typo: Should be sys_ns / giga

> +      const float tiny = 5e-3;

Shouldn't that be 0.5e-3 for usr and sys, and 0.5e-6 for wall,
to match the number of decimal places printed below?

Bruno




reply via email to

[Prev in Thread] Current Thread [Next in Thread]