annotate src/profile.c @ 44:8d2a9b52c682 r19-15prefinal

Import from CVS: tag r19-15prefinal
author cvs
date Mon, 13 Aug 2007 08:55:10 +0200
parents 859a2309aef8
children c0965ff3b039
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1 /* Why the hell is XEmacs so fucking slow?
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2 Copyright (C) 1996 Ben Wing.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4 This file is part of XEmacs.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6 XEmacs is free software; you can redistribute it and/or modify it
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
7 under the terms of the GNU General Public License as published by the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
8 Free Software Foundation; either version 2, or (at your option) any
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
9 later version.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
10
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
11 XEmacs is distributed in the hope that it will be useful, but WITHOUT
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
12 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
14 for more details.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
15
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
16 You should have received a copy of the GNU General Public License
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
17 along with XEmacs; see the file COPYING. If not, write to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
18 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
19 Boston, MA 02111-1307, USA. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
20
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
21 #include <config.h>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
22 #include "lisp.h"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
23
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
24 #include "backtrace.h"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
25 #include "bytecode.h"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
26 #include "hash.h"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
27
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
28 #include "syssignal.h"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
29 #include "systime.h"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
30
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
31 /*
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
32
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
33 We implement our own profiling scheme so that we can determine things
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
34 like which Lisp functions are occupying the most time. Any standard
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
35 OS-provided profiling works on C functions, which is somewhat useless.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
36
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
37 The basic idea is simple. We set a profiling timer using
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
38 setitimer (ITIMER_PROF), which generates a SIGPROF every so often.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
39 \(This runs not in real time but rather when the process is executing
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
40 or the system is running on behalf of the process.) When the signal
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
41 goes off, we see what we're in, and add by 1 the count associated with
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
42 that function.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
43
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
44 It would be nice to use the Lisp allocation mechanism etc. to keep
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
45 track of the profiling information, but we can't because that's not
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
46 safe, and trying to make it safe would be much more work than is
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
47 worth.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
48
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
49 */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
50
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
51 c_hashtable big_profile_table;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
52
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
53 int default_profiling_interval;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
54
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
55 int profiling_active;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
56
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
57 /* The normal flag in_display is used as a critical-section flag
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
58 and is not set the whole time we're in redisplay. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
59 int profiling_redisplay_flag;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
60
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
61 Lisp_Object QSin_redisplay;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
62 Lisp_Object QSin_garbage_collection;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
63 Lisp_Object QSprocessing_events_at_top_level;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
64 Lisp_Object QSunknown;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
65
44
8d2a9b52c682 Import from CVS: tag r19-15prefinal
cvs
parents: 20
diff changeset
66 /* We use inside_profiling to prevent the handler from writing to
8d2a9b52c682 Import from CVS: tag r19-15prefinal
cvs
parents: 20
diff changeset
67 the table while another routine is operating on it. We also set
8d2a9b52c682 Import from CVS: tag r19-15prefinal
cvs
parents: 20
diff changeset
68 inside_profiling in case the timeout between signal calls is short
8d2a9b52c682 Import from CVS: tag r19-15prefinal
cvs
parents: 20
diff changeset
69 enough to catch us while we're already in there. */
8d2a9b52c682 Import from CVS: tag r19-15prefinal
cvs
parents: 20
diff changeset
70 volatile static int inside_profiling;
8d2a9b52c682 Import from CVS: tag r19-15prefinal
cvs
parents: 20
diff changeset
71
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
72 static SIGTYPE
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
73 sigprof_handler (int signo)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
74 {
44
8d2a9b52c682 Import from CVS: tag r19-15prefinal
cvs
parents: 20
diff changeset
75 /* Don't do anything if we are shutting down, or are doing a maphash
8d2a9b52c682 Import from CVS: tag r19-15prefinal
cvs
parents: 20
diff changeset
76 or clrhash on the table. */
8d2a9b52c682 Import from CVS: tag r19-15prefinal
cvs
parents: 20
diff changeset
77 if (!inside_profiling && !preparing_for_armageddon)
8d2a9b52c682 Import from CVS: tag r19-15prefinal
cvs
parents: 20
diff changeset
78 {
8d2a9b52c682 Import from CVS: tag r19-15prefinal
cvs
parents: 20
diff changeset
79 Lisp_Object fun;
8d2a9b52c682 Import from CVS: tag r19-15prefinal
cvs
parents: 20
diff changeset
80
8d2a9b52c682 Import from CVS: tag r19-15prefinal
cvs
parents: 20
diff changeset
81 /* If something below causes an error to be signaled, we'll
8d2a9b52c682 Import from CVS: tag r19-15prefinal
cvs
parents: 20
diff changeset
82 not correctly reset this flag. But we'll be in worse shape
8d2a9b52c682 Import from CVS: tag r19-15prefinal
cvs
parents: 20
diff changeset
83 than that anyways, since we'll longjmp back to the last
8d2a9b52c682 Import from CVS: tag r19-15prefinal
cvs
parents: 20
diff changeset
84 condition case. */
8d2a9b52c682 Import from CVS: tag r19-15prefinal
cvs
parents: 20
diff changeset
85 inside_profiling = 1;
8d2a9b52c682 Import from CVS: tag r19-15prefinal
cvs
parents: 20
diff changeset
86
8d2a9b52c682 Import from CVS: tag r19-15prefinal
cvs
parents: 20
diff changeset
87 if (profiling_redisplay_flag)
8d2a9b52c682 Import from CVS: tag r19-15prefinal
cvs
parents: 20
diff changeset
88 fun = QSin_redisplay;
8d2a9b52c682 Import from CVS: tag r19-15prefinal
cvs
parents: 20
diff changeset
89 else if (gc_in_progress)
8d2a9b52c682 Import from CVS: tag r19-15prefinal
cvs
parents: 20
diff changeset
90 fun = QSin_garbage_collection;
8d2a9b52c682 Import from CVS: tag r19-15prefinal
cvs
parents: 20
diff changeset
91 else if (backtrace_list)
8d2a9b52c682 Import from CVS: tag r19-15prefinal
cvs
parents: 20
diff changeset
92 {
8d2a9b52c682 Import from CVS: tag r19-15prefinal
cvs
parents: 20
diff changeset
93 fun = *backtrace_list->function;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
94
44
8d2a9b52c682 Import from CVS: tag r19-15prefinal
cvs
parents: 20
diff changeset
95 /* #### dmoore - why do we need to unmark it, we aren't in GC. */
8d2a9b52c682 Import from CVS: tag r19-15prefinal
cvs
parents: 20
diff changeset
96 XUNMARK (fun);
8d2a9b52c682 Import from CVS: tag r19-15prefinal
cvs
parents: 20
diff changeset
97 if (!GC_SYMBOLP (fun) && !GC_COMPILED_FUNCTIONP (fun))
8d2a9b52c682 Import from CVS: tag r19-15prefinal
cvs
parents: 20
diff changeset
98 fun = QSunknown;
8d2a9b52c682 Import from CVS: tag r19-15prefinal
cvs
parents: 20
diff changeset
99 }
8d2a9b52c682 Import from CVS: tag r19-15prefinal
cvs
parents: 20
diff changeset
100 else
8d2a9b52c682 Import from CVS: tag r19-15prefinal
cvs
parents: 20
diff changeset
101 fun = QSprocessing_events_at_top_level;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
102
44
8d2a9b52c682 Import from CVS: tag r19-15prefinal
cvs
parents: 20
diff changeset
103 {
8d2a9b52c682 Import from CVS: tag r19-15prefinal
cvs
parents: 20
diff changeset
104 /* #### see comment about memory allocation in start-profiling.
8d2a9b52c682 Import from CVS: tag r19-15prefinal
cvs
parents: 20
diff changeset
105 Allocating memory in a signal handler is BAD BAD BAD.
8d2a9b52c682 Import from CVS: tag r19-15prefinal
cvs
parents: 20
diff changeset
106 If you are using the non-mmap rel-alloc code, you might
8d2a9b52c682 Import from CVS: tag r19-15prefinal
cvs
parents: 20
diff changeset
107 lose because of this. Even worse, if the memory allocation
8d2a9b52c682 Import from CVS: tag r19-15prefinal
cvs
parents: 20
diff changeset
108 fails, the `error' generated whacks everything hard. */
8d2a9b52c682 Import from CVS: tag r19-15prefinal
cvs
parents: 20
diff changeset
109 long count;
8d2a9b52c682 Import from CVS: tag r19-15prefinal
cvs
parents: 20
diff changeset
110 CONST void *vval;
8d2a9b52c682 Import from CVS: tag r19-15prefinal
cvs
parents: 20
diff changeset
111
8d2a9b52c682 Import from CVS: tag r19-15prefinal
cvs
parents: 20
diff changeset
112 if (gethash (LISP_TO_VOID (fun), big_profile_table, &vval))
8d2a9b52c682 Import from CVS: tag r19-15prefinal
cvs
parents: 20
diff changeset
113 count = (long) vval;
8d2a9b52c682 Import from CVS: tag r19-15prefinal
cvs
parents: 20
diff changeset
114 else
8d2a9b52c682 Import from CVS: tag r19-15prefinal
cvs
parents: 20
diff changeset
115 count = 0;
8d2a9b52c682 Import from CVS: tag r19-15prefinal
cvs
parents: 20
diff changeset
116 count++;
8d2a9b52c682 Import from CVS: tag r19-15prefinal
cvs
parents: 20
diff changeset
117 vval = (CONST void *) count;
8d2a9b52c682 Import from CVS: tag r19-15prefinal
cvs
parents: 20
diff changeset
118 puthash (LISP_TO_VOID (fun), (void *) vval, big_profile_table);
8d2a9b52c682 Import from CVS: tag r19-15prefinal
cvs
parents: 20
diff changeset
119 }
8d2a9b52c682 Import from CVS: tag r19-15prefinal
cvs
parents: 20
diff changeset
120
8d2a9b52c682 Import from CVS: tag r19-15prefinal
cvs
parents: 20
diff changeset
121 inside_profiling = 0;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
122 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
123 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
124
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 0
diff changeset
125 DEFUN ("start-profiling", Fstart_profiling, 0, 1, 0, /*
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
126 Start profiling, with profile queries every MICROSECS.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
127 If MICROSECS is nil or omitted, the value of `default-profiling-interval'
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
128 is used.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
129
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
130 You can retrieve the recorded profiling info using `get-profiling-info'.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
131
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
132 Starting and stopping profiling does not clear the currently recorded
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
133 info. Thus you can start and stop as many times as you want and everything
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 0
diff changeset
134 will be properly accumulated.
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 0
diff changeset
135 */
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 0
diff changeset
136 (microsecs))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
137 {
44
8d2a9b52c682 Import from CVS: tag r19-15prefinal
cvs
parents: 20
diff changeset
138 /* This function can GC */
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
139 int msecs;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
140 struct itimerval foo;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
141
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
142 /* #### The hash code can safely be called from a signal handler
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
143 except when it has to grow the hashtable. In this case, it calls
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
144 realloc(), which is not (in general) re-entrant. We just be
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
145 sleazy and make the table large enough that it (hopefully) won't
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
146 need to be realloc()ed. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
147 if (!big_profile_table)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
148 big_profile_table = make_hashtable (10000);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
149 if (NILP (microsecs))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
150 msecs = default_profiling_interval;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
151 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
152 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
153 CHECK_NATNUM (microsecs);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
154 msecs = XINT (microsecs);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
155 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
156 if (msecs <= 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
157 msecs = 1000;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
158
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
159 signal (SIGPROF, sigprof_handler);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
160 foo.it_value.tv_sec = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
161 foo.it_value.tv_usec = msecs;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
162 EMACS_NORMALIZE_TIME (foo.it_value);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
163 foo.it_interval = foo.it_value;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
164 profiling_active = 1;
44
8d2a9b52c682 Import from CVS: tag r19-15prefinal
cvs
parents: 20
diff changeset
165 inside_profiling = 0;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
166 setitimer (ITIMER_PROF, &foo, 0);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
167 return Qnil;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
168 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
169
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 0
diff changeset
170 DEFUN ("stop-profiling", Fstop_profiling, 0, 0, 0, /*
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
171 Stop profiling.
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 0
diff changeset
172 */
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 0
diff changeset
173 ())
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
174 {
44
8d2a9b52c682 Import from CVS: tag r19-15prefinal
cvs
parents: 20
diff changeset
175 /* This function does not GC */
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
176 struct itimerval foo;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
177
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
178 foo.it_value.tv_sec = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
179 foo.it_value.tv_usec = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
180 foo.it_interval = foo.it_value;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
181 setitimer (ITIMER_PROF, &foo, 0);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
182 profiling_active = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
183 signal (SIGPROF, fatal_error_signal);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
184 return Qnil;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
185 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
186
44
8d2a9b52c682 Import from CVS: tag r19-15prefinal
cvs
parents: 20
diff changeset
187 static Lisp_Object
8d2a9b52c682 Import from CVS: tag r19-15prefinal
cvs
parents: 20
diff changeset
188 profile_lock_unwind (Lisp_Object ignore)
8d2a9b52c682 Import from CVS: tag r19-15prefinal
cvs
parents: 20
diff changeset
189 {
8d2a9b52c682 Import from CVS: tag r19-15prefinal
cvs
parents: 20
diff changeset
190 inside_profiling = 0;
8d2a9b52c682 Import from CVS: tag r19-15prefinal
cvs
parents: 20
diff changeset
191 return Qnil;
8d2a9b52c682 Import from CVS: tag r19-15prefinal
cvs
parents: 20
diff changeset
192 }
8d2a9b52c682 Import from CVS: tag r19-15prefinal
cvs
parents: 20
diff changeset
193
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
194 struct get_profiling_info_closure
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
195 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
196 Lisp_Object accum;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
197 };
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
198
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
199 static void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
200 get_profiling_info_maphash (CONST void *void_key,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
201 void *void_val,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
202 void *void_closure)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
203 {
44
8d2a9b52c682 Import from CVS: tag r19-15prefinal
cvs
parents: 20
diff changeset
204 /* This function does not GC */
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
205 Lisp_Object key;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
206 struct get_profiling_info_closure *closure = void_closure;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
207 EMACS_INT val;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
208
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
209 CVOID_TO_LISP (key, void_key);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
210 val = (EMACS_INT) void_val;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
211
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
212 closure->accum = Fcons (Fcons (key, make_int (val)),
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
213 closure->accum);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
214 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
215
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 0
diff changeset
216 DEFUN ("get-profiling-info", Fget_profiling_info, 0, 0, 0, /*
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
217 Return the profiling info as an alist.
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 0
diff changeset
218 */
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 0
diff changeset
219 ())
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
220 {
44
8d2a9b52c682 Import from CVS: tag r19-15prefinal
cvs
parents: 20
diff changeset
221 /* This function does not GC */
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
222 struct get_profiling_info_closure closure;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
223
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
224 closure.accum = Qnil;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
225 if (big_profile_table)
44
8d2a9b52c682 Import from CVS: tag r19-15prefinal
cvs
parents: 20
diff changeset
226 {
8d2a9b52c682 Import from CVS: tag r19-15prefinal
cvs
parents: 20
diff changeset
227 int count = specpdl_depth ();
8d2a9b52c682 Import from CVS: tag r19-15prefinal
cvs
parents: 20
diff changeset
228 record_unwind_protect (profile_lock_unwind, Qnil);
8d2a9b52c682 Import from CVS: tag r19-15prefinal
cvs
parents: 20
diff changeset
229 inside_profiling = 1;
8d2a9b52c682 Import from CVS: tag r19-15prefinal
cvs
parents: 20
diff changeset
230 maphash (get_profiling_info_maphash, big_profile_table, &closure);
8d2a9b52c682 Import from CVS: tag r19-15prefinal
cvs
parents: 20
diff changeset
231 unbind_to (count, Qnil);
8d2a9b52c682 Import from CVS: tag r19-15prefinal
cvs
parents: 20
diff changeset
232 }
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
233 return closure.accum;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
234 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
235
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
236 struct mark_profiling_info_closure
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
237 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
238 void (*markfun) (Lisp_Object);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
239 };
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
240
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
241 static void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
242 mark_profiling_info_maphash (CONST void *void_key,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
243 void *void_val,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
244 void *void_closure)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
245 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
246 Lisp_Object key;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
247 struct mark_profiling_info_closure *closure = void_closure;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
248
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
249 CVOID_TO_LISP (key, void_key);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
250 (closure->markfun) (key);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
251 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
252
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
253 void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
254 mark_profiling_info (void (*markfun) (Lisp_Object))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
255 {
44
8d2a9b52c682 Import from CVS: tag r19-15prefinal
cvs
parents: 20
diff changeset
256 /* This function does not GC (if markfun doesn't) */
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
257 struct mark_profiling_info_closure closure;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
258
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
259 closure.markfun = markfun;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
260 if (big_profile_table)
44
8d2a9b52c682 Import from CVS: tag r19-15prefinal
cvs
parents: 20
diff changeset
261 {
8d2a9b52c682 Import from CVS: tag r19-15prefinal
cvs
parents: 20
diff changeset
262 inside_profiling = 1;
8d2a9b52c682 Import from CVS: tag r19-15prefinal
cvs
parents: 20
diff changeset
263 maphash (mark_profiling_info_maphash, big_profile_table, &closure);
8d2a9b52c682 Import from CVS: tag r19-15prefinal
cvs
parents: 20
diff changeset
264 inside_profiling = 0;
8d2a9b52c682 Import from CVS: tag r19-15prefinal
cvs
parents: 20
diff changeset
265 }
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
266 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
267
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 0
diff changeset
268 DEFUN ("clear-profiling-info", Fclear_profiling_info, 0, 0, 0, /*
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
269 Clear out the recorded profiling info.
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 0
diff changeset
270 */
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 0
diff changeset
271 ())
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
272 {
44
8d2a9b52c682 Import from CVS: tag r19-15prefinal
cvs
parents: 20
diff changeset
273 /* This function does not GC */
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
274 if (big_profile_table)
44
8d2a9b52c682 Import from CVS: tag r19-15prefinal
cvs
parents: 20
diff changeset
275 {
8d2a9b52c682 Import from CVS: tag r19-15prefinal
cvs
parents: 20
diff changeset
276 inside_profiling = 1;
8d2a9b52c682 Import from CVS: tag r19-15prefinal
cvs
parents: 20
diff changeset
277 clrhash (big_profile_table);
8d2a9b52c682 Import from CVS: tag r19-15prefinal
cvs
parents: 20
diff changeset
278 inside_profiling = 0;
8d2a9b52c682 Import from CVS: tag r19-15prefinal
cvs
parents: 20
diff changeset
279 }
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
280 return Qnil;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
281 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
282
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 0
diff changeset
283 DEFUN ("profiling-active-p", Fprofiling_active_p, 0, 0, 0, /*
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
284 Return non-nil if profiling information is currently being recorded.
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 0
diff changeset
285 */
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 0
diff changeset
286 ())
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
287 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
288 return profiling_active ? Qt : Qnil;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
289 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
290
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
291 void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
292 syms_of_profile (void)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
293 {
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 0
diff changeset
294 DEFSUBR (Fstart_profiling);
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 0
diff changeset
295 DEFSUBR (Fstop_profiling);
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 0
diff changeset
296 DEFSUBR (Fget_profiling_info);
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 0
diff changeset
297 DEFSUBR (Fclear_profiling_info);
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 0
diff changeset
298 DEFSUBR (Fprofiling_active_p);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
299 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
300
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
301 void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
302 vars_of_profile (void)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
303 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
304 DEFVAR_INT ("default-profiling-interval", &default_profiling_interval /*
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
305 Default time in microseconds between profiling queries.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
306 Used when the argument to `start-profiling' is nil or omitted.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
307 Note that the time in question is CPU time (when the program is executing
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
308 or the kernel is executing on behalf of the program) and not real time.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
309 */ );
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
310 default_profiling_interval = 1000;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
311
44
8d2a9b52c682 Import from CVS: tag r19-15prefinal
cvs
parents: 20
diff changeset
312 inside_profiling = 0;
8d2a9b52c682 Import from CVS: tag r19-15prefinal
cvs
parents: 20
diff changeset
313
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
314 QSin_redisplay = build_string ("(in redisplay)");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
315 staticpro (&QSin_redisplay);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
316 QSin_garbage_collection = build_string ("(in garbage collection)");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
317 staticpro (&QSin_garbage_collection);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
318 QSunknown = build_string ("(unknown)");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
319 staticpro (&QSunknown);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
320 QSprocessing_events_at_top_level =
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
321 build_string ("(processing events at top level)");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
322 staticpro (&QSprocessing_events_at_top_level);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
323 }