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.c43
1 files changed, 17 insertions, 26 deletions
diff --git a/lib-src/profile.c b/lib-src/profile.c
index 086d8cc3e9d..3489e492543 100644
--- a/lib-src/profile.c
+++ b/lib-src/profile.c
@@ -1,5 +1,5 @@
1/* profile.c --- generate periodic events for profiling of Emacs Lisp code. 1/* profile.c --- generate periodic events for profiling of Emacs Lisp code.
2 Copyright (C) 1992, 1994, 1999, 2001-2011 Free Software Foundation, Inc. 2 Copyright (C) 1992, 1994, 1999, 2001-2012 Free Software Foundation, Inc.
3 3
4Author: Boaz Ben-Zvi <boaz@lcs.mit.edu> 4Author: Boaz Ben-Zvi <boaz@lcs.mit.edu>
5 5
@@ -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,44 @@ 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#define SYSTIME_INLINE EXTERN_INLINE
34
35#include <inttypes.h>
32#include <stdio.h> 36#include <stdio.h>
37
38#include <intprops.h>
33#include <systime.h> 39#include <systime.h>
34 40
35static EMACS_TIME TV1, TV2; 41static EMACS_TIME TV1;
36static int watch_not_started = 1; /* flag */ 42static int watch_not_started = 1; /* flag */
37static char time_string[30]; 43static char time_string[INT_STRLEN_BOUND (uintmax_t) + sizeof "."
44 + LOG10_EMACS_TIME_RESOLUTION];
38 45
39/* Reset the stopwatch to zero. */ 46/* Reset the stopwatch to zero. */
40 47
41static void 48static void
42reset_watch (void) 49reset_watch (void)
43{ 50{
44 EMACS_GET_TIME (TV1); 51 TV1 = current_emacs_time ();
45 watch_not_started = 0; 52 watch_not_started = 0;
46} 53}
47 54
48/* This call returns the time since the last reset_watch call. The time 55/* 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> 56 is returned as a string with the format <seconds>.<nanoseconds>
50 If reset_watch was not called yet, exit. */ 57 If reset_watch was not called yet, exit. */
51 58
52static char * 59static char *
53get_time (void) 60get_time (void)
54{ 61{
62 EMACS_TIME TV2 = sub_emacs_time (current_emacs_time (), TV1);
63 uintmax_t s = EMACS_SECS (TV2);
64 int ns = EMACS_NSECS (TV2);
55 if (watch_not_started) 65 if (watch_not_started)
56 exit (EXIT_FAILURE); /* call reset_watch first ! */ 66 exit (EXIT_FAILURE); /* call reset_watch first ! */
57 EMACS_GET_TIME (TV2); 67 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; 68 return time_string;
61} 69}
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 70
80int 71int
81main (void) 72main (void)