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: 28 Oct 2004 18:30:18 +0200 Organization: nocrew Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Message-ID: <85fz3y955x.fsf@junk.nocrew.org> References: <85k7036eqr.fsf@junk.nocrew.org> <85vfjgbphf.fsf_-_@junk.nocrew.org> NNTP-Posting-Host: deer.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: sea.gmane.org 1098981087 851 80.91.229.6 (28 Oct 2004 16:31:27 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Thu, 28 Oct 2004 16:31:27 +0000 (UTC) Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Thu Oct 28 18:31:12 2004 Return-path: Original-Received: from lists.gnu.org ([199.232.76.165]) by deer.gmane.org with esmtp (Exim 3.35 #1 (Debian)) id 1CNDB9-00015n-00 for ; Thu, 28 Oct 2004 18:31:12 +0200 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.33) id 1CNDIx-0007pC-IX for ged-emacs-devel@m.gmane.org; Thu, 28 Oct 2004 12:39:15 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.33) id 1CNDIm-0007mq-1U for emacs-devel@gnu.org; Thu, 28 Oct 2004 12:39:04 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.33) id 1CNDIi-0007lP-Sg for emacs-devel@gnu.org; Thu, 28 Oct 2004 12:39:01 -0400 Original-Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.33) id 1CNDIi-0007ke-Nb for emacs-devel@gnu.org; Thu, 28 Oct 2004 12:39:00 -0400 Original-Received: from [80.91.229.2] (helo=main.gmane.org) by monty-python.gnu.org with esmtp (Exim 4.34) id 1CNDAQ-00036y-Pc for emacs-devel@gnu.org; Thu, 28 Oct 2004 12:30:27 -0400 Original-Received: from list by main.gmane.org with local (Exim 3.35 #1 (Debian)) id 1CNDAP-0001qC-00 for ; Thu, 28 Oct 2004 18:30:25 +0200 Original-Received: from junk.nocrew.org ([213.242.147.30]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Thu, 28 Oct 2004 18:30:25 +0200 Original-Received: from lars by junk.nocrew.org with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Thu, 28 Oct 2004 18:30:25 +0200 X-Injected-Via-Gmane: http://gmane.org/ Original-To: emacs-devel@gnu.org Original-Lines: 256 Original-X-Complaints-To: usenet@sea.gmane.org X-Gmane-NNTP-Posting-Host: junk.nocrew.org User-Agent: Gnus/5.0808 (Gnus v5.8.8) Emacs/20.7 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: main.gmane.org gmane.emacs.devel:29117 X-Report-Spam: http://spam.gmane.org/gmane.emacs.devel:29117 Richard Stallman wrote: > [Lars Brinkhoff wrote:] > [I wish there were a] function that returns the amount of > processor time used [by Emacs], for implementing [the Common > Lisp function] get-internal-run-time. > > ANSI CL says: > The intent is that the difference between the values of > two calls to this function be the amount of time between > the two calls during which computational effort was > expended on behalf of the executing program. > I haven't found a suitable function for this in Emacs. > > Would you like to contribute such a function? The above was written in May. I believe all prerequisite paperwork has finally been done now. The patch has been updated to the current version in CVS. Also, at the end there's a small space optimization for the sxhash function. etc/NEWS (Lisp Changes): ** The new primitive `get-internal-run-time' returns the processor run time used by Emacs since start-up. ./ChangeLog: 2004-10-28 Lars Brinkhoff * configure.in: Add check for getrusage. src/ChangeLog: 2004-10-28 Lars Brinkhoff * config.in: Add HAVE_GETRUSAGE. * editfns.c (Fget_internal_run_time): New function. (syms_of_data): Defsubr it. * fns.c (sxhash): As far as possible, merge calculation of hash code for symbols and strings. lispref/ChangeLog: 2004-10-28 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.375 diff -c -r1.375 configure.in *** configure.in 20 Oct 2004 16:16:07 -0000 1.375 --- configure.in 28 Oct 2004 16:09:55 -0000 *************** *** 2353,2359 **** 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 \ --- 2353,2359 ---- 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: lispref/os.texi =================================================================== RCS file: /cvsroot/emacs/emacs/lispref/os.texi,v retrieving revision 1.65 diff -c -r1.65 os.texi *** lispref/os.texi 8 Aug 2004 00:00:07 -0000 1.65 --- lispref/os.texi 28 Oct 2004 16:10:04 -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. *************** *** 1285,1290 **** --- 1286,1313 ---- 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 @section Time Calculations Index: src/config.in =================================================================== RCS file: /cvsroot/emacs/emacs/src/config.in,v retrieving revision 1.200 diff -c -r1.200 config.in *** src/config.in 20 Oct 2004 16:23:30 -0000 1.200 --- src/config.in 28 Oct 2004 16:10:04 -0000 *************** *** 196,201 **** --- 196,204 ---- /* Define to 1 if you have the `getpt' function. */ #undef HAVE_GETPT + /* Define to 1 if you have the `getrusage' function. */ + #undef HAVE_GETRUSAGE + /* Define to 1 if you have the `getsockname' function. */ #undef HAVE_GETSOCKNAME Index: src/editfns.c =================================================================== RCS file: /cvsroot/emacs/emacs/src/editfns.c,v retrieving revision 1.382 diff -c -r1.382 editfns.c *** src/editfns.c 27 Oct 2004 11:02:06 -0000 1.382 --- src/editfns.c 28 Oct 2004 16:10:06 -0000 *************** *** 39,44 **** --- 39,48 ---- #include #endif + #if defined HAVE_SYS_RESOURCE_H + #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 *************** *** 4315,4320 **** --- 4360,4366 ---- 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: src/fns.c =================================================================== RCS file: /cvsroot/emacs/emacs/src/fns.c,v retrieving revision 1.374 diff -c -r1.374 fns.c *** src/fns.c 26 Oct 2004 22:38:50 -0000 1.374 --- src/fns.c 28 Oct 2004 16:10:07 -0000 *************** *** 5007,5021 **** hash = XUINT (obj); break; - case Lisp_Symbol: - hash = sxhash_string (SDATA (SYMBOL_NAME (obj)), - SCHARS (SYMBOL_NAME (obj))); - break; - case Lisp_Misc: hash = XUINT (obj); break; case Lisp_String: hash = sxhash_string (SDATA (obj), SCHARS (obj)); break; --- 5007,5020 ---- hash = XUINT (obj); break; case Lisp_Misc: hash = XUINT (obj); break; + case Lisp_Symbol: + obj = SYMBOL_NAME (obj); + /* Fall through. */ + case Lisp_String: hash = sxhash_string (SDATA (obj), SCHARS (obj)); break;