annotate src/profile.c @ 199:169c0442b401 r20-3b26

Import from CVS: tag r20-3b26
author cvs
date Mon, 13 Aug 2007 10:00:33 +0200
parents 3d6bfa290dbd
children e45d5e7c476e
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 /* #### dmoore - why do we need to unmark it, we aren't in GC. */
9f59509498e1 Import from CVS: tag r20-1b10
cvs
parents: 70
diff changeset
96 XUNMARK (fun);
9f59509498e1 Import from CVS: tag r20-1b10
cvs
parents: 70
diff changeset
97 if (!GC_SYMBOLP (fun) && !GC_COMPILED_FUNCTIONP (fun))
9f59509498e1 Import from CVS: tag r20-1b10
cvs
parents: 70
diff changeset
98 fun = QSunknown;
9f59509498e1 Import from CVS: tag r20-1b10
cvs
parents: 70
diff changeset
99 }
9f59509498e1 Import from CVS: tag r20-1b10
cvs
parents: 70
diff changeset
100 else
9f59509498e1 Import from CVS: tag r20-1b10
cvs
parents: 70
diff changeset
101 fun = QSprocessing_events_at_top_level;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
102
116
9f59509498e1 Import from CVS: tag r20-1b10
cvs
parents: 70
diff changeset
103 {
9f59509498e1 Import from CVS: tag r20-1b10
cvs
parents: 70
diff changeset
104 /* #### see comment about memory allocation in start-profiling.
9f59509498e1 Import from CVS: tag r20-1b10
cvs
parents: 70
diff changeset
105 Allocating memory in a signal handler is BAD BAD BAD.
9f59509498e1 Import from CVS: tag r20-1b10
cvs
parents: 70
diff changeset
106 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
107 lose because of this. Even worse, if the memory allocation
116
9f59509498e1 Import from CVS: tag r20-1b10
cvs
parents: 70
diff changeset
108 fails, the `error' generated whacks everything hard. */
9f59509498e1 Import from CVS: tag r20-1b10
cvs
parents: 70
diff changeset
109 long count;
9f59509498e1 Import from CVS: tag r20-1b10
cvs
parents: 70
diff changeset
110 CONST void *vval;
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 149
diff changeset
111
116
9f59509498e1 Import from CVS: tag r20-1b10
cvs
parents: 70
diff changeset
112 if (gethash (LISP_TO_VOID (fun), big_profile_table, &vval))
9f59509498e1 Import from CVS: tag r20-1b10
cvs
parents: 70
diff changeset
113 count = (long) vval;
9f59509498e1 Import from CVS: tag r20-1b10
cvs
parents: 70
diff changeset
114 else
9f59509498e1 Import from CVS: tag r20-1b10
cvs
parents: 70
diff changeset
115 count = 0;
9f59509498e1 Import from CVS: tag r20-1b10
cvs
parents: 70
diff changeset
116 count++;
9f59509498e1 Import from CVS: tag r20-1b10
cvs
parents: 70
diff changeset
117 vval = (CONST void *) count;
9f59509498e1 Import from CVS: tag r20-1b10
cvs
parents: 70
diff changeset
118 puthash (LISP_TO_VOID (fun), (void *) vval, big_profile_table);
9f59509498e1 Import from CVS: tag r20-1b10
cvs
parents: 70
diff changeset
119 }
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 149
diff changeset
120
116
9f59509498e1 Import from CVS: tag r20-1b10
cvs
parents: 70
diff changeset
121 inside_profiling = 0;
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 56
diff changeset
122 }
0
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 {
116
9f59509498e1 Import from CVS: tag r20-1b10
cvs
parents: 70
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;
116
9f59509498e1 Import from CVS: tag r20-1b10
cvs
parents: 70
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 {
116
9f59509498e1 Import from CVS: tag r20-1b10
cvs
parents: 70
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
116
9f59509498e1 Import from CVS: tag r20-1b10
cvs
parents: 70
diff changeset
187 static Lisp_Object
9f59509498e1 Import from CVS: tag r20-1b10
cvs
parents: 70
diff changeset
188 profile_lock_unwind (Lisp_Object ignore)
9f59509498e1 Import from CVS: tag r20-1b10
cvs
parents: 70
diff changeset
189 {
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 149
diff changeset
190 inside_profiling = 0;
116
9f59509498e1 Import from CVS: tag r20-1b10
cvs
parents: 70
diff changeset
191 return Qnil;
9f59509498e1 Import from CVS: tag r20-1b10
cvs
parents: 70
diff changeset
192 }
9f59509498e1 Import from CVS: tag r20-1b10
cvs
parents: 70
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 {
116
9f59509498e1 Import from CVS: tag r20-1b10
cvs
parents: 70
diff changeset
204 /* This function does not GC */
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
205 Lisp_Object key;
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 149
diff changeset
206 struct get_profiling_info_closure *closure
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 149
diff changeset
207 = (struct get_profiling_info_closure *) void_closure;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
208 EMACS_INT val;
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 val = (EMACS_INT) void_val;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
212
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 149
diff changeset
213 closure->accum = Fcons (Fcons (key, make_int (val)), closure->accum);
0
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 {
116
9f59509498e1 Import from CVS: tag r20-1b10
cvs
parents: 70
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)
116
9f59509498e1 Import from CVS: tag r20-1b10
cvs
parents: 70
diff changeset
226 {
9f59509498e1 Import from CVS: tag r20-1b10
cvs
parents: 70
diff changeset
227 int count = specpdl_depth ();
9f59509498e1 Import from CVS: tag r20-1b10
cvs
parents: 70
diff changeset
228 record_unwind_protect (profile_lock_unwind, Qnil);
9f59509498e1 Import from CVS: tag r20-1b10
cvs
parents: 70
diff changeset
229 inside_profiling = 1;
9f59509498e1 Import from CVS: tag r20-1b10
cvs
parents: 70
diff changeset
230 maphash (get_profiling_info_maphash, big_profile_table, &closure);
9f59509498e1 Import from CVS: tag r20-1b10
cvs
parents: 70
diff changeset
231 unbind_to (count, Qnil);
9f59509498e1 Import from CVS: tag r20-1b10
cvs
parents: 70
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
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
248 CVOID_TO_LISP (key, void_key);
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 149
diff changeset
249 (((struct mark_profiling_info_closure *) void_closure)->markfun) (key);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
250 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
251
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
252 void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
253 mark_profiling_info (void (*markfun) (Lisp_Object))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
254 {
116
9f59509498e1 Import from CVS: tag r20-1b10
cvs
parents: 70
diff changeset
255 /* This function does not GC (if markfun doesn't) */
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
256 struct mark_profiling_info_closure closure;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
257
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
258 closure.markfun = markfun;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
259 if (big_profile_table)
116
9f59509498e1 Import from CVS: tag r20-1b10
cvs
parents: 70
diff changeset
260 {
9f59509498e1 Import from CVS: tag r20-1b10
cvs
parents: 70
diff changeset
261 inside_profiling = 1;
9f59509498e1 Import from CVS: tag r20-1b10
cvs
parents: 70
diff changeset
262 maphash (mark_profiling_info_maphash, big_profile_table, &closure);
9f59509498e1 Import from CVS: tag r20-1b10
cvs
parents: 70
diff changeset
263 inside_profiling = 0;
9f59509498e1 Import from CVS: tag r20-1b10
cvs
parents: 70
diff changeset
264 }
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
265 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
266
199
169c0442b401 Import from CVS: tag r20-3b26
cvs
parents: 185
diff changeset
267 DEFUN ("clear-profiling-info", Fclear_profiling_info, 0, 0, "", /*
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
268 Clear out the recorded profiling info.
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 0
diff changeset
269 */
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 0
diff changeset
270 ())
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
271 {
116
9f59509498e1 Import from CVS: tag r20-1b10
cvs
parents: 70
diff changeset
272 /* This function does not GC */
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
273 if (big_profile_table)
116
9f59509498e1 Import from CVS: tag r20-1b10
cvs
parents: 70
diff changeset
274 {
9f59509498e1 Import from CVS: tag r20-1b10
cvs
parents: 70
diff changeset
275 inside_profiling = 1;
9f59509498e1 Import from CVS: tag r20-1b10
cvs
parents: 70
diff changeset
276 clrhash (big_profile_table);
9f59509498e1 Import from CVS: tag r20-1b10
cvs
parents: 70
diff changeset
277 inside_profiling = 0;
9f59509498e1 Import from CVS: tag r20-1b10
cvs
parents: 70
diff changeset
278 }
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
279 return Qnil;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
280 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
281
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 0
diff changeset
282 DEFUN ("profiling-active-p", Fprofiling_active_p, 0, 0, 0, /*
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
283 Return non-nil if profiling information is currently being recorded.
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 0
diff changeset
284 */
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 0
diff changeset
285 ())
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
286 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
287 return profiling_active ? Qt : Qnil;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
288 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
289
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
290 void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
291 syms_of_profile (void)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
292 {
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 0
diff changeset
293 DEFSUBR (Fstart_profiling);
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 0
diff changeset
294 DEFSUBR (Fstop_profiling);
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 0
diff changeset
295 DEFSUBR (Fget_profiling_info);
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 0
diff changeset
296 DEFSUBR (Fclear_profiling_info);
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 0
diff changeset
297 DEFSUBR (Fprofiling_active_p);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
298 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
299
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
300 void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
301 vars_of_profile (void)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
302 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
303 DEFVAR_INT ("default-profiling-interval", &default_profiling_interval /*
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
304 Default time in microseconds between profiling queries.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
305 Used when the argument to `start-profiling' is nil or omitted.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
306 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
307 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
308 */ );
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
309 default_profiling_interval = 1000;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
310
116
9f59509498e1 Import from CVS: tag r20-1b10
cvs
parents: 70
diff changeset
311 inside_profiling = 0;
9f59509498e1 Import from CVS: tag r20-1b10
cvs
parents: 70
diff changeset
312
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
313 QSin_redisplay = build_string ("(in redisplay)");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
314 staticpro (&QSin_redisplay);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
315 QSin_garbage_collection = build_string ("(in garbage collection)");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
316 staticpro (&QSin_garbage_collection);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
317 QSunknown = build_string ("(unknown)");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
318 staticpro (&QSunknown);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
319 QSprocessing_events_at_top_level =
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
320 build_string ("(processing events at top level)");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
321 staticpro (&QSprocessing_events_at_top_level);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
322 }