diff options
| author | Bill Wohler | 2012-11-24 19:43:02 -0800 |
|---|---|---|
| committer | Bill Wohler | 2012-11-24 19:43:02 -0800 |
| commit | 5244bc019bf7376caff3bb198ff674e0ad9fb0e6 (patch) | |
| tree | 02ee1615e904771f692ec2957c79a08ae029a13d /lib-src/profile.c | |
| parent | 9f7e719509474e92f85955e22e57ffeebd4e96f3 (diff) | |
| parent | c07a6ded1df2f4156badc9add2953579622c3722 (diff) | |
| download | emacs-5244bc019bf7376caff3bb198ff674e0ad9fb0e6.tar.gz emacs-5244bc019bf7376caff3bb198ff674e0ad9fb0e6.zip | |
Merge from trunk.
Diffstat (limited to 'lib-src/profile.c')
| -rw-r--r-- | lib-src/profile.c | 43 |
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 | ||
| 4 | Author: Boaz Ben-Zvi <boaz@lcs.mit.edu> | 4 | Author: 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 | ||
| 35 | static EMACS_TIME TV1, TV2; | 41 | static EMACS_TIME TV1; |
| 36 | static int watch_not_started = 1; /* flag */ | 42 | static int watch_not_started = 1; /* flag */ |
| 37 | static char time_string[30]; | 43 | static 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 | ||
| 41 | static void | 48 | static void |
| 42 | reset_watch (void) | 49 | reset_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 | ||
| 52 | static char * | 59 | static char * |
| 53 | get_time (void) | 60 | get_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 */ | ||
| 66 | gettimeofday (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 | ||
| 80 | int | 71 | int |
| 81 | main (void) | 72 | main (void) |