aboutsummaryrefslogtreecommitdiffstats
path: root/lib-src
diff options
context:
space:
mode:
authorPaul Eggert2012-06-22 14:17:42 -0700
committerPaul Eggert2012-06-22 14:17:42 -0700
commitd35af63cd671563fd188c3b0a1ef30067027c7aa (patch)
treec9e01847ccf788e23794684da9331c3e0defd0d3 /lib-src
parentf143bfe38b43ad0a9d817f05c25e418982dca06f (diff)
downloademacs-d35af63cd671563fd188c3b0a1ef30067027c7aa.tar.gz
emacs-d35af63cd671563fd188c3b0a1ef30067027c7aa.zip
Support higher-resolution time stamps.
Fixes: debbugs:9000
Diffstat (limited to 'lib-src')
-rw-r--r--lib-src/ChangeLog10
-rw-r--r--lib-src/Makefile.in5
-rw-r--r--lib-src/profile.c32
3 files changed, 26 insertions, 21 deletions
diff --git a/lib-src/ChangeLog b/lib-src/ChangeLog
index 68a8c37c2fb..11f68cebf14 100644
--- a/lib-src/ChangeLog
+++ b/lib-src/ChangeLog
@@ -1,3 +1,13 @@
12012-06-22 Paul Eggert <eggert@cs.ucla.edu>
2
3 Support higher-resolution time stamps (Bug#9000).
4 * Makefile.in (LIB_CLOCK_GETTIME): New macro.
5 (profile${EXEEXT}): Use it.
6 * profile.c: Include inttyeps.h, intprops.h.
7 (time_string): Size conservatively; do not guess size.
8 (get_time): Now prints nanoseconds.
9 (gettimeofday): Remove replacement function; gnulib now does this.
10
12012-06-08 Andreas Schwab <schwab@linux-m68k.org> 112012-06-08 Andreas Schwab <schwab@linux-m68k.org>
2 12
3 * make-docfile.c (search_lisp_doc_at_eol): Unget last read 13 * make-docfile.c (search_lisp_doc_at_eol): Unget last read
diff --git a/lib-src/Makefile.in b/lib-src/Makefile.in
index 2df22d9f7d8..a325fc18aac 100644
--- a/lib-src/Makefile.in
+++ b/lib-src/Makefile.in
@@ -159,6 +159,8 @@ LIBHESIOD=@LIBHESIOD@
159LIBRESOLV=@LIBRESOLV@ 159LIBRESOLV=@LIBRESOLV@
160## -llockfile if HAVE_LIBLOCKFILE or -lmail if HAVE_LIBMAIL 160## -llockfile if HAVE_LIBLOCKFILE or -lmail if HAVE_LIBMAIL
161LIBS_MAIL=@LIBS_MAIL@ 161LIBS_MAIL=@LIBS_MAIL@
162## empty or -lrt or -lposix4 if HAVE_CLOCK_GETTIME
163LIB_CLOCK_GETTIME = @LIB_CLOCK_GETTIME@
162 164
163## Extra libraries to use when linking movemail. 165## Extra libraries to use when linking movemail.
164LIBS_MOVE = $(LIBS_MAIL) $(KRB4LIB) $(DESLIB) $(KRB5LIB) $(CRYPTOLIB) \ 166LIBS_MOVE = $(LIBS_MAIL) $(KRB4LIB) $(DESLIB) $(KRB5LIB) $(CRYPTOLIB) \
@@ -309,7 +311,8 @@ ctags${EXEEXT}: etags${EXEEXT}
309 regex.o $(LOADLIBES) -o ctags 311 regex.o $(LOADLIBES) -o ctags
310 312
311profile${EXEEXT}: ${srcdir}/profile.c ../src/config.h 313profile${EXEEXT}: ${srcdir}/profile.c ../src/config.h
312 $(CC) ${ALL_CFLAGS} ${srcdir}/profile.c $(LOADLIBES) -o profile 314 $(CC) ${ALL_CFLAGS} ${srcdir}/profile.c \
315 $(LOADLIBES) $(LIB_CLOCK_GETTIME) -o profile
313 316
314make-docfile${EXEEXT}: ${srcdir}/make-docfile.c ../src/config.h 317make-docfile${EXEEXT}: ${srcdir}/make-docfile.c ../src/config.h
315 $(CC) ${ALL_CFLAGS} ${srcdir}/make-docfile.c $(LOADLIBES) \ 318 $(CC) ${ALL_CFLAGS} ${srcdir}/make-docfile.c $(LOADLIBES) \
diff --git a/lib-src/profile.c b/lib-src/profile.c
index 8ed4f318974..3e642237c6b 100644
--- a/lib-src/profile.c
+++ b/lib-src/profile.c
@@ -29,12 +29,17 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
29 ** operations: reset_watch, get_time 29 ** operations: reset_watch, get_time
30 */ 30 */
31#include <config.h> 31#include <config.h>
32
33#include <inttypes.h>
32#include <stdio.h> 34#include <stdio.h>
35
36#include <intprops.h>
33#include <systime.h> 37#include <systime.h>
34 38
35static EMACS_TIME TV1, TV2; 39static EMACS_TIME TV1, TV2;
36static int watch_not_started = 1; /* flag */ 40static int watch_not_started = 1; /* flag */
37static char time_string[30]; 41static char time_string[INT_STRLEN_BOUND (uintmax_t) + sizeof "."
42 + LOG10_EMACS_TIME_RESOLUTION];
38 43
39/* Reset the stopwatch to zero. */ 44/* Reset the stopwatch to zero. */
40 45
@@ -46,36 +51,23 @@ reset_watch (void)
46} 51}
47 52
48/* This call returns the time since the last reset_watch call. The time 53/* This call returns the time since the last reset_watch call. The time
49 is returned as a string with the format <seconds>.<micro-seconds> 54 is returned as a string with the format <seconds>.<nanoseconds>
50 If reset_watch was not called yet, exit. */ 55 If reset_watch was not called yet, exit. */
51 56
52static char * 57static char *
53get_time (void) 58get_time (void)
54{ 59{
60 uintmax_t s;
61 int ns;
55 if (watch_not_started) 62 if (watch_not_started)
56 exit (EXIT_FAILURE); /* call reset_watch first ! */ 63 exit (EXIT_FAILURE); /* call reset_watch first ! */
57 EMACS_GET_TIME (TV2); 64 EMACS_GET_TIME (TV2);
58 EMACS_SUB_TIME (TV2, TV2, TV1); 65 EMACS_SUB_TIME (TV2, TV2, TV1);
59 sprintf (time_string, "%lu.%06lu", (unsigned long)EMACS_SECS (TV2), (unsigned long)EMACS_USECS (TV2)); 66 s = EMACS_SECS (TV2);
67 ns = EMACS_NSECS (TV2);
68 sprintf (time_string, "%"PRIuMAX".%0*d", s, LOG10_EMACS_TIME_RESOLUTION, ns);
60 return time_string; 69 return time_string;
61} 70}
62
63#if ! defined (HAVE_GETTIMEOFDAY) && defined (HAVE_TIMEVAL)
64
65/* ARGSUSED */
66gettimeofday (tp, tzp)
67 struct timeval *tp;
68 struct timezone *tzp;
69{
70 extern long time ();
71
72 tp->tv_sec = time ((long *)0);
73 tp->tv_usec = 0;
74 if (tzp != 0)
75 tzp->tz_minuteswest = -1;
76}
77
78#endif
79 71
80int 72int
81main (void) 73main (void)