[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH 6/7] lib-src support for ns-resolution time stamps
From: |
Paul Eggert |
Subject: |
[PATCH 6/7] lib-src support for ns-resolution time stamps |
Date: |
Fri, 01 Jul 2011 01:16:09 -0700 |
User-agent: |
Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.2.17) Gecko/20110516 Thunderbird/3.1.10 |
This much-smaller patch is more C-level support, in the lib-src directory.
It's needed, so that lib-src can compile with the new src directory.
Add support for nanosecond-resolution time stamps.
* Makefile.in (LIB_CLOCK_GETTIME): New macro.
(profile${EXEEXT}): Use it.
* profile.c: Include inttyeps.h, intprops.h.
(time_string): Size conservatively; do not guess size.
(get_time): Now prints nanoseconds.
(gettimeofday): Remove replacement function; gnulib now does this.
=== modified file 'lib-src/Makefile.in'
--- lib-src/Makefile.in 2011-05-25 07:13:57 +0000
+++ lib-src/Makefile.in 2011-07-01 05:24:03 +0000
@@ -156,6 +156,8 @@
address@hidden@
## -llockfile if HAVE_LIBLOCKFILE or -lmail if HAVE_LIBMAIL
address@hidden@
+## empty or -lrt or -lposix4 if HAVE_CLOCK_GETTIME
+LIB_CLOCK_GETTIME = @LIB_CLOCK_GETTIME@
## Extra libraries to use when linking movemail.
LIBS_MOVE = $(LIBS_MAIL) $(KRB4LIB) $(DESLIB) $(KRB5LIB) $(CRYPTOLIB) \
@@ -328,7 +330,8 @@
regex.o $(LOADLIBES) -o ctags
profile${EXEEXT}: ${srcdir}/profile.c ../src/config.h
- $(CC) ${ALL_CFLAGS} ${srcdir}/profile.c $(LOADLIBES) -o profile
+ $(CC) ${ALL_CFLAGS} ${srcdir}/profile.c \
+ $(LOADLIBES) $(LIB_CLOCK_GETTIME) -o profile
make-docfile${EXEEXT}: ${srcdir}/make-docfile.c ../src/config.h
$(CC) ${ALL_CFLAGS} ${srcdir}/make-docfile.c $(LOADLIBES) \
=== modified file 'lib-src/profile.c'
--- lib-src/profile.c 2011-02-21 18:06:25 +0000
+++ lib-src/profile.c 2011-07-01 05:24:03 +0000
@@ -29,12 +29,17 @@
** operations: reset_watch, get_time
*/
#include <config.h>
+
+#include <inttypes.h>
#include <stdio.h>
+
+#include <intprops.h>
#include <systime.h>
static EMACS_TIME TV1, TV2;
static int watch_not_started = 1; /* flag */
-static char time_string[30];
+static char time_string[INT_STRLEN_BOUND (uintmax_t) + sizeof "."
+ + LOG10_EMACS_TIME_RESOLUTION];
/* Reset the stopwatch to zero. */
@@ -46,36 +51,23 @@
}
/* This call returns the time since the last reset_watch call. The time
- is returned as a string with the format <seconds>.<micro-seconds>
+ is returned as a string with the format <seconds>.<nanoseconds>
If reset_watch was not called yet, exit. */
static char *
get_time (void)
{
+ uintmax_t s;
+ int ns;
if (watch_not_started)
exit (EXIT_FAILURE); /* call reset_watch first ! */
EMACS_GET_TIME (TV2);
EMACS_SUB_TIME (TV2, TV2, TV1);
- sprintf (time_string, "%lu.%06lu", (unsigned long)EMACS_SECS (TV2),
(unsigned long)EMACS_USECS (TV2));
+ s = EMACS_SECS (TV2);
+ ns = EMACS_NSECS (TV2);
+ sprintf (time_string, "%"PRIuMAX".%0*d", s, LOG10_EMACS_TIME_RESOLUTION, ns);
return time_string;
}
-
-#if ! defined (HAVE_GETTIMEOFDAY) && defined (HAVE_TIMEVAL)
-
-/* ARGSUSED */
-gettimeofday (tp, tzp)
- struct timeval *tp;
- struct timezone *tzp;
-{
- extern long time ();
-
- tp->tv_sec = time ((long *)0);
- tp->tv_usec = 0;
- if (tzp != 0)
- tzp->tz_minuteswest = -1;
-}
-
-#endif
int
main (void)
- Re: [PATCH 1/7] gnulib substrate for ns-resolution time stamps, (continued)
- Re: [PATCH 1/7] gnulib substrate for ns-resolution time stamps, Eli Zaretskii, 2011/07/01
- Re: [PATCH 1/7] gnulib substrate for ns-resolution time stamps, Eli Zaretskii, 2011/07/01
- Re: [PATCH 1/7] gnulib substrate for ns-resolution time stamps, Paul Eggert, 2011/07/01
- Re: [PATCH 1/7] gnulib substrate for ns-resolution time stamps, Eli Zaretskii, 2011/07/01
- Re: [PATCH 1/7] gnulib substrate for ns-resolution time stamps, Paul Eggert, 2011/07/01
- Re: [PATCH 1/7] gnulib substrate for ns-resolution time stamps, Eli Zaretskii, 2011/07/01
[PATCH 2/7] etc/NEWS patch for ns-resolution time stamps, Paul Eggert, 2011/07/01
[PATCH 3/7] Doc patches for ns-resolution time stamps, Paul Eggert, 2011/07/01
[PATCH 4/7] configure-time support for ns-resolution time stamps, Paul Eggert, 2011/07/01
[PATCH 5/7] C-level support for ns-resolution time stamps, Paul Eggert, 2011/07/01
[PATCH 6/7] lib-src support for ns-resolution time stamps,
Paul Eggert <=
[PATCH 7/7] Lisp-level support for ns-resolution time stamps, Paul Eggert, 2011/07/01
Re: nanosecond-resolution time stamps, Stefan Monnier, 2011/07/01