From: Lars Brinkhoff <lars@nocrew.org>
Subject: Re: get-internal-run-time
Date: 28 Oct 2004 18:30:18 +0200 [thread overview]
Message-ID: <85fz3y955x.fsf@junk.nocrew.org> (raw)
In-Reply-To: 85vfjgbphf.fsf_-_@junk.nocrew.org
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 <lars@nocrew.org>
* configure.in: Add check for getrusage.
src/ChangeLog:
2004-10-28 Lars Brinkhoff <lars@nocrew.org>
* 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 <lars@nocrew.org>
* 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 <stdio.h>
#endif
+ #if defined HAVE_SYS_RESOURCE_H
+ #include <sys/resource.h>
+ #endif
+
#include <ctype.h>
#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
+ }
\f
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;
prev parent reply other threads:[~2004-10-28 16:30 UTC|newest]
Thread overview: 86+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <E1BH4Nx-000730-Dq@fencepost.gnu.org>
[not found] ` <85k7036eqr.fsf@junk.nocrew.org>
[not found] ` <E1BI6nw-0005F4-Hl@fencepost.gnu.org>
[not found] ` <85smepfzqo.fsf@junk.nocrew.org>
[not found] ` <E1BIm46-0001Ha-5A@fencepost.gnu.org>
2004-04-28 10:43 ` User-reserved element in byte code vectors (was: Emacs Common Lisp) Lars Brinkhoff
2004-04-28 13:48 ` Stefan Monnier
2004-04-28 15:08 ` User-reserved element in byte code vectors Lars Brinkhoff
2004-04-28 15:38 ` Stefan Monnier
2004-04-28 16:51 ` Lars Brinkhoff
2004-04-28 17:12 ` Stefan Monnier
2004-05-02 7:59 ` Lars Brinkhoff
2004-05-02 9:43 ` Miles Bader
2004-05-02 16:02 ` Lars Brinkhoff
2004-05-03 14:03 ` Richard Stallman
2004-05-03 19:57 ` Miles Bader
2004-05-05 5:23 ` Lars Brinkhoff
2004-05-05 20:21 ` Richard Stallman
2004-05-06 3:55 ` Miles Bader
2004-05-06 4:56 ` Miles Bader
2004-05-06 11:48 ` Richard Stallman
2004-05-14 17:53 ` Miles Bader
2004-05-14 18:27 ` Stefan Monnier
2004-05-14 19:50 ` Lars Brinkhoff
2004-05-14 22:03 ` Miles Bader
2004-05-14 22:14 ` Stefan Monnier
2004-05-15 18:34 ` Richard Stallman
2004-05-15 23:10 ` Miles Bader
2004-05-17 11:04 ` Richard Stallman
2004-05-17 11:28 ` Lars Brinkhoff
2004-05-17 16:30 ` Stefan Monnier
2004-05-17 22:06 ` Miles Bader
2004-05-17 22:33 ` David Kastrup
2004-05-18 1:29 ` Miles Bader
2004-05-18 13:17 ` Stefan Monnier
2004-05-18 23:45 ` Miles Bader
2004-05-19 6:28 ` David Kastrup
2004-05-19 6:37 ` Miles Bader
2004-05-19 19:00 ` Richard Stallman
2004-05-19 22:32 ` Function vectors: +funvec-20030520-0-c.patch Miles Bader
2004-05-19 7:34 ` User-reserved element in byte code vectors Kim F. Storm
2004-05-19 13:45 ` Richard Stallman
2004-05-19 14:28 ` Miles Bader
2004-05-19 15:19 ` Stefan Monnier
2004-05-20 0:31 ` Miles Bader
2004-05-20 13:17 ` Richard Stallman
2004-05-21 1:28 ` Miles Bader
2004-05-22 7:31 ` Richard Stallman
2004-05-22 9:37 ` Miles Bader
2004-05-18 14:53 ` Richard Stallman
2004-05-18 17:34 ` Miles Bader
2004-05-18 14:53 ` Richard Stallman
2004-05-16 23:53 ` Stefan Monnier
[not found] ` <E1BP3ym-0007oy-F7@fencepost.gnu.org>
[not found] ` <20040515231754.GB20052@fencepost>
2004-05-16 4:02 ` Function vectors: +funvec-20030516-0-c.patch Miles Bader
2004-05-16 12:28 ` Function vectors: +funvec-20030516-1-c.patch Miles Bader
2004-05-16 23:58 ` Function vectors: +funvec-20030516-0-c.patch Stefan Monnier
2004-05-17 0:03 ` Miles Bader
2004-05-17 0:14 ` Stefan Monnier
2004-05-17 0:30 ` Miles Bader
2004-05-17 16:09 ` Stefan Monnier
2004-05-17 22:21 ` Miles Bader
2004-05-18 13:30 ` Stefan Monnier
2004-05-17 11:04 ` Richard Stallman
2004-05-17 11:04 ` Richard Stallman
2004-05-17 22:54 ` Miles Bader
2004-05-18 14:54 ` Richard Stallman
2004-05-18 6:04 ` Function vectors: +funvec-20030518-0-c.patch Miles Bader
2004-05-06 6:17 ` User-reserved element in byte code vectors Lars Brinkhoff
2004-05-06 14:24 ` Stefan Monnier
2004-05-06 20:39 ` Miles Bader
2004-05-02 16:37 ` Stefan Monnier
2004-05-02 18:59 ` Lars Brinkhoff
2004-05-02 19:21 ` Stefan Monnier
2004-05-02 19:27 ` Lars Brinkhoff
2004-05-02 19:54 ` Stefan Monnier
2004-05-02 20:28 ` Lars Brinkhoff
2004-05-02 21:07 ` Stefan Monnier
2004-05-03 6:08 ` Lars Brinkhoff
2004-05-02 19:52 ` Richard Stallman
2004-04-28 15:38 ` User-reserved element in byte code vectors (was: Emacs Common Lisp) Miles Bader
2004-05-01 5:30 ` Lars Brinkhoff
2004-05-01 23:58 ` Miles Bader
2004-05-01 7:01 ` get-internal-run-time Lars Brinkhoff
2004-05-01 18:53 ` get-internal-run-time Lars Brinkhoff
2004-05-02 14:44 ` get-internal-run-time Eli Zaretskii
2004-05-02 15:45 ` get-internal-run-time Lars Brinkhoff
2004-05-02 18:41 ` get-internal-run-time Lars Brinkhoff
2004-05-03 0:10 ` get-internal-run-time Kevin Ryde
2004-05-03 5:38 ` get-internal-run-time Lars Brinkhoff
2004-05-03 14:03 ` get-internal-run-time Richard Stallman
2004-10-28 16:30 ` Lars Brinkhoff [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=85fz3y955x.fsf@junk.nocrew.org \
--to=lars@nocrew.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).