[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: |
Akim Demaille |
Subject: |
Re: timevar: 3/3: use clock_gettime to get wall clock time |
Date: |
Sat, 13 Oct 2018 07:42:17 +0200 |
> Le 12 oct. 2018 à 17:59, Bruno Haible <address@hidden> a écrit :
>
> Hi Akim,
>
> There are three issues with this patch:
>
> 1) Portability. As listed in
> https://www.gnu.org/software/gnulib/manual/html_node/clock_005fgettime.html
> Gnulib provides no replacement for clock_gettime. So, you'll probably need
> gettimeofday or module ‘gettime' as fallback.
Ugh. Sorry about this.
> Or possibly solve both problems at once by using the Gnulib module
> 'gethrxtime', and 'xtime_t' instead of 'float' for the 'wall' field.
> Or 'gettime'. I don’t know how 'gettime' compares against 'gethrxtime'.
gethrxtime is exactly what I need, thanks! It does use gettime as
a fallback, after having tried better (accuracy and monotony) options.
Here is my updated proposal.
commit aa5694c0854d4f778a5e50676d44341d0e696e8f
Author: Akim Demaille <address@hidden>
Date: Fri Oct 12 06:46:09 2018 +0200
timevar: use gethrxtime to get wall clock time
clock_gettime is not portable. gethrxtime takes the best available
option to get the wall clock time, including clock_gettime (monotonic
clock), and gettime (non monotonic).
Suggested by Bruno Haible.
* modules/timevar (Depends-on): We need gethrxtime.
We no longer use times().
* lib/timevar.c (set_to_current_time): Use gethrxtime.
diff --git a/ChangeLog b/ChangeLog
index ecd69df04..72fda2c1f 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,14 @@
+2018-10-13 Akim Demaille <address@hidden>
+
+ timevar: use gethrxtime to get wall clock time
+ clock_gettime is not portable. gethrxtime takes the best available
+ option to get the wall clock time, including clock_gettime (monotonic
+ clock), and gettime (non monotonic).
+ Suggested by Bruno Haible.
+ * modules/timevar (Depends-on): We need gethrxtime.
+ We no longer use times().
+ * lib/timevar.c (set_to_current_time): Use gethrxtime.
+
2018-10-13 Akim Demaille <address@hidden>
bootstrap: fix wget command for po files.
diff --git a/lib/timevar.c b/lib/timevar.c
index 8b574e277..2f7cf97c8 100644
--- a/lib/timevar.c
+++ b/lib/timevar.c
@@ -30,6 +30,7 @@
#include <sys/time.h>
#include <sys/times.h>
+#include "gethrxtime.h"
#include "gettext.h"
#define _(msgid) gettext (msgid)
#include "xalloc.h"
@@ -108,6 +109,9 @@ set_to_current_time (struct timevar_time_def *now)
getrusage (RUSAGE_CHILDREN, &rusage);
now->user += rusage.ru_utime.tv_sec + rusage.ru_utime.tv_usec * 1e-6;
now->sys += rusage.ru_stime.tv_sec + rusage.ru_stime.tv_usec * 1e-6;
+
+ xtime_t t = gethrxtime();
+ now->wall = t * 1e-9;
}
/* Return the current time. */
diff --git a/modules/timevar b/modules/timevar
index 354d1d211..3e1eb48f7 100644
--- a/modules/timevar
+++ b/modules/timevar
@@ -6,12 +6,12 @@ lib/timevar.h
lib/timevar.c
Depends-on:
+gethrxtime
getrusage
gettext-h
stdlib
sys_time
sys_times
-times
xalloc
Makefile.am:
> 3) Link dependency: List the link dependencies, like it's done e.g. in
> the 'clock-time', 'gettime', and 'gethrxtime' modules. Also use these
> dependencies when linking the test program (in module ‘timevar-tests').
AFAICT, there are no direct link dependencies in timevar, only indirect
ones via the modules it depends upon. What do you mean?
- Re: timevar: further work, (continued)
- Re: timevar: further work, Akim Demaille, 2018/10/11
- Re: timevar: further work, Akim Demaille, 2018/10/11
- Re: timevar: 1/3: expect that getrusage is available, Akim Demaille, 2018/10/12
- Re: timevar: 1/3: expect that getrusage is available, Bruno Haible, 2018/10/12
- Re: timevar: 1/3: expect that getrusage is available, Akim Demaille, 2018/10/13
- Re: timevar: 1/3: expect that getrusage is available, Bruno Haible, 2018/10/13
- Re: timevar: 2/3: improve the output format, Akim Demaille, 2018/10/12
- Re: timevar: 2/3: improve the output format, Bruno Haible, 2018/10/12
- Re: timevar: 3/3: use clock_gettime to get wall clock time, Akim Demaille, 2018/10/12
- Re: timevar: 3/3: use clock_gettime to get wall clock time, Bruno Haible, 2018/10/12
- Re: timevar: 3/3: use clock_gettime to get wall clock time,
Akim Demaille <=
- Re: timevar: 3/3: use clock_gettime to get wall clock time, Bruno Haible, 2018/10/13
- Re: timevar: 3/3: use clock_gettime to get wall clock time, Akim Demaille, 2018/10/13
- Re: timevar: 3/3: use clock_gettime to get wall clock time, Bruno Haible, 2018/10/13
- Re: timevar: 3/3: use clock_gettime to get wall clock time, Akim Demaille, 2018/10/13
- Re: timevar: 3/3: use clock_gettime to get wall clock time, Bruno Haible, 2018/10/13
- Re: timevar: 3/3: use clock_gettime to get wall clock time, Akim Demaille, 2018/10/14
- Re: timevar: 3/3: use clock_gettime to get wall clock time, Bruno Haible, 2018/10/14
- Re: timevar: 3/3: use clock_gettime to get wall clock time, Akim Demaille, 2018/10/14
- Re: timevar: 3/3: use clock_gettime to get wall clock time, Bruno Haible, 2018/10/14