annotate src/profile.c @ 221:6c0ae1f9357f r20-4b9

Import from CVS: tag r20-4b9
author cvs
date Mon, 13 Aug 2007 10:10:02 +0200
parents e45d5e7c476e
children f955c73f5258
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
116
9f59509498e1 Import from CVS: tag r20-1b10
cvs
parents: 70
diff changeset
66 /* We use inside_profiling to prevent the handler from writing to
9f59509498e1 Import from CVS: tag r20-1b10
cvs
parents: 70
diff changeset
67 the table while another routine is operating on it. We also set
9f59509498e1 Import from CVS: tag r20-1b10
cvs
parents: 70
diff changeset
68 inside_profiling in case the timeout between signal calls is short
9f59509498e1 Import from CVS: tag r20-1b10
cvs
parents: 70
diff changeset
69 enough to catch us while we're already in there. */
149
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 116
diff changeset
70 static volatile int inside_profiling;
116
9f59509498e1 Import from CVS: tag r20-1b10
cvs
parents: 70
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 {
116
9f59509498e1 Import from CVS: tag r20-1b10
cvs
parents: 70
diff changeset
75 /* Don't do anything if we are shutting down, or are doing a maphash
9f59509498e1 Import from CVS: tag r20-1b10
cvs
parents: 70
diff changeset
76 or clrhash on the table. */
9f59509498e1 Import from CVS: tag r20-1b10
cvs
parents: 70
diff changeset
77 if (!inside_profiling && !preparing_for_armageddon)
9f59509498e1 Import from CVS: tag r20-1b10
cvs
parents: 70
diff changeset
78 {
9f59509498e1 Import from CVS: tag r20-1b10
cvs
parents: 70
diff changeset
79 Lisp_Object fun;
9f59509498e1 Import from CVS: tag r20-1b10
cvs
parents: 70
diff changeset
80
9f59509498e1 Import from CVS: tag r20-1b10
cvs
parents: 70
diff changeset
81 /* If something below causes an error to be signaled, we'll
9f59509498e1 Import from CVS: tag r20-1b10
cvs
parents: 70
diff changeset
82 not correctly reset this flag. But we'll be in worse shape
9f59509498e1 Import from CVS: tag r20-1b10
cvs
parents: 70
diff changeset
83 than that anyways, since we'll longjmp back to the last
9f59509498e1 Import from CVS: tag r20-1b10
cvs
parents: 70
diff changeset
84 condition case. */
9f59509498e1 Import from CVS: tag r20-1b10
cvs
parents: 70
diff changeset
85 inside_profiling = 1;
9f59509498e1 Import from CVS: tag r20-1b10
cvs
parents: 70
diff changeset
86
9f59509498e1 Import from CVS: tag r20-1b10
cvs
parents: 70
diff changeset
87 if (profiling_redisplay_flag)
9f59509498e1 Import from CVS: tag r20-1b10
cvs
parents: 70
diff changeset
88 fun = QSin_redisplay;
9f59509498e1 Import from CVS: tag r20-1b10
cvs
parents: 70
diff changeset
89 else if (gc_in_progress)
9f59509498e1 Import from CVS: tag r20-1b10
cvs
parents: 70
diff changeset
90 fun = QSin_garbage_collection;
9f59509498e1 Import from CVS: tag r20-1b10
cvs
parents: 70
diff changeset
91 else if (backtrace_list)
9f59509498e1 Import from CVS: tag r20-1b10
cvs
parents: 70
diff changeset
92 {
9f59509498e1 Import from CVS: tag r20-1b10
cvs
parents: 70
diff changeset
93 fun = *backtrace_list->function;
44
8d2a9b52c682 Import from CVS: tag r19-15prefinal
cvs
parents: 20
diff changeset
94
116
9f59509498e1 Import from CVS: tag r20-1b10
cvs
parents: 70
diff changeset
95 if (!GC_SYMBOLP (fun) && !GC_COMPILED_FUNCTIONP (fun))
9f59509498e1 Import from CVS: tag r20-1b10
cvs
parents: 70
diff changeset
96 fun = QSunknown;
9f59509498e1 Import from CVS: tag r20-1b10
cvs
parents: 70
diff changeset
97 }
9f59509498e1 Import from CVS: tag r20-1b10
cvs
parents: 70
diff changeset
98 else
9f59509498e1 Import from CVS: tag r20-1b10
cvs
parents: 70
diff changeset
99 fun = QSprocessing_events_at_top_level;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
100
116
9f59509498e1 Import from CVS: tag r20-1b10
cvs
parents: 70
diff changeset
101 {
9f59509498e1 Import from CVS: tag r20-1b10
cvs
parents: 70
diff changeset
102 /* #### see comment about memory allocation in start-profiling.
9f59509498e1 Import from CVS: tag r20-1b10
cvs
parents: 70
diff changeset
103 Allocating memory in a signal handler is BAD BAD BAD.
9f59509498e1 Import from CVS: tag r20-1b10
cvs
parents: 70
diff changeset
104 If you are using the non-mmap rel-alloc code, you might
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 149
diff changeset
105 lose because of this. Even worse, if the memory allocation
116
9f59509498e1 Import from CVS: tag r20-1b10
cvs
parents: 70
diff changeset
106 fails, the `error' generated whacks everything hard. */
9f59509498e1 Import from CVS: tag r20-1b10
cvs
parents: 70
diff changeset
107 long count;
9f59509498e1 Import from CVS: tag r20-1b10
cvs
parents: 70
diff changeset
108 CONST void *vval;
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 149
diff changeset
109
116
9f59509498e1 Import from CVS: tag r20-1b10
cvs
parents: 70
diff changeset
110 if (gethash (LISP_TO_VOID (fun), big_profile_table, &vval))
9f59509498e1 Import from CVS: tag r20-1b10
cvs
parents: 70
diff changeset
111 count = (long) vval;
9f59509498e1 Import from CVS: tag r20-1b10
cvs
parents: 70
diff changeset
112 else
9f59509498e1 Import from CVS: tag r20-1b10
cvs
parents: 70
diff changeset
113 count = 0;
9f59509498e1 Import from CVS: tag r20-1b10
cvs
parents: 70
diff changeset
114 count++;
9f59509498e1 Import from CVS: tag r20-1b10
cvs
parents: 70
diff changeset
115 vval = (CONST void *) count;
9f59509498e1 Import from CVS: tag r20-1b10
cvs
parents: 70
diff changeset
116 puthash (LISP_TO_VOID (fun), (void *) vval, big_profile_table);
9f59509498e1 Import from CVS: tag r20-1b10
cvs
parents: 70
diff changeset
117 }
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 149
diff changeset
118
116
9f59509498e1 Import from CVS: tag r20-1b10
cvs
parents: 70
diff changeset
119 inside_profiling = 0;
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 56
diff changeset
120 }
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
121 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
122
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 0
diff changeset
123 DEFUN ("start-profiling", Fstart_profiling, 0, 1, 0, /*
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
124 Start profiling, with profile queries every MICROSECS.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
125 If MICROSECS is nil or omitted, the value of `default-profiling-interval'
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
126 is used.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
127
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
128 You can retrieve the recorded profiling info using `get-profiling-info'.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
129
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
130 Starting and stopping profiling does not clear the currently recorded
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
131 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
132 will be properly accumulated.
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 0
diff changeset
133 */
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 0
diff changeset
134 (microsecs))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
135 {
116
9f59509498e1 Import from CVS: tag r20-1b10
cvs
parents: 70
diff changeset
136 /* This function can GC */
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
137 int msecs;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
138 struct itimerval foo;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
139
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
140 /* #### The hash code can safely be called from a signal handler
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
141 except when it has to grow the hashtable. In this case, it calls
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
142 realloc(), which is not (in general) re-entrant. We just be
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
143 sleazy and make the table large enough that it (hopefully) won't
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
144 need to be realloc()ed. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
145 if (!big_profile_table)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
146 big_profile_table = make_hashtable (10000);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
147 if (NILP (microsecs))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
148 msecs = default_profiling_interval;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
149 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
150 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
151 CHECK_NATNUM (microsecs);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
152 msecs = XINT (microsecs);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
153 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
154 if (msecs <= 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
155 msecs = 1000;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
156
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
157 signal (SIGPROF, sigprof_handler);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
158 foo.it_value.tv_sec = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
159 foo.it_value.tv_usec = msecs;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
160 EMACS_NORMALIZE_TIME (foo.it_value);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
161 foo.it_interval = foo.it_value;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
162 profiling_active = 1;
116
9f59509498e1 Import from CVS: tag r20-1b10
cvs
parents: 70
diff changeset
163 inside_profiling = 0;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
164 setitimer (ITIMER_PROF, &foo, 0);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
165 return Qnil;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
166 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
167
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 0
diff changeset
168 DEFUN ("stop-profiling", Fstop_profiling, 0, 0, 0, /*
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
169 Stop profiling.
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 0
diff changeset
170 */
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 0
diff changeset
171 ())
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
172 {
116
9f59509498e1 Import from CVS: tag r20-1b10
cvs
parents: 70
diff changeset
173 /* This function does not GC */
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
174 struct itimerval foo;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
175
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
176 foo.it_value.tv_sec = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
177 foo.it_value.tv_usec = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
178 foo.it_interval = foo.it_value;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
179 setitimer (ITIMER_PROF, &foo, 0);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
180 profiling_active = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
181 signal (SIGPROF, fatal_error_signal);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
182 return Qnil;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
183 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
184
116
9f59509498e1 Import from CVS: tag r20-1b10
cvs
parents: 70
diff changeset
185 static Lisp_Object
9f59509498e1 Import from CVS: tag r20-1b10
cvs
parents: 70
diff changeset
186 profile_lock_unwind (Lisp_Object ignore)
9f59509498e1 Import from CVS: tag r20-1b10
cvs
parents: 70
diff changeset
187 {
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 149
diff changeset
188 inside_profiling = 0;
116
9f59509498e1 Import from CVS: tag r20-1b10
cvs
parents: 70
diff changeset
189 return Qnil;
9f59509498e1 Import from CVS: tag r20-1b10
cvs
parents: 70
diff changeset
190 }
9f59509498e1 Import from CVS: tag r20-1b10
cvs
parents: 70
diff changeset
191
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
192 struct get_profiling_info_closure
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
193 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
194 Lisp_Object accum;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
195 };
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
196
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
197 static void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
198 get_profiling_info_maphash (CONST void *void_key,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
199 void *void_val,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
200 void *void_closure)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
201 {
116
9f59509498e1 Import from CVS: tag r20-1b10
cvs
parents: 70
diff changeset
202 /* This function does not GC */
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
203 Lisp_Object key;
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 149
diff changeset
204 struct get_profiling_info_closure *closure
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 149
diff changeset
205 = (struct get_profiling_info_closure *) void_closure;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
206 EMACS_INT val;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
207
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
208 CVOID_TO_LISP (key, void_key);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
209 val = (EMACS_INT) void_val;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
210
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 149
diff changeset
211 closure->accum = Fcons (Fcons (key, make_int (val)), closure->accum);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
212 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
213
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 0
diff changeset
214 DEFUN ("get-profiling-info", Fget_profiling_info, 0, 0, 0, /*
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
215 Return the profiling info as an alist.
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 0
diff changeset
216 */
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 0
diff changeset
217 ())
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
218 {
116
9f59509498e1 Import from CVS: tag r20-1b10
cvs
parents: 70
diff changeset
219 /* This function does not GC */
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
220 struct get_profiling_info_closure closure;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
221
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
222 closure.accum = Qnil;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
223 if (big_profile_table)
116
9f59509498e1 Import from CVS: tag r20-1b10
cvs
parents: 70
diff changeset
224 {
9f59509498e1 Import from CVS: tag r20-1b10
cvs
parents: 70
diff changeset
225 int count = specpdl_depth ();
9f59509498e1 Import from CVS: tag r20-1b10
cvs
parents: 70
diff changeset
226 record_unwind_protect (profile_lock_unwind, Qnil);
9f59509498e1 Import from CVS: tag r20-1b10
cvs
parents: 70
diff changeset
227 inside_profiling = 1;
9f59509498e1 Import from CVS: tag r20-1b10
cvs
parents: 70
diff changeset
228 maphash (get_profiling_info_maphash, big_profile_table, &closure);
9f59509498e1 Import from CVS: tag r20-1b10
cvs
parents: 70
diff changeset
229 unbind_to (count, Qnil);
9f59509498e1 Import from CVS: tag r20-1b10
cvs
parents: 70
diff changeset
230 }
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
231 return closure.accum;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
232 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
233
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
234 struct mark_profiling_info_closure
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
235 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
236 void (*markfun) (Lisp_Object);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
237 };
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
238
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
239 static void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
240 mark_profiling_info_maphash (CONST void *void_key,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
241 void *void_val,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
242 void *void_closure)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
243 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
244 Lisp_Object key;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
245
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
246 CVOID_TO_LISP (key, void_key);
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 149
diff changeset
247 (((struct mark_profiling_info_closure *) void_closure)->markfun) (key);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
248 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
249
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
250 void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
251 mark_profiling_info (void (*markfun) (Lisp_Object))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
252 {
116
9f59509498e1 Import from CVS: tag r20-1b10
cvs
parents: 70
diff changeset
253 /* This function does not GC (if markfun doesn't) */
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
254 struct mark_profiling_info_closure closure;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
255
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
256 closure.markfun = markfun;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
257 if (big_profile_table)
116
9f59509498e1 Import from CVS: tag r20-1b10
cvs
parents: 70
diff changeset
258 {
9f59509498e1 Import from CVS: tag r20-1b10
cvs
parents: 70
diff changeset
259 inside_profiling = 1;
9f59509498e1 Import from CVS: tag r20-1b10
cvs
parents: 70
diff changeset
260 maphash (mark_profiling_info_maphash, big_profile_table, &closure);
9f59509498e1 Import from CVS: tag r20-1b10
cvs
parents: 70
diff changeset
261 inside_profiling = 0;
9f59509498e1 Import from CVS: tag r20-1b10
cvs
parents: 70
diff changeset
262 }
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
263 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
264
199
169c0442b401 Import from CVS: tag r20-3b26
cvs
parents: 185
diff changeset
265 DEFUN ("clear-profiling-info", Fclear_profiling_info, 0, 0, "", /*
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
266 Clear out the recorded profiling info.
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 0
diff changeset
267 */
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 0
diff changeset
268 ())
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
269 {
116
9f59509498e1 Import from CVS: tag r20-1b10
cvs
parents: 70
diff changeset
270 /* This function does not GC */
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
271 if (big_profile_table)
116
9f59509498e1 Import from CVS: tag r20-1b10
cvs
parents: 70
diff changeset
272 {
9f59509498e1 Import from CVS: tag r20-1b10
cvs
parents: 70
diff changeset
273 inside_profiling = 1;
9f59509498e1 Import from CVS: tag r20-1b10
cvs
parents: 70
diff changeset
274 clrhash (big_profile_table);
9f59509498e1 Import from CVS: tag r20-1b10
cvs
parents: 70
diff changeset
275 inside_profiling = 0;
9f59509498e1 Import from CVS: tag r20-1b10
cvs
parents: 70
diff changeset
276 }
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
277 return Qnil;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
278 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
279
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 0
diff changeset
280 DEFUN ("profiling-active-p", Fprofiling_active_p, 0, 0, 0, /*
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
281 Return non-nil if profiling information is currently being recorded.
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 0
diff changeset
282 */
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 0
diff changeset
283 ())
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
284 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
285 return profiling_active ? Qt : Qnil;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
286 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
287
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
288 void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
289 syms_of_profile (void)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
290 {
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 0
diff changeset
291 DEFSUBR (Fstart_profiling);
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 0
diff changeset
292 DEFSUBR (Fstop_profiling);
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 0
diff changeset
293 DEFSUBR (Fget_profiling_info);
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 0
diff changeset
294 DEFSUBR (Fclear_profiling_info);
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 0
diff changeset
295 DEFSUBR (Fprofiling_active_p);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
296 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
297
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
298 void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
299 vars_of_profile (void)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
300 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
301 DEFVAR_INT ("default-profiling-interval", &default_profiling_interval /*
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
302 Default time in microseconds between profiling queries.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
303 Used when the argument to `start-profiling' is nil or omitted.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
304 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
305 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
306 */ );
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
307 default_profiling_interval = 1000;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
308
116
9f59509498e1 Import from CVS: tag r20-1b10
cvs
parents: 70
diff changeset
309 inside_profiling = 0;
9f59509498e1 Import from CVS: tag r20-1b10
cvs
parents: 70
diff changeset
310
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
311 QSin_redisplay = build_string ("(in redisplay)");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
312 staticpro (&QSin_redisplay);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
313 QSin_garbage_collection = build_string ("(in garbage collection)");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
314 staticpro (&QSin_garbage_collection);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
315 QSunknown = build_string ("(unknown)");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
316 staticpro (&QSunknown);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
317 QSprocessing_events_at_top_level =
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
318 build_string ("(processing events at top level)");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
319 staticpro (&QSprocessing_events_at_top_level);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
320 }