annotate src/profile.c @ 90:99da576a67e7 xemacs-20-0

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