annotate src/profile.c @ 1123:37bdd24225ef

[xemacs-hg @ 2002-11-27 07:15:02 by ben] bug fixes, profiling debugging improvements configure.in: Check for GCC version and only use -Wpacked in v3. .cvsignore: Add .idb, .ilk for MS Windows VC++. cl-macs.el: Document better. cmdloop.el: Removed. Remove nonworking breakpoint-on-error now that debug-on-error works as documented. help.el: Extract out with-displaying-help-buffer into a more general mechanism. lib-complete.el: Support thunks in find-library-source-path. startup.el: Don't catch errors when noninteractive, because that makes stack traces from stack-trace-on-error useless. .cvsignore: Windows shit. alloc.c: Better redisplay-related assert. elhash.c: Comment change. eval.c: Don't generate large warning strings (e.g. backtraces) when they will be discarded. Implement debug-on-error as documented -- it will enter the debugger and crash when an uncaught signal happens noninteractively and we are --debug. Better redisplay-related asserts. frame-msw.c, frame.c, lisp.h, redisplay.c, scrollbar-gtk.c, scrollbar-x.c, signal.c, sysdep.c: Fix up documentation related to QUIT (which CANNOT garbage-collect under any circumstances), and to redisplay critical sections. lread.c: Add load-ignore-out-of-date-elc-files, load-always-display-messages, load-show-full-path-in-messages for more robust package compilation and debugging. profile.c: Overhaul profile code. Change format to include call count and be extensible for further info. Remove call-count-profile-table. Add set-profiling-info. See related profile.el changes (which SHOULD ABSOLUTELY be in the core! Get rid of xemacs-devel and xemacs-base packages *yesterday*!).
author ben
date Wed, 27 Nov 2002 07:15:36 +0000
parents 2b6fa2618f76
children f3437b56874d
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1 /* Why the hell is XEmacs so fucking slow?
1123
37bdd24225ef [xemacs-hg @ 2002-11-27 07:15:02 by ben]
ben
parents: 853
diff changeset
2 Copyright (C) 1996, 2002 Ben Wing.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3 Copyright (C) 1998 Free Software Foundation, Inc.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5 This file is part of XEmacs.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
7 XEmacs is free software; you can redistribute it and/or modify it
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
8 under the terms of the GNU General Public License as published by the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
9 Free Software Foundation; either version 2, or (at your option) any
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
10 later version.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
11
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
12 XEmacs is distributed in the hope that it will be useful, but WITHOUT
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
15 for more details.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
16
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
17 You should have received a copy of the GNU General Public License
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
18 along with XEmacs; see the file COPYING. If not, write to
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
19 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
20 Boston, MA 02111-1307, USA. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
21
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
22 #include <config.h>
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
23 #include "lisp.h"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
24
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
25 #include "backtrace.h"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
26 #include "bytecode.h"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
27 #include "elhash.h"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
28 #include "hash.h"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
29
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
30 #include "syssignal.h"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
31 #include "systime.h"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
32
611
38db05db9cb5 [xemacs-hg @ 2001-06-08 12:21:09 by ben]
ben
parents: 458
diff changeset
33 #ifndef HAVE_SETITIMER
38db05db9cb5 [xemacs-hg @ 2001-06-08 12:21:09 by ben]
ben
parents: 458
diff changeset
34 #error Sorry charlie. We need a scalpel and all we have is a lawnmower.
38db05db9cb5 [xemacs-hg @ 2001-06-08 12:21:09 by ben]
ben
parents: 458
diff changeset
35 #endif
38db05db9cb5 [xemacs-hg @ 2001-06-08 12:21:09 by ben]
ben
parents: 458
diff changeset
36
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
37 /* We implement our own profiling scheme so that we can determine
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
38 things like which Lisp functions are occupying the most time. Any
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
39 standard OS-provided profiling works on C functions, which is
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
40 somewhat useless.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
41
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
42 The basic idea is simple. We set a profiling timer using setitimer
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
43 (ITIMER_PROF), which generates a SIGPROF every so often. (This
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
44 runs not in real time but rather when the process is executing or
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
45 the system is running on behalf of the process.) When the signal
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
46 goes off, we see what we're in, and add 1 to the count associated
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
47 with that function.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
48
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
49 It would be nice to use the Lisp allocation mechanism etc. to keep
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
50 track of the profiling information, but we can't because that's not
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
51 safe, and trying to make it safe would be much more work than it's
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
52 worth.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
53
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
54 Jan 1998: In addition to this, I have added code to remember call
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
55 counts of Lisp funcalls. The profile_increase_call_count()
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
56 function is called from Ffuncall(), and serves to add data to
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
57 Vcall_count_profile_table. This mechanism is much simpler and
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
58 independent of the SIGPROF-driven one. It uses the Lisp allocation
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
59 mechanism normally, since it is not called from a handler. It may
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
60 even be useful to provide a way to turn on only one profiling
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
61 mechanism, but I haven't done so yet. --hniksic */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
62
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
63 static struct hash_table *big_profile_table;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
64 Lisp_Object Vcall_count_profile_table;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
65
458
c33ae14dd6d0 Import from CVS: tag r21-2-44
cvs
parents: 442
diff changeset
66 Fixnum default_profiling_interval;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
67
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
68 int profiling_active;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
69
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
70 /* The normal flag in_display is used as a critical-section flag
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
71 and is not set the whole time we're in redisplay. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
72 int profiling_redisplay_flag;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
73
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
74 static Lisp_Object QSin_redisplay;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
75 static Lisp_Object QSin_garbage_collection;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
76 static Lisp_Object QSprocessing_events_at_top_level;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
77 static Lisp_Object QSunknown;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
78
1123
37bdd24225ef [xemacs-hg @ 2002-11-27 07:15:02 by ben]
ben
parents: 853
diff changeset
79 static Lisp_Object Qtiming, Qcall_count;
37bdd24225ef [xemacs-hg @ 2002-11-27 07:15:02 by ben]
ben
parents: 853
diff changeset
80
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
81 /* We use inside_profiling to prevent the handler from writing to
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
82 the table while another routine is operating on it. We also set
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
83 inside_profiling in case the timeout between signal calls is short
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
84 enough to catch us while we're already in there. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
85 static volatile int inside_profiling;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
86
1123
37bdd24225ef [xemacs-hg @ 2002-11-27 07:15:02 by ben]
ben
parents: 853
diff changeset
87 static void
37bdd24225ef [xemacs-hg @ 2002-11-27 07:15:02 by ben]
ben
parents: 853
diff changeset
88 create_call_count_profile_table (void)
37bdd24225ef [xemacs-hg @ 2002-11-27 07:15:02 by ben]
ben
parents: 853
diff changeset
89 {
37bdd24225ef [xemacs-hg @ 2002-11-27 07:15:02 by ben]
ben
parents: 853
diff changeset
90 if (NILP (Vcall_count_profile_table))
37bdd24225ef [xemacs-hg @ 2002-11-27 07:15:02 by ben]
ben
parents: 853
diff changeset
91 Vcall_count_profile_table =
37bdd24225ef [xemacs-hg @ 2002-11-27 07:15:02 by ben]
ben
parents: 853
diff changeset
92 make_lisp_hash_table (100, HASH_TABLE_NON_WEAK, HASH_TABLE_EQ);
37bdd24225ef [xemacs-hg @ 2002-11-27 07:15:02 by ben]
ben
parents: 853
diff changeset
93 }
37bdd24225ef [xemacs-hg @ 2002-11-27 07:15:02 by ben]
ben
parents: 853
diff changeset
94
37bdd24225ef [xemacs-hg @ 2002-11-27 07:15:02 by ben]
ben
parents: 853
diff changeset
95 static void
37bdd24225ef [xemacs-hg @ 2002-11-27 07:15:02 by ben]
ben
parents: 853
diff changeset
96 create_timing_profile_table (void)
37bdd24225ef [xemacs-hg @ 2002-11-27 07:15:02 by ben]
ben
parents: 853
diff changeset
97 {
37bdd24225ef [xemacs-hg @ 2002-11-27 07:15:02 by ben]
ben
parents: 853
diff changeset
98 /* #### The hash code can safely be called from a signal handler
37bdd24225ef [xemacs-hg @ 2002-11-27 07:15:02 by ben]
ben
parents: 853
diff changeset
99 except when it has to grow the hash table. In this case, it calls
37bdd24225ef [xemacs-hg @ 2002-11-27 07:15:02 by ben]
ben
parents: 853
diff changeset
100 realloc(), which is not (in general) re-entrant. We'll just be
37bdd24225ef [xemacs-hg @ 2002-11-27 07:15:02 by ben]
ben
parents: 853
diff changeset
101 sleazy and make the table large enough that it (hopefully) won't
37bdd24225ef [xemacs-hg @ 2002-11-27 07:15:02 by ben]
ben
parents: 853
diff changeset
102 need to be realloc()ed. */
37bdd24225ef [xemacs-hg @ 2002-11-27 07:15:02 by ben]
ben
parents: 853
diff changeset
103 if (!big_profile_table)
37bdd24225ef [xemacs-hg @ 2002-11-27 07:15:02 by ben]
ben
parents: 853
diff changeset
104 big_profile_table = make_hash_table (10000);
37bdd24225ef [xemacs-hg @ 2002-11-27 07:15:02 by ben]
ben
parents: 853
diff changeset
105 }
37bdd24225ef [xemacs-hg @ 2002-11-27 07:15:02 by ben]
ben
parents: 853
diff changeset
106
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
107 /* Increase the value of OBJ in Vcall_count_profile_table hash table.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
108 If the hash table is nil, create it first. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
109 void
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
110 profile_increase_call_count (Lisp_Object obj)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
111 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
112 Lisp_Object count;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
113
1123
37bdd24225ef [xemacs-hg @ 2002-11-27 07:15:02 by ben]
ben
parents: 853
diff changeset
114 create_call_count_profile_table ();
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
115
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
116 count = Fgethash (obj, Vcall_count_profile_table, Qzero);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
117 if (!INTP (count))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
118 count = Qzero;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
119 Fputhash (obj, make_int (1 + XINT (count)), Vcall_count_profile_table);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
120 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
121
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
122 static SIGTYPE
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
123 sigprof_handler (int signo)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
124 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
125 /* Don't do anything if we are shutting down, or are doing a maphash
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
126 or clrhash on the table. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
127 if (!inside_profiling && !preparing_for_armageddon)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
128 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
129 Lisp_Object fun;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
130
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
131 /* If something below causes an error to be signaled, we'll
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
132 not correctly reset this flag. But we'll be in worse shape
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
133 than that anyways, since we'll longjmp back to the last
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
134 condition case. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
135 inside_profiling = 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
136
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
137 if (profiling_redisplay_flag)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
138 fun = QSin_redisplay;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
139 else if (gc_in_progress)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
140 fun = QSin_garbage_collection;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
141 else if (backtrace_list)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
142 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
143 fun = *backtrace_list->function;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
144
434
9d177e8d4150 Import from CVS: tag r21-2-25
cvs
parents: 428
diff changeset
145 if (!SYMBOLP (fun)
9d177e8d4150 Import from CVS: tag r21-2-25
cvs
parents: 428
diff changeset
146 && !COMPILED_FUNCTIONP (fun)
9d177e8d4150 Import from CVS: tag r21-2-25
cvs
parents: 428
diff changeset
147 && !SUBRP (fun)
9d177e8d4150 Import from CVS: tag r21-2-25
cvs
parents: 428
diff changeset
148 && !CONSP (fun))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
149 fun = QSunknown;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
150 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
151 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
152 fun = QSprocessing_events_at_top_level;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
153
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
154 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
155 /* #### see comment about memory allocation in start-profiling.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
156 Allocating memory in a signal handler is BAD BAD BAD.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
157 If you are using the non-mmap rel-alloc code, you might
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
158 lose because of this. Even worse, if the memory allocation
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
159 fails, the `error' generated whacks everything hard. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
160 long count;
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 434
diff changeset
161 const void *vval;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
162
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
163 if (gethash (LISP_TO_VOID (fun), big_profile_table, &vval))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
164 count = (long) vval;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
165 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
166 count = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
167 count++;
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 434
diff changeset
168 vval = (const void *) count;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
169 puthash (LISP_TO_VOID (fun), (void *) vval, big_profile_table);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
170 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
171
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
172 inside_profiling = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
173 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
174 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
175
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
176 DEFUN ("start-profiling", Fstart_profiling, 0, 1, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
177 Start profiling, with profile queries every MICROSECS.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
178 If MICROSECS is nil or omitted, the value of `default-profiling-interval'
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
179 is used.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
180
1123
37bdd24225ef [xemacs-hg @ 2002-11-27 07:15:02 by ben]
ben
parents: 853
diff changeset
181 Information on function timings and call counts is currently recorded.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
182 You can retrieve the recorded profiling info using `get-profiling-info'.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
183
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
184 Starting and stopping profiling does not clear the currently recorded
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
185 info. Thus you can start and stop as many times as you want and everything
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
186 will be properly accumulated.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
187 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
188 (microsecs))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
189 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
190 /* This function can GC */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
191 int msecs;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
192 struct itimerval foo;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
193
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
194 /* #### The hash code can safely be called from a signal handler
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
195 except when it has to grow the hash table. In this case, it calls
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
196 realloc(), which is not (in general) re-entrant. We'll just be
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
197 sleazy and make the table large enough that it (hopefully) won't
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
198 need to be realloc()ed. */
1123
37bdd24225ef [xemacs-hg @ 2002-11-27 07:15:02 by ben]
ben
parents: 853
diff changeset
199 create_timing_profile_table ();
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
200
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
201 if (NILP (microsecs))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
202 msecs = default_profiling_interval;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
203 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
204 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
205 CHECK_NATNUM (microsecs);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
206 msecs = XINT (microsecs);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
207 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
208 if (msecs <= 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
209 msecs = 1000;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
210
613
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 611
diff changeset
211 set_timeout_signal (SIGPROF, sigprof_handler);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
212 foo.it_value.tv_sec = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
213 foo.it_value.tv_usec = msecs;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
214 EMACS_NORMALIZE_TIME (foo.it_value);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
215 foo.it_interval = foo.it_value;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
216 profiling_active = 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
217 inside_profiling = 0;
611
38db05db9cb5 [xemacs-hg @ 2001-06-08 12:21:09 by ben]
ben
parents: 458
diff changeset
218 qxe_setitimer (ITIMER_PROF, &foo, 0);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
219 return Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
220 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
221
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
222 DEFUN ("stop-profiling", Fstop_profiling, 0, 0, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
223 Stop profiling.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
224 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
225 ())
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
226 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
227 /* This function does not GC */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
228 struct itimerval foo;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
229
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
230 foo.it_value.tv_sec = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
231 foo.it_value.tv_usec = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
232 foo.it_interval = foo.it_value;
611
38db05db9cb5 [xemacs-hg @ 2001-06-08 12:21:09 by ben]
ben
parents: 458
diff changeset
233 qxe_setitimer (ITIMER_PROF, &foo, 0);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
234 profiling_active = 0;
613
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 611
diff changeset
235 set_timeout_signal (SIGPROF, fatal_error_signal);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
236 return Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
237 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
238
1123
37bdd24225ef [xemacs-hg @ 2002-11-27 07:15:02 by ben]
ben
parents: 853
diff changeset
239 DEFUN ("clear-profiling-info", Fclear_profiling_info, 0, 0, "", /*
37bdd24225ef [xemacs-hg @ 2002-11-27 07:15:02 by ben]
ben
parents: 853
diff changeset
240 Clear out the recorded profiling info.
37bdd24225ef [xemacs-hg @ 2002-11-27 07:15:02 by ben]
ben
parents: 853
diff changeset
241 This clears both the internal timing information and the call counts in
37bdd24225ef [xemacs-hg @ 2002-11-27 07:15:02 by ben]
ben
parents: 853
diff changeset
242 `call-count-profile-table'.
37bdd24225ef [xemacs-hg @ 2002-11-27 07:15:02 by ben]
ben
parents: 853
diff changeset
243 */
37bdd24225ef [xemacs-hg @ 2002-11-27 07:15:02 by ben]
ben
parents: 853
diff changeset
244 ())
37bdd24225ef [xemacs-hg @ 2002-11-27 07:15:02 by ben]
ben
parents: 853
diff changeset
245 {
37bdd24225ef [xemacs-hg @ 2002-11-27 07:15:02 by ben]
ben
parents: 853
diff changeset
246 /* This function does not GC */
37bdd24225ef [xemacs-hg @ 2002-11-27 07:15:02 by ben]
ben
parents: 853
diff changeset
247 if (big_profile_table)
37bdd24225ef [xemacs-hg @ 2002-11-27 07:15:02 by ben]
ben
parents: 853
diff changeset
248 {
37bdd24225ef [xemacs-hg @ 2002-11-27 07:15:02 by ben]
ben
parents: 853
diff changeset
249 inside_profiling = 1;
37bdd24225ef [xemacs-hg @ 2002-11-27 07:15:02 by ben]
ben
parents: 853
diff changeset
250 clrhash (big_profile_table);
37bdd24225ef [xemacs-hg @ 2002-11-27 07:15:02 by ben]
ben
parents: 853
diff changeset
251 inside_profiling = 0;
37bdd24225ef [xemacs-hg @ 2002-11-27 07:15:02 by ben]
ben
parents: 853
diff changeset
252 }
37bdd24225ef [xemacs-hg @ 2002-11-27 07:15:02 by ben]
ben
parents: 853
diff changeset
253 if (!NILP (Vcall_count_profile_table))
37bdd24225ef [xemacs-hg @ 2002-11-27 07:15:02 by ben]
ben
parents: 853
diff changeset
254 Fclrhash (Vcall_count_profile_table);
37bdd24225ef [xemacs-hg @ 2002-11-27 07:15:02 by ben]
ben
parents: 853
diff changeset
255 return Qnil;
37bdd24225ef [xemacs-hg @ 2002-11-27 07:15:02 by ben]
ben
parents: 853
diff changeset
256 }
37bdd24225ef [xemacs-hg @ 2002-11-27 07:15:02 by ben]
ben
parents: 853
diff changeset
257
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
258 struct get_profiling_info_closure
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
259 {
1123
37bdd24225ef [xemacs-hg @ 2002-11-27 07:15:02 by ben]
ben
parents: 853
diff changeset
260 Lisp_Object timing;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
261 };
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
262
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
263 static int
1123
37bdd24225ef [xemacs-hg @ 2002-11-27 07:15:02 by ben]
ben
parents: 853
diff changeset
264 get_profiling_info_timing_maphash (const void *void_key,
37bdd24225ef [xemacs-hg @ 2002-11-27 07:15:02 by ben]
ben
parents: 853
diff changeset
265 void *void_val,
37bdd24225ef [xemacs-hg @ 2002-11-27 07:15:02 by ben]
ben
parents: 853
diff changeset
266 void *void_closure)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
267 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
268 /* This function does not GC */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
269 Lisp_Object key;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
270 struct get_profiling_info_closure *closure
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
271 = (struct get_profiling_info_closure *) void_closure;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
272 EMACS_INT val;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
273
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
274 key = VOID_TO_LISP (void_key);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
275 val = (EMACS_INT) void_val;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
276
1123
37bdd24225ef [xemacs-hg @ 2002-11-27 07:15:02 by ben]
ben
parents: 853
diff changeset
277 Fputhash (key, make_int (val), closure->timing);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
278 return 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
279 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
280
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
281 DEFUN ("get-profiling-info", Fget_profiling_info, 0, 0, 0, /*
1123
37bdd24225ef [xemacs-hg @ 2002-11-27 07:15:02 by ben]
ben
parents: 853
diff changeset
282 Return the currently recorded profiling info.
37bdd24225ef [xemacs-hg @ 2002-11-27 07:15:02 by ben]
ben
parents: 853
diff changeset
283 The format is a plist of symbols describing type of info recorded and
37bdd24225ef [xemacs-hg @ 2002-11-27 07:15:02 by ben]
ben
parents: 853
diff changeset
284 an associated type-specific entry. Currently, the following info types
37bdd24225ef [xemacs-hg @ 2002-11-27 07:15:02 by ben]
ben
parents: 853
diff changeset
285 are recorded
37bdd24225ef [xemacs-hg @ 2002-11-27 07:15:02 by ben]
ben
parents: 853
diff changeset
286
37bdd24225ef [xemacs-hg @ 2002-11-27 07:15:02 by ben]
ben
parents: 853
diff changeset
287 `timing'
37bdd24225ef [xemacs-hg @ 2002-11-27 07:15:02 by ben]
ben
parents: 853
diff changeset
288 A hash table of funcallable objects or strings describing internal processing
37bdd24225ef [xemacs-hg @ 2002-11-27 07:15:02 by ben]
ben
parents: 853
diff changeset
289 operations \(redisplay, garbage collection, etc.), along with associated
37bdd24225ef [xemacs-hg @ 2002-11-27 07:15:02 by ben]
ben
parents: 853
diff changeset
290 tick counts (the frequency of ticks is controlled by
37bdd24225ef [xemacs-hg @ 2002-11-27 07:15:02 by ben]
ben
parents: 853
diff changeset
291 `default-profiling-interval' or the argument to `start-profiling').
37bdd24225ef [xemacs-hg @ 2002-11-27 07:15:02 by ben]
ben
parents: 853
diff changeset
292
37bdd24225ef [xemacs-hg @ 2002-11-27 07:15:02 by ben]
ben
parents: 853
diff changeset
293 `call-count'
37bdd24225ef [xemacs-hg @ 2002-11-27 07:15:02 by ben]
ben
parents: 853
diff changeset
294 A hash table of funcallable objects and associated call counts.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
295 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
296 ())
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
297 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
298 /* This function does not GC */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
299 struct get_profiling_info_closure closure;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
300
1123
37bdd24225ef [xemacs-hg @ 2002-11-27 07:15:02 by ben]
ben
parents: 853
diff changeset
301 closure.timing =
37bdd24225ef [xemacs-hg @ 2002-11-27 07:15:02 by ben]
ben
parents: 853
diff changeset
302 make_lisp_hash_table (100, HASH_TABLE_NON_WEAK, HASH_TABLE_EQUAL);
37bdd24225ef [xemacs-hg @ 2002-11-27 07:15:02 by ben]
ben
parents: 853
diff changeset
303
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
304 if (big_profile_table)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
305 {
853
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 826
diff changeset
306 int count = internal_bind_int ((int *) &inside_profiling, 1);
1123
37bdd24225ef [xemacs-hg @ 2002-11-27 07:15:02 by ben]
ben
parents: 853
diff changeset
307 maphash (get_profiling_info_timing_maphash, big_profile_table, &closure);
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 613
diff changeset
308 unbind_to (count);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
309 }
1123
37bdd24225ef [xemacs-hg @ 2002-11-27 07:15:02 by ben]
ben
parents: 853
diff changeset
310
37bdd24225ef [xemacs-hg @ 2002-11-27 07:15:02 by ben]
ben
parents: 853
diff changeset
311 return list4 (Qtiming, closure.timing, Qcall_count,
37bdd24225ef [xemacs-hg @ 2002-11-27 07:15:02 by ben]
ben
parents: 853
diff changeset
312 !NILP (Vcall_count_profile_table) ?
37bdd24225ef [xemacs-hg @ 2002-11-27 07:15:02 by ben]
ben
parents: 853
diff changeset
313 Fcopy_hash_table (Vcall_count_profile_table) :
37bdd24225ef [xemacs-hg @ 2002-11-27 07:15:02 by ben]
ben
parents: 853
diff changeset
314 make_lisp_hash_table (100, HASH_TABLE_NON_WEAK,
37bdd24225ef [xemacs-hg @ 2002-11-27 07:15:02 by ben]
ben
parents: 853
diff changeset
315 HASH_TABLE_EQ));
37bdd24225ef [xemacs-hg @ 2002-11-27 07:15:02 by ben]
ben
parents: 853
diff changeset
316 }
37bdd24225ef [xemacs-hg @ 2002-11-27 07:15:02 by ben]
ben
parents: 853
diff changeset
317
37bdd24225ef [xemacs-hg @ 2002-11-27 07:15:02 by ben]
ben
parents: 853
diff changeset
318 struct set_profiling_info_closure
37bdd24225ef [xemacs-hg @ 2002-11-27 07:15:02 by ben]
ben
parents: 853
diff changeset
319 {
37bdd24225ef [xemacs-hg @ 2002-11-27 07:15:02 by ben]
ben
parents: 853
diff changeset
320 Lisp_Object timing;
37bdd24225ef [xemacs-hg @ 2002-11-27 07:15:02 by ben]
ben
parents: 853
diff changeset
321 };
37bdd24225ef [xemacs-hg @ 2002-11-27 07:15:02 by ben]
ben
parents: 853
diff changeset
322
37bdd24225ef [xemacs-hg @ 2002-11-27 07:15:02 by ben]
ben
parents: 853
diff changeset
323 static int
37bdd24225ef [xemacs-hg @ 2002-11-27 07:15:02 by ben]
ben
parents: 853
diff changeset
324 set_profiling_info_timing_maphash (Lisp_Object key,
37bdd24225ef [xemacs-hg @ 2002-11-27 07:15:02 by ben]
ben
parents: 853
diff changeset
325 Lisp_Object val,
37bdd24225ef [xemacs-hg @ 2002-11-27 07:15:02 by ben]
ben
parents: 853
diff changeset
326 void *void_closure)
37bdd24225ef [xemacs-hg @ 2002-11-27 07:15:02 by ben]
ben
parents: 853
diff changeset
327 {
37bdd24225ef [xemacs-hg @ 2002-11-27 07:15:02 by ben]
ben
parents: 853
diff changeset
328 /* This function does not GC */
37bdd24225ef [xemacs-hg @ 2002-11-27 07:15:02 by ben]
ben
parents: 853
diff changeset
329 if (!INTP (val))
37bdd24225ef [xemacs-hg @ 2002-11-27 07:15:02 by ben]
ben
parents: 853
diff changeset
330 invalid_argument_2
37bdd24225ef [xemacs-hg @ 2002-11-27 07:15:02 by ben]
ben
parents: 853
diff changeset
331 ("Function timing count is not an integer in given entry",
37bdd24225ef [xemacs-hg @ 2002-11-27 07:15:02 by ben]
ben
parents: 853
diff changeset
332 key, val);
37bdd24225ef [xemacs-hg @ 2002-11-27 07:15:02 by ben]
ben
parents: 853
diff changeset
333
37bdd24225ef [xemacs-hg @ 2002-11-27 07:15:02 by ben]
ben
parents: 853
diff changeset
334 puthash (LISP_TO_VOID (key), (void *) XINT (val), big_profile_table);
37bdd24225ef [xemacs-hg @ 2002-11-27 07:15:02 by ben]
ben
parents: 853
diff changeset
335
37bdd24225ef [xemacs-hg @ 2002-11-27 07:15:02 by ben]
ben
parents: 853
diff changeset
336 return 0;
37bdd24225ef [xemacs-hg @ 2002-11-27 07:15:02 by ben]
ben
parents: 853
diff changeset
337 }
37bdd24225ef [xemacs-hg @ 2002-11-27 07:15:02 by ben]
ben
parents: 853
diff changeset
338
37bdd24225ef [xemacs-hg @ 2002-11-27 07:15:02 by ben]
ben
parents: 853
diff changeset
339 DEFUN ("set-profiling-info", Fset_profiling_info, 1, 1, 0, /*
37bdd24225ef [xemacs-hg @ 2002-11-27 07:15:02 by ben]
ben
parents: 853
diff changeset
340 Set the currently recorded profiling info.
37bdd24225ef [xemacs-hg @ 2002-11-27 07:15:02 by ben]
ben
parents: 853
diff changeset
341 INFO should be in the same format returned by `get-profiling-info',
37bdd24225ef [xemacs-hg @ 2002-11-27 07:15:02 by ben]
ben
parents: 853
diff changeset
342 as described there.
37bdd24225ef [xemacs-hg @ 2002-11-27 07:15:02 by ben]
ben
parents: 853
diff changeset
343 */
37bdd24225ef [xemacs-hg @ 2002-11-27 07:15:02 by ben]
ben
parents: 853
diff changeset
344 (info))
37bdd24225ef [xemacs-hg @ 2002-11-27 07:15:02 by ben]
ben
parents: 853
diff changeset
345 {
37bdd24225ef [xemacs-hg @ 2002-11-27 07:15:02 by ben]
ben
parents: 853
diff changeset
346 /* This function does not GC */
37bdd24225ef [xemacs-hg @ 2002-11-27 07:15:02 by ben]
ben
parents: 853
diff changeset
347 Fclear_profiling_info ();
37bdd24225ef [xemacs-hg @ 2002-11-27 07:15:02 by ben]
ben
parents: 853
diff changeset
348
37bdd24225ef [xemacs-hg @ 2002-11-27 07:15:02 by ben]
ben
parents: 853
diff changeset
349 {
37bdd24225ef [xemacs-hg @ 2002-11-27 07:15:02 by ben]
ben
parents: 853
diff changeset
350 EXTERNAL_PROPERTY_LIST_LOOP_3 (key, value, info)
37bdd24225ef [xemacs-hg @ 2002-11-27 07:15:02 by ben]
ben
parents: 853
diff changeset
351 {
37bdd24225ef [xemacs-hg @ 2002-11-27 07:15:02 by ben]
ben
parents: 853
diff changeset
352 if (EQ (key, Qtiming))
37bdd24225ef [xemacs-hg @ 2002-11-27 07:15:02 by ben]
ben
parents: 853
diff changeset
353 {
37bdd24225ef [xemacs-hg @ 2002-11-27 07:15:02 by ben]
ben
parents: 853
diff changeset
354 CHECK_HASH_TABLE (value);
37bdd24225ef [xemacs-hg @ 2002-11-27 07:15:02 by ben]
ben
parents: 853
diff changeset
355 create_timing_profile_table ();
37bdd24225ef [xemacs-hg @ 2002-11-27 07:15:02 by ben]
ben
parents: 853
diff changeset
356 elisp_maphash_unsafe (set_profiling_info_timing_maphash, value,
37bdd24225ef [xemacs-hg @ 2002-11-27 07:15:02 by ben]
ben
parents: 853
diff changeset
357 NULL);
37bdd24225ef [xemacs-hg @ 2002-11-27 07:15:02 by ben]
ben
parents: 853
diff changeset
358 }
37bdd24225ef [xemacs-hg @ 2002-11-27 07:15:02 by ben]
ben
parents: 853
diff changeset
359 else if (EQ (key, Qcall_count))
37bdd24225ef [xemacs-hg @ 2002-11-27 07:15:02 by ben]
ben
parents: 853
diff changeset
360 {
37bdd24225ef [xemacs-hg @ 2002-11-27 07:15:02 by ben]
ben
parents: 853
diff changeset
361 Vcall_count_profile_table = Fcopy_hash_table (value);
37bdd24225ef [xemacs-hg @ 2002-11-27 07:15:02 by ben]
ben
parents: 853
diff changeset
362 }
37bdd24225ef [xemacs-hg @ 2002-11-27 07:15:02 by ben]
ben
parents: 853
diff changeset
363 else
37bdd24225ef [xemacs-hg @ 2002-11-27 07:15:02 by ben]
ben
parents: 853
diff changeset
364 invalid_constant ("Unrecognized profiling-info keyword", key);
37bdd24225ef [xemacs-hg @ 2002-11-27 07:15:02 by ben]
ben
parents: 853
diff changeset
365 }
37bdd24225ef [xemacs-hg @ 2002-11-27 07:15:02 by ben]
ben
parents: 853
diff changeset
366 }
37bdd24225ef [xemacs-hg @ 2002-11-27 07:15:02 by ben]
ben
parents: 853
diff changeset
367
37bdd24225ef [xemacs-hg @ 2002-11-27 07:15:02 by ben]
ben
parents: 853
diff changeset
368 return Qnil;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
369 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
370
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
371 static int
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 434
diff changeset
372 mark_profiling_info_maphash (const void *void_key,
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
373 void *void_val,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
374 void *void_closure)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
375 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
376 Lisp_Object key;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
377
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
378 key = VOID_TO_LISP (void_key);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
379 mark_object (key);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
380 return 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
381 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
382
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
383 void
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
384 mark_profiling_info (void)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
385 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
386 /* This function does not GC */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
387 if (big_profile_table)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
388 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
389 inside_profiling = 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
390 maphash (mark_profiling_info_maphash, big_profile_table, 0);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
391 inside_profiling = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
392 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
393 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
394
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
395 DEFUN ("profiling-active-p", Fprofiling_active_p, 0, 0, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
396 Return non-nil if profiling information is currently being recorded.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
397 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
398 ())
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
399 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
400 return profiling_active ? Qt : Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
401 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
402
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
403 void
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
404 syms_of_profile (void)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
405 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
406 DEFSUBR (Fstart_profiling);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
407 DEFSUBR (Fstop_profiling);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
408 DEFSUBR (Fget_profiling_info);
1123
37bdd24225ef [xemacs-hg @ 2002-11-27 07:15:02 by ben]
ben
parents: 853
diff changeset
409 DEFSUBR (Fset_profiling_info);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
410 DEFSUBR (Fclear_profiling_info);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
411 DEFSUBR (Fprofiling_active_p);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
412 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
413
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
414 void
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
415 vars_of_profile (void)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
416 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
417 DEFVAR_INT ("default-profiling-interval", &default_profiling_interval /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
418 Default CPU time in microseconds between profiling sampling.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
419 Used when the argument to `start-profiling' is nil or omitted.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
420 Note that the time in question is CPU time (when the program is executing
1123
37bdd24225ef [xemacs-hg @ 2002-11-27 07:15:02 by ben]
ben
parents: 853
diff changeset
421 or the kernel is executing on behalf of the program) and not real time, and
37bdd24225ef [xemacs-hg @ 2002-11-27 07:15:02 by ben]
ben
parents: 853
diff changeset
422 there is usually a machine-dependent limit on how small this value can be.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
423 */ );
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
424 default_profiling_interval = 1000;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
425
1123
37bdd24225ef [xemacs-hg @ 2002-11-27 07:15:02 by ben]
ben
parents: 853
diff changeset
426 staticpro (&Vcall_count_profile_table);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
427 Vcall_count_profile_table = Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
429 inside_profiling = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
430
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 613
diff changeset
431 QSin_redisplay = build_msg_string ("(in redisplay)");
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
432 staticpro (&QSin_redisplay);
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 613
diff changeset
433 QSin_garbage_collection = build_msg_string ("(in garbage collection)");
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
434 staticpro (&QSin_garbage_collection);
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 613
diff changeset
435 QSunknown = build_msg_string ("(unknown)");
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
436 staticpro (&QSunknown);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
437 QSprocessing_events_at_top_level =
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 613
diff changeset
438 build_msg_string ("(processing events at top level)");
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
439 staticpro (&QSprocessing_events_at_top_level);
1123
37bdd24225ef [xemacs-hg @ 2002-11-27 07:15:02 by ben]
ben
parents: 853
diff changeset
440
37bdd24225ef [xemacs-hg @ 2002-11-27 07:15:02 by ben]
ben
parents: 853
diff changeset
441 DEFSYMBOL (Qtiming);
37bdd24225ef [xemacs-hg @ 2002-11-27 07:15:02 by ben]
ben
parents: 853
diff changeset
442 DEFSYMBOL (Qcall_count);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
443 }