diff options
author | Paul Eggert <eggert@cs.ucla.edu> | 2012-06-22 14:17:42 -0700 |
---|---|---|
committer | Paul Eggert <eggert@cs.ucla.edu> | 2012-06-22 14:17:42 -0700 |
commit | d35af63cd671563fd188c3b0a1ef30067027c7aa (patch) | |
tree | c9e01847ccf788e23794684da9331c3e0defd0d3 /lib-src/profile.c | |
parent | f143bfe38b43ad0a9d817f05c25e418982dca06f (diff) |
Support higher-resolution time stamps.
Fixes: debbugs:9000
Diffstat (limited to 'lib-src/profile.c')
-rw-r--r-- | lib-src/profile.c | 32 |
1 files changed, 12 insertions, 20 deletions
diff --git a/lib-src/profile.c b/lib-src/profile.c index 8ed4f31897..3e642237c6 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/>. */ ** 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 @@ reset_watch (void) } /* 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) |