aboutsummaryrefslogtreecommitdiffstats
path: root/lib-src/profile.c
diff options
context:
space:
mode:
Diffstat (limited to 'lib-src/profile.c')
-rw-r--r--lib-src/profile.c39
1 files changed, 14 insertions, 25 deletions
diff --git a/lib-src/profile.c b/lib-src/profile.c
index 8ed4f318974..d21f2c28e58 100644
--- a/lib-src/profile.c
+++ b/lib-src/profile.c
@@ -20,7 +20,7 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
20 20
21 21
22/** 22/**
23 ** To be run as an emacs process. Input string that starts with: 23 ** To be run as an emacs subprocess. Input string that starts with:
24 ** 'z' -- resets the watch (to zero). 24 ** 'z' -- resets the watch (to zero).
25 ** 'p' -- return time (on stdout) as string with format <sec>.<micro-sec> 25 ** 'p' -- return time (on stdout) as string with format <sec>.<micro-sec>
26 ** 'q' -- exit. 26 ** 'q' -- exit.
@@ -29,53 +29,42 @@ 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;
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
41static void 46static void
42reset_watch (void) 47reset_watch (void)
43{ 48{
44 EMACS_GET_TIME (TV1); 49 TV1 = current_emacs_time ();
45 watch_not_started = 0; 50 watch_not_started = 0;
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 EMACS_TIME TV2 = sub_emacs_time (current_emacs_time (), TV1);
61 uintmax_t s = EMACS_SECS (TV2);
62 int ns = EMACS_NSECS (TV2);
55 if (watch_not_started) 63 if (watch_not_started)
56 exit (EXIT_FAILURE); /* call reset_watch first ! */ 64 exit (EXIT_FAILURE); /* call reset_watch first ! */
57 EMACS_GET_TIME (TV2); 65 sprintf (time_string, "%"PRIuMAX".%0*d", s, LOG10_EMACS_TIME_RESOLUTION, ns);
58 EMACS_SUB_TIME (TV2, TV2, TV1);
59 sprintf (time_string, "%lu.%06lu", (unsigned long)EMACS_SECS (TV2), (unsigned long)EMACS_USECS (TV2));
60 return time_string; 66 return time_string;
61} 67}
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 68
80int 69int
81main (void) 70main (void)