annotate src/profile.c @ 0:376386a54a3c r19-14

Import from CVS: tag r19-14
author cvs
date Mon, 13 Aug 2007 08:45:50 +0200
parents
children 859a2309aef8
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
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
66 static SIGTYPE
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
67 sigprof_handler (int signo)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
68 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
69 Lisp_Object fun;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
70
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
71 if (profiling_redisplay_flag)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
72 fun = QSin_redisplay;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
73 else if (gc_in_progress)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
74 fun = QSin_garbage_collection;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
75 else if (backtrace_list)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
76 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
77 fun = *backtrace_list->function;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
78
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
79 XUNMARK (fun);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
80 if (!GC_SYMBOLP (fun) && !GC_COMPILED_FUNCTIONP (fun))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
81 fun = QSunknown;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
82 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
83 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
84 fun = QSprocessing_events_at_top_level;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
85
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
86 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
87 long count;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
88 CONST void *vval;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
89
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
90 if (gethash (LISP_TO_VOID (fun), big_profile_table, &vval))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
91 count = (long) vval;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
92 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
93 count = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
94 count++;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
95 vval = (CONST void *) count;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
96 puthash (LISP_TO_VOID (fun), (void *) vval, big_profile_table);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
97 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
98 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
99
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
100 DEFUN ("start-profiling", Fstart_profiling, Sstart_profiling, 0, 1, 0 /*
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
101 Start profiling, with profile queries every MICROSECS.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
102 If MICROSECS is nil or omitted, the value of `default-profiling-interval'
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
103 is used.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
104
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
105 You can retrieve the recorded profiling info using `get-profiling-info'.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
106
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
107 Starting and stopping profiling does not clear the currently recorded
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
108 info. Thus you can start and stop as many times as you want and everything
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
109 will be properly accumulated.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
110 */ )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
111 (microsecs)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
112 Lisp_Object microsecs;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
113 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
114 int msecs;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
115 struct itimerval foo;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
116
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
117 /* #### The hash code can safely be called from a signal handler
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
118 except when it has to grow the hashtable. In this case, it calls
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
119 realloc(), which is not (in general) re-entrant. We just be
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
120 sleazy and make the table large enough that it (hopefully) won't
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
121 need to be realloc()ed. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
122 if (!big_profile_table)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
123 big_profile_table = make_hashtable (10000);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
124 if (NILP (microsecs))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
125 msecs = default_profiling_interval;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
126 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
127 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
128 CHECK_NATNUM (microsecs);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
129 msecs = XINT (microsecs);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
130 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
131 if (msecs <= 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
132 msecs = 1000;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
133
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
134 signal (SIGPROF, sigprof_handler);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
135 foo.it_value.tv_sec = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
136 foo.it_value.tv_usec = msecs;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
137 EMACS_NORMALIZE_TIME (foo.it_value);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
138 foo.it_interval = foo.it_value;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
139 profiling_active = 1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
140 setitimer (ITIMER_PROF, &foo, 0);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
141 return Qnil;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
142 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
143
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
144 DEFUN ("stop-profiling", Fstop_profiling, Sstop_profiling, 0, 0, 0 /*
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
145 Stop profiling.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
146 */ )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
147 ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
148 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
149 struct itimerval foo;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
150
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
151 foo.it_value.tv_sec = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
152 foo.it_value.tv_usec = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
153 foo.it_interval = foo.it_value;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
154 setitimer (ITIMER_PROF, &foo, 0);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
155 profiling_active = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
156 signal (SIGPROF, fatal_error_signal);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
157 return Qnil;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
158 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
159
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
160 struct get_profiling_info_closure
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
161 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
162 Lisp_Object accum;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
163 };
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
164
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
165 static void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
166 get_profiling_info_maphash (CONST void *void_key,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
167 void *void_val,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
168 void *void_closure)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
169 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
170 /* This function can GC */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
171 Lisp_Object key;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
172 struct get_profiling_info_closure *closure = void_closure;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
173 EMACS_INT val;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
174
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
175 CVOID_TO_LISP (key, void_key);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
176 val = (EMACS_INT) void_val;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
177
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
178 closure->accum = Fcons (Fcons (key, make_int (val)),
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
179 closure->accum);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
180 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
181
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
182 DEFUN ("get-profiling-info", Fget_profiling_info, Sget_profiling_info,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
183 0, 0, 0 /*
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
184 Return the profiling info as an alist.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
185 */ )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
186 ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
187 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
188 struct get_profiling_info_closure closure;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
189
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
190 closure.accum = Qnil;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
191 if (big_profile_table)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
192 maphash (get_profiling_info_maphash, big_profile_table, &closure);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
193 return closure.accum;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
194 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
195
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
196 struct mark_profiling_info_closure
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
197 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
198 void (*markfun) (Lisp_Object);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
199 };
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
200
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
201 static void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
202 mark_profiling_info_maphash (CONST void *void_key,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
203 void *void_val,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
204 void *void_closure)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
205 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
206 /* This function can GC */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
207 Lisp_Object key;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
208 struct mark_profiling_info_closure *closure = void_closure;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
209
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
210 CVOID_TO_LISP (key, void_key);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
211 (closure->markfun) (key);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
212 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
213
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
214 void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
215 mark_profiling_info (void (*markfun) (Lisp_Object))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
216 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
217 struct mark_profiling_info_closure closure;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
218
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
219 closure.markfun = markfun;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
220 if (big_profile_table)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
221 maphash (mark_profiling_info_maphash, big_profile_table, &closure);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
222 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
223
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
224 DEFUN ("clear-profiling-info", Fclear_profiling_info, Sclear_profiling_info,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
225 0, 0, 0 /*
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
226 Clear out the recorded profiling info.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
227 */ )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
228 ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
229 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
230 if (big_profile_table)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
231 clrhash (big_profile_table);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
232 return Qnil;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
233 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
234
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
235 DEFUN ("profiling-active-p", Fprofiling_active_p, Sprofiling_active_p,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
236 0, 0, 0 /*
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
237 Return non-nil if profiling information is currently being recorded.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
238 */ )
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 return profiling_active ? Qt : Qnil;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
242 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
243
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
244 void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
245 syms_of_profile (void)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
246 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
247 defsubr (&Sstart_profiling);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
248 defsubr (&Sstop_profiling);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
249 defsubr (&Sget_profiling_info);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
250 defsubr (&Sclear_profiling_info);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
251 defsubr (&Sprofiling_active_p);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
252 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
253
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
254 void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
255 vars_of_profile (void)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
256 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
257 DEFVAR_INT ("default-profiling-interval", &default_profiling_interval /*
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
258 Default time in microseconds between profiling queries.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
259 Used when the argument to `start-profiling' is nil or omitted.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
260 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
261 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
262 */ );
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
263 default_profiling_interval = 1000;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
264
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
265 QSin_redisplay = build_string ("(in redisplay)");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
266 staticpro (&QSin_redisplay);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
267 QSin_garbage_collection = build_string ("(in garbage collection)");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
268 staticpro (&QSin_garbage_collection);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
269 QSunknown = build_string ("(unknown)");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
270 staticpro (&QSunknown);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
271 QSprocessing_events_at_top_level =
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
272 build_string ("(processing events at top level)");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
273 staticpro (&QSprocessing_events_at_top_level);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
274 }