From mboxrd@z Thu Jan 1 00:00:00 1970 Path: main.gmane.org!not-for-mail From: Lars Brinkhoff Newsgroups: gmane.emacs.devel Subject: Re: get-internal-run-time Date: 02 May 2004 20:41:14 +0200 Organization: nocrew Sender: emacs-devel-bounces+emacs-devel=quimby.gnus.org@gnu.org Message-ID: <85u0yy8yet.fsf@junk.nocrew.org> References: <85k7036eqr.fsf@junk.nocrew.org> <85vfjgbphf.fsf_-_@junk.nocrew.org> <85isfgasj6.fsf@junk.nocrew.org> <5567-Sun02May2004164421+0300-eliz@gnu.org> NNTP-Posting-Host: deer.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: sea.gmane.org 1083523478 28318 80.91.224.253 (2 May 2004 18:44:38 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Sun, 2 May 2004 18:44:38 +0000 (UTC) Cc: rms@gnu.org, emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+emacs-devel=quimby.gnus.org@gnu.org Sun May 02 20:44:31 2004 Return-path: Original-Received: from quimby.gnus.org ([80.91.224.244]) by deer.gmane.org with esmtp (Exim 3.35 #1 (Debian)) id 1BKLx1-00007F-00 for ; Sun, 02 May 2004 20:44:31 +0200 Original-Received: from monty-python.gnu.org ([199.232.76.173]) by quimby.gnus.org with esmtp (Exim 3.35 #1 (Debian)) id 1BKLx1-0006L4-00 for ; Sun, 02 May 2004 20:44:31 +0200 Original-Received: from localhost ([127.0.0.1] helo=monty-python.gnu.org) by monty-python.gnu.org with esmtp (Exim 4.30) id 1BKLvY-0001qk-R2 for emacs-devel@quimby.gnus.org; Sun, 02 May 2004 14:43:00 -0400 Original-Received: from list by monty-python.gnu.org with tmda-scanned (Exim 4.30) id 1BKLvP-0001nr-FZ for emacs-devel@gnu.org; Sun, 02 May 2004 14:42:51 -0400 Original-Received: from mail by monty-python.gnu.org with spam-scanned (Exim 4.30) id 1BKLuw-0001e2-8E for emacs-devel@gnu.org; Sun, 02 May 2004 14:42:48 -0400 Original-Received: from [213.242.147.30] (helo=junk.nocrew.org) by monty-python.gnu.org with esmtp (Exim 4.30) id 1BKLts-0001Ik-Fb; Sun, 02 May 2004 14:41:16 -0400 Original-Received: from lars by junk.nocrew.org with local (Exim 3.35 #1 (Debian)) id 1BKLtq-0006Kr-00; Sun, 02 May 2004 20:41:14 +0200 Original-To: Eli Zaretskii In-Reply-To: <5567-Sun02May2004164421+0300-eliz@gnu.org> Original-Lines: 181 User-Agent: Gnus/5.0808 (Gnus v5.8.8) Emacs/20.7 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.4 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+emacs-devel=quimby.gnus.org@gnu.org Xref: main.gmane.org gmane.emacs.devel:22546 X-Report-Spam: http://spam.gmane.org/gmane.emacs.devel:22546 "Eli Zaretskii" writes: > Is it enough to test for sys/resource.h to deduce that getrusage is > available? Or perhaps we need to test for the function as well? Here's an updated patch. I believe I've signed copyright assignment papers for contributions to Emacs, but that was many years ago, so I don't know if they're still on file. etc/NEWS (Lisp Changes): ** The new primitive `get-internal-run-time' returns the processor run time used by Emacs since start-up. ./ChangeLog: 2004-05-02 Lars Brinkhoff * configure.in: Add check for getrusage. src/ChangeLog: 2004-05-02 Lars Brinkhoff * editfns.c (Fget_internal_run_time): New function. (syms_of_data): Defsubr it. lispref/ChangeLog: 2004-05-02 Lars Brinkhoff * os.texi (Processor Run Time): New section documenting get-internal-run-time. Index: configure.in =================================================================== RCS file: /cvsroot/emacs/emacs/configure.in,v retrieving revision 1.366 diff -c -r1.366 configure.in *** configure.in 29 Apr 2004 18:59:27 -0000 1.366 --- configure.in 2 May 2004 16:41:37 -0000 *************** *** 2344,2350 **** AC_CHECK_HEADERS(maillock.h) AC_CHECK_FUNCS(gethostname getdomainname dup2 \ ! rename closedir mkdir rmdir sysinfo \ random lrand48 bcopy bcmp logb frexp fmod rint cbrt ftime res_init setsid \ strerror fpathconf select mktime euidaccess getpagesize tzset setlocale \ utimes setrlimit setpgid getcwd getwd shutdown getaddrinfo \ --- 2344,2350 ---- AC_CHECK_HEADERS(maillock.h) AC_CHECK_FUNCS(gethostname getdomainname dup2 \ ! rename closedir mkdir rmdir sysinfo getrusage \ random lrand48 bcopy bcmp logb frexp fmod rint cbrt ftime res_init setsid \ strerror fpathconf select mktime euidaccess getpagesize tzset setlocale \ utimes setrlimit setpgid getcwd getwd shutdown getaddrinfo \ Index: src/editfns.c =================================================================== RCS file: /cvsroot/emacs/emacs/src/editfns.c,v retrieving revision 1.372 diff -c -r1.372 editfns.c *** src/editfns.c 27 Apr 2004 13:28:38 -0000 1.372 --- src/editfns.c 2 May 2004 16:41:38 -0000 *************** *** 39,44 **** --- 39,48 ---- #include #endif + #if defined HAVE_SYS_RESOURCE_H && defined HAVE_GETRUSAGE + #include + #endif + #include #include "lisp.h" *************** *** 1375,1380 **** --- 1379,1425 ---- 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 *************** *** 4280,4285 **** --- 4325,4331 ---- 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); Index: lispref/os.texi =================================================================== RCS file: /cvsroot/emacs/emacs/lispref/os.texi,v retrieving revision 1.62 diff -c -r1.62 os.texi *** lispref/os.texi 17 Feb 2004 01:06:10 -0000 1.62 --- lispref/os.texi 2 May 2004 16:41:39 -0000 *************** *** 23,28 **** --- 23,29 ---- * Time of Day:: Getting the current time. * Time Conversion:: Converting a time from numeric form to a string, or to calendrical data (or vice versa). + * Processor Run Time:: Getting the run time used by Emacs. * Time Calculations:: Adding, subtracting, comparing times, etc. * Timers:: Setting a timer to call a function at a certain time. * Terminal Input:: Recording terminal input for debugging. *************** *** 1247,1252 **** --- 1248,1275 ---- if you try to encode a time that is out of range, an error results. For instance, years before 1970 do not work on some systems; on others, years as early as 1901 do work. + @end defun + + @node Processor Run Time + @section Processor Run time + + @defun get-internal-run-time + This function returns the processor run time used by Emacs as a list + of three integers: @code{(@var{high} @var{low} @var{microsec})}. The + integers @var{high} and @var{low} combine to give the number of + seconds, which is + @ifnottex + @var{high} * 2**16 + @var{low}. + @end ifnottex + @tex + $high*2^{16}+low$. + @end tex + + The third element, @var{microsec}, gives the microseconds (or 0 for + systems that return time with the resolution of only one second). + + If the system doesn't provide a way to determine the processor run + time, get-internal-run-time returns the same time as current-time. @end defun @node Time Calculations