From: Eli Zaretskii Date: Sat, 6 Nov 2004 17:00:37 +0000 (+0000) Subject: (Fget_internal_run_time): New function. X-Git-Tag: ttn-vms-21-2-B4~4150 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=4211ee7d6c8eef0680f89781012f0551e3a88eb5;p=emacs.git (Fget_internal_run_time): New function. (syms_of_data): Defsubr it. --- diff --git a/src/editfns.c b/src/editfns.c index e83e53e9d24..2e8134d4495 100644 --- a/src/editfns.c +++ b/src/editfns.c @@ -39,6 +39,10 @@ Boston, MA 02111-1307, USA. */ #include #endif +#if defined HAVE_SYS_RESOURCE_H +#include +#endif + #include #include "lisp.h" @@ -1375,6 +1379,47 @@ resolution finer than a second. */) return Flist (3, result); } + +DEFUN ("get-internal-run-time", Fget_internal_run_time, Sget_internal_run_time, + 0, 0, 0, + doc: /* Return the current run time used by Emacs. +The time is returned as a list of three integers. The first has the +most significant 16 bits of the seconds, while the second has the +least significant 16 bits. The third integer gives the microsecond +count. + +On systems that can't determine the run time, get-internal-run-time +does the same thing as current-time. The microsecond count is zero on +systems that do not provide resolution finer than a second. */) + () +{ +#ifdef HAVE_GETRUSAGE + struct rusage usage; + Lisp_Object result[3]; + int secs, usecs; + + if (getrusage (RUSAGE_SELF, &usage) < 0) + /* This shouldn't happen. What action is appropriate? */ + Fsignal (Qerror, Qnil); + + /* Sum up user time and system time. */ + secs = usage.ru_utime.tv_sec + usage.ru_stime.tv_sec; + usecs = usage.ru_utime.tv_usec + usage.ru_stime.tv_usec; + if (usecs >= 1000000) + { + usecs -= 1000000; + secs++; + } + + XSETINT (result[0], (secs >> 16) & 0xffff); + XSETINT (result[1], (secs >> 0) & 0xffff); + XSETINT (result[2], usecs); + + return Flist (3, result); +#else + return Fcurrent_time (); +#endif +} int @@ -4315,6 +4360,7 @@ functions if all the text being accessed has this property. */); defsubr (&Suser_full_name); defsubr (&Semacs_pid); defsubr (&Scurrent_time); + defsubr (&Sget_internal_run_time); defsubr (&Sformat_time_string); defsubr (&Sfloat_time); defsubr (&Sdecode_time);