annotate src/profile.c @ 1598:ac1be85b4a5f

[xemacs-hg @ 2003-07-31 13:32:24 by crestani] 2003-07-29 Marcus Crestani <crestani@informatik.uni-tuebingen.de> Markus Kaltenbach <makalten@informatik.uni-tuebingen.de> * README.kkcc: Aligned to the changes. * alloc.c: Implemented the kkcc_gc_stack. (kkcc_gc_stack_init): (kkcc_gc_stack_free): (kkcc_gc_stack_realloc): (kkcc_gc_stack_full): (kkcc_gc_stack_empty): (kkcc_gc_stack_push): (kkcc_gc_stack_pop): (kkcc_gc_stack_push_lisp_object): (mark_object_maybe_checking_free): Push objects on kkcc stack instead of marking. (mark_struct_contents): Push objects on kkcc stack instead of marking. (kkcc_marking): KKCC mark algorithm using the kkcc_gc_stack. (mark_object): Removed KKCC ifdefs. (garbage_collect_1): Push objects on kkcc stack instead of marking. * data.c: Added XD_FLAG_NO_KKCC to ephemeron_description and to weak_list_description. * data.c (finish_marking_weak_lists): Push objects on kkcc stack instead of marking. (continue_marking_ephemerons): Push objects on kkcc stack instead of marking. (finish_marking_ephemerons): Push objects on kkcc stack instead of marking. * elhash.c (finish_marking_weak_hash_tables): Push objects on kkcc stack instead of marking. * eval.c: Added XD_FLAG_NO_KKCC to subr_description. * lisp.h: Added prototype for kkcc_gc_stack_push_lisp_object. * profile.c (mark_profiling_info_maphash): Push keys on kkcc stack instead of marking.
author crestani
date Thu, 31 Jul 2003 13:32:26 +0000
parents 01c57eb70ae9
children 04bc9d2f42c7
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1 /* Why the hell is XEmacs so fucking slow?
1292
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
2 Copyright (C) 1996, 2002, 2003 Ben Wing.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3 Copyright (C) 1998 Free Software Foundation, Inc.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5 This file is part of XEmacs.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
7 XEmacs is free software; you can redistribute it and/or modify it
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
8 under the terms of the GNU General Public License as published by the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
9 Free Software Foundation; either version 2, or (at your option) any
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
10 later version.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
11
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
12 XEmacs is distributed in the hope that it will be useful, but WITHOUT
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
15 for more details.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
16
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
17 You should have received a copy of the GNU General Public License
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
18 along with XEmacs; see the file COPYING. If not, write to
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
19 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
20 Boston, MA 02111-1307, USA. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
21
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
22 #include <config.h>
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
23 #include "lisp.h"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
24
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
25 #include "backtrace.h"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
26 #include "bytecode.h"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
27 #include "elhash.h"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
28 #include "hash.h"
1315
70921960b980 [xemacs-hg @ 2003-02-20 08:19:28 by ben]
ben
parents: 1292
diff changeset
29 #include "profile.h"
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
30
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
31 #include "syssignal.h"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
32 #include "systime.h"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
33
611
38db05db9cb5 [xemacs-hg @ 2001-06-08 12:21:09 by ben]
ben
parents: 458
diff changeset
34 #ifndef HAVE_SETITIMER
38db05db9cb5 [xemacs-hg @ 2001-06-08 12:21:09 by ben]
ben
parents: 458
diff changeset
35 #error Sorry charlie. We need a scalpel and all we have is a lawnmower.
38db05db9cb5 [xemacs-hg @ 2001-06-08 12:21:09 by ben]
ben
parents: 458
diff changeset
36 #endif
38db05db9cb5 [xemacs-hg @ 2001-06-08 12:21:09 by ben]
ben
parents: 458
diff changeset
37
1292
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
38 #ifdef WIN32_ANY
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
39 int mswindows_is_blocking;
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
40 #endif
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
41
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
42 /* Written by Ben Wing.
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
43
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
44 We implement our own profiling scheme so that we can determine
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
45 things like which Lisp functions are occupying the most time. Any
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
46 standard OS-provided profiling works on C functions, which is
1292
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
47 not always that useful -- and inconvenient, since it requires compiling
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
48 with profile info and can't be retrieved dynamically, as XEmacs is
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
49 running.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
50
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
51 The basic idea is simple. We set a profiling timer using setitimer
1292
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
52 (ITIMER_PROF), which generates a SIGPROF every so often. (This runs not
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
53 in real time but rather when the process is executing or the system is
1346
01c57eb70ae9 [xemacs-hg @ 2003-03-09 02:27:27 by ben]
ben
parents: 1315
diff changeset
54 running on behalf of the process -- at least, that is the case under
01c57eb70ae9 [xemacs-hg @ 2003-03-09 02:27:27 by ben]
ben
parents: 1315
diff changeset
55 Unix. Under MS Windows and Cygwin, there is no setitimer(), so we
01c57eb70ae9 [xemacs-hg @ 2003-03-09 02:27:27 by ben]
ben
parents: 1315
diff changeset
56 simulate it using multimedia timers, which run in real time. To make
01c57eb70ae9 [xemacs-hg @ 2003-03-09 02:27:27 by ben]
ben
parents: 1315
diff changeset
57 the results a bit more realistic, we ignore ticks that go off while
01c57eb70ae9 [xemacs-hg @ 2003-03-09 02:27:27 by ben]
ben
parents: 1315
diff changeset
58 blocking on an event wait. Note that Cygwin does provide a simulation
01c57eb70ae9 [xemacs-hg @ 2003-03-09 02:27:27 by ben]
ben
parents: 1315
diff changeset
59 of setitimer(), but it's in real time anyway, since Windows doesn't
01c57eb70ae9 [xemacs-hg @ 2003-03-09 02:27:27 by ben]
ben
parents: 1315
diff changeset
60 provide a way to have process-time timers, and furthermore, it's broken,
01c57eb70ae9 [xemacs-hg @ 2003-03-09 02:27:27 by ben]
ben
parents: 1315
diff changeset
61 so we don't use it.) When the signal goes off, we see what we're in, and
01c57eb70ae9 [xemacs-hg @ 2003-03-09 02:27:27 by ben]
ben
parents: 1315
diff changeset
62 add 1 to the count associated with that function.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
63
1292
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
64 It would be nice to use the Lisp allocation mechanism etc. to keep track
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
65 of the profiling information (i.e. to use Lisp hash tables), but we
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
66 can't because that's not safe -- updating the timing information happens
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
67 inside of a signal handler, so we can't rely on not being in the middle
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
68 of Lisp allocation, garbage collection, malloc(), etc. Trying to make
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
69 it work would be much more work than it's worth. Instead we use a basic
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
70 (non-Lisp) hash table, which will not conflict with garbage collection
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
71 or anything else as long as it doesn't try to resize itself. Resizing
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
72 itself, however (which happens as a result of a puthash()), could be
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
73 deadly. To avoid this, we make sure, at points where it's safe
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
74 (e.g. profile_record_about_to_call() -- recording the entry into a
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
75 function call), that the table always has some breathing room in it so
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
76 that no resizes will occur until at least that many items are added.
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
77 This is safe because any new item to be added in the sigprof would
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
78 likely have the profile_record_about_to_call() called just before it,
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
79 and the breathing room is checked.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
80
1292
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
81 In general: any entry that the sigprof handler puts into the table comes
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
82 from a backtrace frame (except "Processing Events at Top Level", and
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
83 there's only one of those). Either that backtrace frame was added when
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
84 profiling was on (in which case profile_record_about_to_call() was
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
85 called and the breathing space updated), or when it was off -- and in
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
86 this case, no such frames can have been added since the last time
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
87 `start-profile' was called, so when `start-profile' is called we make
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
88 sure there is sufficient breathing room to account for all entries
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
89 currently on the stack.
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
90
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
91 Jan 1998: In addition to timing info, I have added code to remember call
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
92 counts of Lisp funcalls. The profile_increase_call_count()
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
93 function is called from Ffuncall(), and serves to add data to
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
94 Vcall_count_profile_table. This mechanism is much simpler and
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
95 independent of the SIGPROF-driven one. It uses the Lisp allocation
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
96 mechanism normally, since it is not called from a handler. It may
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
97 even be useful to provide a way to turn on only one profiling
1292
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
98 mechanism, but I haven't done so yet. --hniksic
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
99
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
100 Dec 2002: Total overhaul of the interface, making it sane and easier to
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
101 use. --ben
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
102
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
103 Feb 2003: Lots of rewriting of the internal code. Add GC-consing-usage,
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
104 total GC usage, and total timing to the information tracked. Track
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
105 profiling overhead and allow the ability to have internal sections
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
106 (e.g. internal-external conversion, byte-char conversion) that are
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
107 treated like Lisp functions for the purpose of profiling. --ben
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
108
1292
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
109 BEWARE: If you are modifying this file, be *very* careful. Correctly
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
110 implementing the "total" values is very tricky due to the possibility of
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
111 recursion and of functions already on the stack when starting to
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
112 profile/still on the stack when stopping.
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
113 */
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
114
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
115 /* We use a plain table here because we're recording inside of a signal
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
116 handler. */
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
117 static struct hash_table *big_profile_table;
1292
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
118 Lisp_Object Vtotal_timing_profile_table;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
119 Lisp_Object Vcall_count_profile_table;
1292
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
120 Lisp_Object Vtotal_gc_usage_profile_table;
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
121 Lisp_Object Vgc_usage_profile_table;
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
122
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
123 extern int lisp_eval_depth;
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
124
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
125 extern EMACS_UINT total_consing;
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
126 static volatile EMACS_UINT total_ticks;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
127
458
c33ae14dd6d0 Import from CVS: tag r21-2-44
cvs
parents: 442
diff changeset
128 Fixnum default_profiling_interval;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
129
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
130 int profiling_active;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
131
1292
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
132 static Lisp_Object QSprocessing_events_at_top_level;
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
133 static Lisp_Object QSunknown, QSprofile_overhead;
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
134
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
135 static Lisp_Object Qtiming, Qtotal_timing, Qcall_count;
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
136 static Lisp_Object Qgc_usage, Qtotal_gc_usage;
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
137
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
138 /* This needs to be >= the total number of defined internal sections,
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
139 plus 1 or 2?? Set it extra big just to be ultra-paranoid. */
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
140 #define EXTRA_BREATHING_ROOM 100
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
141
1292
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
142 /* We use profiling_lock to prevent the signal handler from writing to
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
143 the table while another routine is operating on it. We also set
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
144 profiling_lock in case the timeout between signal calls is short
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
145 enough to catch us while we're already in there. */
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
146 static volatile int profiling_lock;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
147
1292
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
148 /* Whether we're in the process of doing *any* profiling-related stuff.
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
149 Used to indicate amount of time spent profiling. */
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
150 static int in_profiling;
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
151
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
152 #if 0 /* #### for KKCC, eventually */
1123
37bdd24225ef [xemacs-hg @ 2002-11-27 07:15:02 by ben]
ben
parents: 853
diff changeset
153
1292
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
154 static const struct memory_description hentry_description_1[] = {
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
155 { XD_LISP_OBJECT, offsetof (hentry, key) },
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
156 { XD_END }
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
157 };
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
158
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
159 static const struct sized_memory_description hentry_description = {
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
160 sizeof (hentry),
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
161 hentry_description_1
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
162 };
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
163
1292
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
164 static const struct memory_description plain_hash_table_description_1[] = {
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
165 { XD_ELEMCOUNT, offsetof (struct hash_table, size) },
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
166 { XD_STRUCT_PTR, offsetof (struct hash_table, harray), XD_INDIRECT (0, 0),
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
167 &hentry_description },
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
168 { XD_END }
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
169 };
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
170
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
171 static const struct sized_memory_description plain_hash_table_description = {
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
172 sizeof (struct hash_table),
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
173 plain_hash_table_description_1
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
174 };
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
175
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
176 #endif /* 0 */
1123
37bdd24225ef [xemacs-hg @ 2002-11-27 07:15:02 by ben]
ben
parents: 853
diff changeset
177
37bdd24225ef [xemacs-hg @ 2002-11-27 07:15:02 by ben]
ben
parents: 853
diff changeset
178 static void
37bdd24225ef [xemacs-hg @ 2002-11-27 07:15:02 by ben]
ben
parents: 853
diff changeset
179 create_timing_profile_table (void)
37bdd24225ef [xemacs-hg @ 2002-11-27 07:15:02 by ben]
ben
parents: 853
diff changeset
180 {
1292
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
181 /* The hash code can safely be called from a signal handler except when
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
182 it has to grow the hash table. In this case, it calls realloc(),
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
183 which is not (in general) re-entrant. The way we deal with this is
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
184 documented at the top of this file. */
1123
37bdd24225ef [xemacs-hg @ 2002-11-27 07:15:02 by ben]
ben
parents: 853
diff changeset
185 if (!big_profile_table)
1292
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
186 big_profile_table = make_hash_table (2000);
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
187 }
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
188
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
189 static void
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
190 create_profile_tables (void)
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
191 {
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
192 create_timing_profile_table ();
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
193 if (NILP (Vtotal_timing_profile_table))
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
194 Vtotal_timing_profile_table =
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
195 make_lisp_hash_table (100, HASH_TABLE_NON_WEAK, HASH_TABLE_EQ);
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
196 if (NILP (Vcall_count_profile_table))
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
197 Vcall_count_profile_table =
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
198 make_lisp_hash_table (100, HASH_TABLE_NON_WEAK, HASH_TABLE_EQ);
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
199 if (NILP (Vgc_usage_profile_table))
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
200 Vgc_usage_profile_table =
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
201 make_lisp_hash_table (100, HASH_TABLE_NON_WEAK, HASH_TABLE_EQ);
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
202 if (NILP (Vtotal_gc_usage_profile_table))
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
203 Vtotal_gc_usage_profile_table =
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
204 make_lisp_hash_table (100, HASH_TABLE_NON_WEAK, HASH_TABLE_EQ);
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
205 }
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
206
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
207 static Lisp_Object
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
208 current_profile_function (void)
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
209 {
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
210 Lisp_Object fun;
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
211 struct backtrace *bt = backtrace_list;
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
212
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
213 /* 2 because we set in_profiling when we entered the current routine. */
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
214 if (in_profiling >= 2)
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
215 return QSprofile_overhead;
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
216
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
217 /* Find a function actually being called. Potentially (?) there could be
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
218 a number of non-calling funs -- calling foo autoloads, which tries to
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
219 call bar, but requires evalling its args first, which calls baz, ...
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
220 If profiling was not enabled when the function was called, just treat
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
221 the function as actually called, because the info about whether we've
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
222 finished the preamble will not have been recorded. */
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
223 for (; bt && !bt->function_being_called; bt = bt->next)
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
224 ;
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
225
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
226 if (bt)
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
227 {
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
228 fun = *bt->function;
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
229
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
230 if (!SYMBOLP (fun)
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
231 && !COMPILED_FUNCTIONP (fun)
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
232 && !SUBRP (fun)
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
233 && !CONSP (fun)
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
234 && !STRINGP (fun))
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
235 fun = QSunknown;
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
236 }
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
237 else
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
238 fun = QSprocessing_events_at_top_level;
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
239 return fun;
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
240 }
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
241
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
242 void
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
243 profile_record_consing (EMACS_INT size)
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
244 {
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
245 Lisp_Object fun;
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
246 Lisp_Object count;
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
247
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
248 in_profiling++;
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
249 fun = current_profile_function ();
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
250 count = Fgethash (fun, Vgc_usage_profile_table, Qzero);
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
251 Fputhash (fun, make_int (size + XINT (count)), Vgc_usage_profile_table);
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
252 in_profiling--;
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
253 }
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
254
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
255 void
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
256 profile_record_unconsing (EMACS_INT size)
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
257 {
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
258 /* If we don't want to record values less than 0, change this; but then
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
259 the totals won't be accurate. */
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
260 profile_record_consing (-size);
1123
37bdd24225ef [xemacs-hg @ 2002-11-27 07:15:02 by ben]
ben
parents: 853
diff changeset
261 }
37bdd24225ef [xemacs-hg @ 2002-11-27 07:15:02 by ben]
ben
parents: 853
diff changeset
262
1292
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
263 inline static void
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
264 profile_sow_backtrace (struct backtrace *bt)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
265 {
1292
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
266 bt->current_total_timing_val =
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
267 XINT (Fgethash (*bt->function, Vtotal_timing_profile_table, Qzero));
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
268 bt->current_total_gc_usage_val =
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
269 XINT (Fgethash (*bt->function, Vtotal_gc_usage_profile_table, Qzero));
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
270 bt->function_being_called = 1;
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
271 /* Need to think carefully about the exact order of operations here
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
272 so that we don't end up with totals being less than function-only
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
273 values; */
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
274 bt->total_consing_at_start = total_consing;
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
275 /* Order of operation is tricky here because we want the total function
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
276 time to be as close as possible to (and absolutely not less than) the
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
277 function-only time. From the sigprof-handler's perspective, the
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
278 function is "entered" the moment we finish executing the
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
279 in_profiling-- statement below, and ends the moment we finish
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
280 executing the in_profiling++ statement in
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
281 profile_record_just_called(). By recording the tick value as close as
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
282 possible to the "in-function" window but not in it, we satisfy the
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
283 conditions just mentioned. */
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
284 bt->total_ticks_at_start = total_ticks;
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
285 }
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
286
1292
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
287 void
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
288 profile_record_about_to_call (struct backtrace *bt)
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
289 {
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
290 in_profiling++;
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
291 profiling_lock = 1;
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
292 /* See comments in create_timing_profile_table(). */
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
293 pregrow_hash_table_if_necessary (big_profile_table, EXTRA_BREATHING_ROOM);
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
294 profiling_lock = 0;
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
295 Fputhash (*bt->function,
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
296 make_int (1 + XINT (Fgethash (*bt->function,
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
297 Vcall_count_profile_table,
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
298 Qzero))),
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
299 Vcall_count_profile_table);
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
300 /* This may be set if the function was in its preamble at the time that
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
301 `start-profiling' was called. If so, we shouldn't reset the values
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
302 because we may get inconsistent results, since we have already started
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
303 recording ticks and consing for the function. */
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
304 if (!bt->function_being_called)
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
305 profile_sow_backtrace (bt);
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
306 in_profiling--;
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
307 }
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
308
1292
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
309 inline static void
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
310 profile_reap_backtrace (struct backtrace *bt)
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
311 {
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
312 EMACS_UINT ticks;
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
313 /* The following statement *MUST* come directly after the preceding one!
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
314 See the comment above. */
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
315 ticks = total_ticks;
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
316 /* We need to reset the "in-function" flag here. Otherwise the sigprof
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
317 handler will record more ticks for the function while the post-amble
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
318 is executing, and its value will be > our total value. */
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
319 bt->function_being_called = 0;
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
320 Fputhash (*bt->function,
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
321 /* This works even when the total_ticks value has overwrapped.
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
322 Same for total_consing below. */
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
323 make_int ((EMACS_INT) (ticks - bt->total_ticks_at_start)
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
324 + bt->current_total_timing_val),
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
325 Vtotal_timing_profile_table);
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
326 Fputhash (*bt->function,
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
327 make_int ((EMACS_INT)
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
328 (total_consing - bt->total_consing_at_start)
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
329 + bt->current_total_gc_usage_val),
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
330 Vtotal_gc_usage_profile_table);
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
331 }
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
332
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
333 void
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
334 profile_record_just_called (struct backtrace *bt)
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
335 {
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
336 in_profiling++;
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
337 profile_reap_backtrace (bt);
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
338 in_profiling--;
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
339 }
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
340
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
341 /* Called when unwinding the catch stack after a throw or signal, to
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
342 note that we are exiting the function. */
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
343 void
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
344 profile_record_unwind (struct backtrace *bt)
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
345 {
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
346 /* We may have thrown while still in a function's preamble. */
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
347 if (bt->function_being_called)
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
348 profile_record_just_called (bt);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
349 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
350
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
351 static SIGTYPE
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
352 sigprof_handler (int signo)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
353 {
1292
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
354 #ifdef WIN32_ANY
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
355 /* Windows unfortunately does not have any such thing as setitimer
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
356 (ITIMER_PROF, ...), which runs in process time. Everything is real
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
357 time. So to get slightly more reasonable results, ignore completely
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
358 the times when we're blocking. Same applies, of course, to Cygwin. */
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
359 if (mswindows_is_blocking)
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
360 return;
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
361 #endif
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
362
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
363 in_profiling++;
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
364 total_ticks++;
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
365
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
366 /* Don't do anything if we are shutting down, or are doing a maphash
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
367 or clrhash on the table. */
1292
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
368 if (!profiling_lock && !preparing_for_armageddon)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
369 {
1292
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
370 Lisp_Object fun = current_profile_function ();
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
371
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
372 /* If something below causes an error to be signaled, we'll
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
373 not correctly reset this flag. But we'll be in worse shape
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
374 than that anyways, since we'll longjmp back to the last
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
375 condition case. */
1292
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
376 profiling_lock = 1;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
377
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
378 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
379 long count;
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 434
diff changeset
380 const void *vval;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
381
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
382 if (gethash (LISP_TO_VOID (fun), big_profile_table, &vval))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
383 count = (long) vval;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
384 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
385 count = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
386 count++;
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 434
diff changeset
387 vval = (const void *) count;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
388 puthash (LISP_TO_VOID (fun), (void *) vval, big_profile_table);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
389 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
390
1292
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
391 profiling_lock = 0;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
392 }
1292
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
393 in_profiling--;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
394 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
395
1292
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
396 DEFUN ("start-profiling", Fstart_profiling, 0, 1, "", /*
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
397 Start profiling, with profile queries every MICROSECS.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
398 If MICROSECS is nil or omitted, the value of `default-profiling-interval'
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
399 is used.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
400
1123
37bdd24225ef [xemacs-hg @ 2002-11-27 07:15:02 by ben]
ben
parents: 853
diff changeset
401 Information on function timings and call counts is currently recorded.
1292
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
402 You can retrieve the recorded profiling info using `get-profiling-info',
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
403 or the higher-level function `profile-results'.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
404
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
405 Starting and stopping profiling does not clear the currently recorded
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
406 info. Thus you can start and stop as many times as you want and everything
1292
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
407 will be properly accumulated. (To clear, use `clear-profiling-info'.)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
408 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
409 (microsecs))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
410 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
411 /* This function can GC */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
412 int msecs;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
413 struct itimerval foo;
1292
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
414 int depth;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
415
1292
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
416 if (profiling_active)
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
417 return Qnil;
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
418 depth = internal_bind_int (&in_profiling, 1 + in_profiling);
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
419
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
420 create_profile_tables ();
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
421 /* See comments at top of file and in create_timing_profile_table().
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
422 We ensure enough breathing room for all entries currently on the
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
423 stack. */
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
424 pregrow_hash_table_if_necessary (big_profile_table,
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
425 EXTRA_BREATHING_ROOM + lisp_eval_depth);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
426
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
427 if (NILP (microsecs))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
428 msecs = default_profiling_interval;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
429 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
430 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
431 CHECK_NATNUM (microsecs);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
432 msecs = XINT (microsecs);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
433 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
434 if (msecs <= 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
435 msecs = 1000;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
436
613
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 611
diff changeset
437 set_timeout_signal (SIGPROF, sigprof_handler);
1292
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
438 {
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
439 struct backtrace *bt = backtrace_list;
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
440
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
441 /* When we begin profiling, pretend like we just entered all the
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
442 functions currently on the stack. When we stop profiling, do the
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
443 opposite. This ensures consistent values being recorded for both
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
444 function-only and total in such cases. */
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
445 for (; bt; bt = bt->next)
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
446 profile_sow_backtrace (bt);
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
447 }
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
448 profiling_active = 1;
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
449 profiling_lock = 0;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
450 foo.it_value.tv_sec = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
451 foo.it_value.tv_usec = msecs;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
452 EMACS_NORMALIZE_TIME (foo.it_value);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
453 foo.it_interval = foo.it_value;
611
38db05db9cb5 [xemacs-hg @ 2001-06-08 12:21:09 by ben]
ben
parents: 458
diff changeset
454 qxe_setitimer (ITIMER_PROF, &foo, 0);
1292
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
455 unbind_to (depth);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
456 return Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
457 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
458
1292
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
459 DEFUN ("stop-profiling", Fstop_profiling, 0, 0, "", /*
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
460 Stop profiling.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
461 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
462 ())
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
463 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
464 /* This function does not GC */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
465 struct itimerval foo;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
466
1292
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
467 if (!profiling_active)
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
468 return Qnil;
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
469 in_profiling++;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
470 foo.it_value.tv_sec = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
471 foo.it_value.tv_usec = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
472 foo.it_interval = foo.it_value;
611
38db05db9cb5 [xemacs-hg @ 2001-06-08 12:21:09 by ben]
ben
parents: 458
diff changeset
473 qxe_setitimer (ITIMER_PROF, &foo, 0);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
474 profiling_active = 0;
1292
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
475 {
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
476 struct backtrace *bt = backtrace_list;
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
477
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
478 for (; bt; bt = bt->next)
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
479 profile_reap_backtrace (bt);
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
480 }
613
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 611
diff changeset
481 set_timeout_signal (SIGPROF, fatal_error_signal);
1292
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
482 in_profiling--;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
483 return Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
484 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
485
1123
37bdd24225ef [xemacs-hg @ 2002-11-27 07:15:02 by ben]
ben
parents: 853
diff changeset
486 DEFUN ("clear-profiling-info", Fclear_profiling_info, 0, 0, "", /*
37bdd24225ef [xemacs-hg @ 2002-11-27 07:15:02 by ben]
ben
parents: 853
diff changeset
487 Clear out the recorded profiling info.
37bdd24225ef [xemacs-hg @ 2002-11-27 07:15:02 by ben]
ben
parents: 853
diff changeset
488 This clears both the internal timing information and the call counts in
37bdd24225ef [xemacs-hg @ 2002-11-27 07:15:02 by ben]
ben
parents: 853
diff changeset
489 `call-count-profile-table'.
37bdd24225ef [xemacs-hg @ 2002-11-27 07:15:02 by ben]
ben
parents: 853
diff changeset
490 */
37bdd24225ef [xemacs-hg @ 2002-11-27 07:15:02 by ben]
ben
parents: 853
diff changeset
491 ())
37bdd24225ef [xemacs-hg @ 2002-11-27 07:15:02 by ben]
ben
parents: 853
diff changeset
492 {
1292
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
493 in_profiling++;
1123
37bdd24225ef [xemacs-hg @ 2002-11-27 07:15:02 by ben]
ben
parents: 853
diff changeset
494 /* This function does not GC */
37bdd24225ef [xemacs-hg @ 2002-11-27 07:15:02 by ben]
ben
parents: 853
diff changeset
495 if (big_profile_table)
37bdd24225ef [xemacs-hg @ 2002-11-27 07:15:02 by ben]
ben
parents: 853
diff changeset
496 {
1292
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
497 profiling_lock = 1;
1123
37bdd24225ef [xemacs-hg @ 2002-11-27 07:15:02 by ben]
ben
parents: 853
diff changeset
498 clrhash (big_profile_table);
1292
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
499 profiling_lock = 0;
1123
37bdd24225ef [xemacs-hg @ 2002-11-27 07:15:02 by ben]
ben
parents: 853
diff changeset
500 }
1292
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
501 if (!NILP (Vtotal_timing_profile_table))
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
502 Fclrhash (Vtotal_timing_profile_table);
1123
37bdd24225ef [xemacs-hg @ 2002-11-27 07:15:02 by ben]
ben
parents: 853
diff changeset
503 if (!NILP (Vcall_count_profile_table))
37bdd24225ef [xemacs-hg @ 2002-11-27 07:15:02 by ben]
ben
parents: 853
diff changeset
504 Fclrhash (Vcall_count_profile_table);
1292
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
505 if (!NILP (Vgc_usage_profile_table))
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
506 Fclrhash (Vgc_usage_profile_table);
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
507 if (!NILP (Vtotal_gc_usage_profile_table))
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
508 Fclrhash (Vtotal_gc_usage_profile_table);
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
509 in_profiling--;
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
510
1123
37bdd24225ef [xemacs-hg @ 2002-11-27 07:15:02 by ben]
ben
parents: 853
diff changeset
511 return Qnil;
37bdd24225ef [xemacs-hg @ 2002-11-27 07:15:02 by ben]
ben
parents: 853
diff changeset
512 }
37bdd24225ef [xemacs-hg @ 2002-11-27 07:15:02 by ben]
ben
parents: 853
diff changeset
513
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
514 struct get_profiling_info_closure
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
515 {
1123
37bdd24225ef [xemacs-hg @ 2002-11-27 07:15:02 by ben]
ben
parents: 853
diff changeset
516 Lisp_Object timing;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
517 };
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
518
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
519 static int
1123
37bdd24225ef [xemacs-hg @ 2002-11-27 07:15:02 by ben]
ben
parents: 853
diff changeset
520 get_profiling_info_timing_maphash (const void *void_key,
37bdd24225ef [xemacs-hg @ 2002-11-27 07:15:02 by ben]
ben
parents: 853
diff changeset
521 void *void_val,
37bdd24225ef [xemacs-hg @ 2002-11-27 07:15:02 by ben]
ben
parents: 853
diff changeset
522 void *void_closure)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
523 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
524 /* This function does not GC */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
525 Lisp_Object key;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
526 struct get_profiling_info_closure *closure
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
527 = (struct get_profiling_info_closure *) void_closure;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
528 EMACS_INT val;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
529
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 771
diff changeset
530 key = VOID_TO_LISP (void_key);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
531 val = (EMACS_INT) void_val;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
532
1123
37bdd24225ef [xemacs-hg @ 2002-11-27 07:15:02 by ben]
ben
parents: 853
diff changeset
533 Fputhash (key, make_int (val), closure->timing);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
534 return 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
535 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
536
1292
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
537 static Lisp_Object
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
538 copy_hash_table_or_blank (Lisp_Object table)
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
539 {
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
540 return !NILP (table) ? Fcopy_hash_table (table) :
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
541 make_lisp_hash_table (100, HASH_TABLE_NON_WEAK,
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
542 HASH_TABLE_EQ);
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
543 }
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
544
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
545 DEFUN ("get-profiling-info", Fget_profiling_info, 0, 0, 0, /*
1123
37bdd24225ef [xemacs-hg @ 2002-11-27 07:15:02 by ben]
ben
parents: 853
diff changeset
546 Return the currently recorded profiling info.
37bdd24225ef [xemacs-hg @ 2002-11-27 07:15:02 by ben]
ben
parents: 853
diff changeset
547 The format is a plist of symbols describing type of info recorded and
37bdd24225ef [xemacs-hg @ 2002-11-27 07:15:02 by ben]
ben
parents: 853
diff changeset
548 an associated type-specific entry. Currently, the following info types
37bdd24225ef [xemacs-hg @ 2002-11-27 07:15:02 by ben]
ben
parents: 853
diff changeset
549 are recorded
37bdd24225ef [xemacs-hg @ 2002-11-27 07:15:02 by ben]
ben
parents: 853
diff changeset
550
37bdd24225ef [xemacs-hg @ 2002-11-27 07:15:02 by ben]
ben
parents: 853
diff changeset
551 `timing'
1292
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
552 A hash table of function descriptions (funcallable objects or strings
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
553 describing internal processing operations -- redisplay, garbage
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
554 collection, etc.), along with associated tick counts (the frequency of
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
555 ticks is controlled by `default-profiling-interval' or the argument to
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
556 `start-profiling').
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
557
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
558 `total-timing'
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
559 A hash table of function descriptions and associated timing count for
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
560 the function and all descendants.
1123
37bdd24225ef [xemacs-hg @ 2002-11-27 07:15:02 by ben]
ben
parents: 853
diff changeset
561
37bdd24225ef [xemacs-hg @ 2002-11-27 07:15:02 by ben]
ben
parents: 853
diff changeset
562 `call-count'
1292
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
563 A hash table of function descriptions and associated call counts.
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
564
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
565 `gc-usage'
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
566 A hash table of function descriptions and associated amount of consing.
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
567
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
568 `total-gc-usage'
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
569 A hash table of function descriptions and associated amount of consing
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
570 in the function and all descendants.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
571 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
572 ())
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
573 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
574 /* This function does not GC */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
575 struct get_profiling_info_closure closure;
1292
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
576 Lisp_Object retv;
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
577 int depth = internal_bind_int (&in_profiling, 1 + in_profiling);
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
578 const void *overhead;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
579
1123
37bdd24225ef [xemacs-hg @ 2002-11-27 07:15:02 by ben]
ben
parents: 853
diff changeset
580 closure.timing =
37bdd24225ef [xemacs-hg @ 2002-11-27 07:15:02 by ben]
ben
parents: 853
diff changeset
581 make_lisp_hash_table (100, HASH_TABLE_NON_WEAK, HASH_TABLE_EQUAL);
37bdd24225ef [xemacs-hg @ 2002-11-27 07:15:02 by ben]
ben
parents: 853
diff changeset
582
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
583 if (big_profile_table)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
584 {
1292
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
585 int count = internal_bind_int ((int *) &profiling_lock, 1);
1123
37bdd24225ef [xemacs-hg @ 2002-11-27 07:15:02 by ben]
ben
parents: 853
diff changeset
586 maphash (get_profiling_info_timing_maphash, big_profile_table, &closure);
1292
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
587
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
588 /* OK, OK ... the total-timing table is not going to have an entry
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
589 for profile overhead, and it looks strange for it to come out 0,
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
590 so make sure it looks reasonable. */
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
591 if (!gethash (LISP_TO_VOID (QSprofile_overhead), big_profile_table,
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
592 &overhead))
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
593 overhead = 0;
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
594 Fputhash (QSprofile_overhead, make_int ((EMACS_INT) overhead),
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
595 Vtotal_timing_profile_table);
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
596
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 613
diff changeset
597 unbind_to (count);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
598 }
1123
37bdd24225ef [xemacs-hg @ 2002-11-27 07:15:02 by ben]
ben
parents: 853
diff changeset
599
1292
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
600 retv = nconc2 (list6 (Qtiming, closure.timing, Qtotal_timing,
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
601 copy_hash_table_or_blank (Vtotal_timing_profile_table),
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
602 Qcall_count,
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
603 copy_hash_table_or_blank (Vcall_count_profile_table)),
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
604 list4 (Qgc_usage,
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
605 copy_hash_table_or_blank (Vgc_usage_profile_table),
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
606 Qtotal_gc_usage,
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
607 copy_hash_table_or_blank (Vtotal_gc_usage_profile_table
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
608 )));
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
609 unbind_to (depth);
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
610 return retv;
1123
37bdd24225ef [xemacs-hg @ 2002-11-27 07:15:02 by ben]
ben
parents: 853
diff changeset
611 }
37bdd24225ef [xemacs-hg @ 2002-11-27 07:15:02 by ben]
ben
parents: 853
diff changeset
612
37bdd24225ef [xemacs-hg @ 2002-11-27 07:15:02 by ben]
ben
parents: 853
diff changeset
613 static int
37bdd24225ef [xemacs-hg @ 2002-11-27 07:15:02 by ben]
ben
parents: 853
diff changeset
614 set_profiling_info_timing_maphash (Lisp_Object key,
37bdd24225ef [xemacs-hg @ 2002-11-27 07:15:02 by ben]
ben
parents: 853
diff changeset
615 Lisp_Object val,
37bdd24225ef [xemacs-hg @ 2002-11-27 07:15:02 by ben]
ben
parents: 853
diff changeset
616 void *void_closure)
37bdd24225ef [xemacs-hg @ 2002-11-27 07:15:02 by ben]
ben
parents: 853
diff changeset
617 {
37bdd24225ef [xemacs-hg @ 2002-11-27 07:15:02 by ben]
ben
parents: 853
diff changeset
618 /* This function does not GC */
37bdd24225ef [xemacs-hg @ 2002-11-27 07:15:02 by ben]
ben
parents: 853
diff changeset
619 if (!INTP (val))
37bdd24225ef [xemacs-hg @ 2002-11-27 07:15:02 by ben]
ben
parents: 853
diff changeset
620 invalid_argument_2
37bdd24225ef [xemacs-hg @ 2002-11-27 07:15:02 by ben]
ben
parents: 853
diff changeset
621 ("Function timing count is not an integer in given entry",
37bdd24225ef [xemacs-hg @ 2002-11-27 07:15:02 by ben]
ben
parents: 853
diff changeset
622 key, val);
37bdd24225ef [xemacs-hg @ 2002-11-27 07:15:02 by ben]
ben
parents: 853
diff changeset
623
37bdd24225ef [xemacs-hg @ 2002-11-27 07:15:02 by ben]
ben
parents: 853
diff changeset
624 puthash (LISP_TO_VOID (key), (void *) XINT (val), big_profile_table);
37bdd24225ef [xemacs-hg @ 2002-11-27 07:15:02 by ben]
ben
parents: 853
diff changeset
625
37bdd24225ef [xemacs-hg @ 2002-11-27 07:15:02 by ben]
ben
parents: 853
diff changeset
626 return 0;
37bdd24225ef [xemacs-hg @ 2002-11-27 07:15:02 by ben]
ben
parents: 853
diff changeset
627 }
37bdd24225ef [xemacs-hg @ 2002-11-27 07:15:02 by ben]
ben
parents: 853
diff changeset
628
37bdd24225ef [xemacs-hg @ 2002-11-27 07:15:02 by ben]
ben
parents: 853
diff changeset
629 DEFUN ("set-profiling-info", Fset_profiling_info, 1, 1, 0, /*
37bdd24225ef [xemacs-hg @ 2002-11-27 07:15:02 by ben]
ben
parents: 853
diff changeset
630 Set the currently recorded profiling info.
37bdd24225ef [xemacs-hg @ 2002-11-27 07:15:02 by ben]
ben
parents: 853
diff changeset
631 INFO should be in the same format returned by `get-profiling-info',
37bdd24225ef [xemacs-hg @ 2002-11-27 07:15:02 by ben]
ben
parents: 853
diff changeset
632 as described there.
37bdd24225ef [xemacs-hg @ 2002-11-27 07:15:02 by ben]
ben
parents: 853
diff changeset
633 */
37bdd24225ef [xemacs-hg @ 2002-11-27 07:15:02 by ben]
ben
parents: 853
diff changeset
634 (info))
37bdd24225ef [xemacs-hg @ 2002-11-27 07:15:02 by ben]
ben
parents: 853
diff changeset
635 {
1292
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
636 int depth;
1123
37bdd24225ef [xemacs-hg @ 2002-11-27 07:15:02 by ben]
ben
parents: 853
diff changeset
637 /* This function does not GC */
37bdd24225ef [xemacs-hg @ 2002-11-27 07:15:02 by ben]
ben
parents: 853
diff changeset
638 Fclear_profiling_info ();
37bdd24225ef [xemacs-hg @ 2002-11-27 07:15:02 by ben]
ben
parents: 853
diff changeset
639
1292
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
640 depth = internal_bind_int (&in_profiling, 1 + in_profiling);
1123
37bdd24225ef [xemacs-hg @ 2002-11-27 07:15:02 by ben]
ben
parents: 853
diff changeset
641 {
37bdd24225ef [xemacs-hg @ 2002-11-27 07:15:02 by ben]
ben
parents: 853
diff changeset
642 EXTERNAL_PROPERTY_LIST_LOOP_3 (key, value, info)
37bdd24225ef [xemacs-hg @ 2002-11-27 07:15:02 by ben]
ben
parents: 853
diff changeset
643 {
37bdd24225ef [xemacs-hg @ 2002-11-27 07:15:02 by ben]
ben
parents: 853
diff changeset
644 if (EQ (key, Qtiming))
37bdd24225ef [xemacs-hg @ 2002-11-27 07:15:02 by ben]
ben
parents: 853
diff changeset
645 {
37bdd24225ef [xemacs-hg @ 2002-11-27 07:15:02 by ben]
ben
parents: 853
diff changeset
646 CHECK_HASH_TABLE (value);
37bdd24225ef [xemacs-hg @ 2002-11-27 07:15:02 by ben]
ben
parents: 853
diff changeset
647 create_timing_profile_table ();
1292
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
648 profiling_lock = 1;
1123
37bdd24225ef [xemacs-hg @ 2002-11-27 07:15:02 by ben]
ben
parents: 853
diff changeset
649 elisp_maphash_unsafe (set_profiling_info_timing_maphash, value,
37bdd24225ef [xemacs-hg @ 2002-11-27 07:15:02 by ben]
ben
parents: 853
diff changeset
650 NULL);
1292
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
651 profiling_lock = 0;
1123
37bdd24225ef [xemacs-hg @ 2002-11-27 07:15:02 by ben]
ben
parents: 853
diff changeset
652 }
37bdd24225ef [xemacs-hg @ 2002-11-27 07:15:02 by ben]
ben
parents: 853
diff changeset
653 else if (EQ (key, Qcall_count))
1292
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
654 Vcall_count_profile_table = Fcopy_hash_table (value);
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
655 else if (EQ (key, Qtotal_timing))
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
656 Vtotal_timing_profile_table = Fcopy_hash_table (value);
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
657 else if (EQ (key, Qgc_usage))
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
658 Vgc_usage_profile_table = Fcopy_hash_table (value);
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
659 else if (EQ (key, Qtotal_gc_usage))
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
660 Vtotal_gc_usage_profile_table = Fcopy_hash_table (value);
1123
37bdd24225ef [xemacs-hg @ 2002-11-27 07:15:02 by ben]
ben
parents: 853
diff changeset
661 else
37bdd24225ef [xemacs-hg @ 2002-11-27 07:15:02 by ben]
ben
parents: 853
diff changeset
662 invalid_constant ("Unrecognized profiling-info keyword", key);
37bdd24225ef [xemacs-hg @ 2002-11-27 07:15:02 by ben]
ben
parents: 853
diff changeset
663 }
37bdd24225ef [xemacs-hg @ 2002-11-27 07:15:02 by ben]
ben
parents: 853
diff changeset
664 }
37bdd24225ef [xemacs-hg @ 2002-11-27 07:15:02 by ben]
ben
parents: 853
diff changeset
665
1292
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
666 unbind_to (depth);
1123
37bdd24225ef [xemacs-hg @ 2002-11-27 07:15:02 by ben]
ben
parents: 853
diff changeset
667 return Qnil;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
668 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
669
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
670 static int
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 434
diff changeset
671 mark_profiling_info_maphash (const void *void_key,
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
672 void *void_val,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
673 void *void_closure)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
674 {
1598
ac1be85b4a5f [xemacs-hg @ 2003-07-31 13:32:24 by crestani]
crestani
parents: 1346
diff changeset
675 #ifdef USE_KKCC
ac1be85b4a5f [xemacs-hg @ 2003-07-31 13:32:24 by crestani]
crestani
parents: 1346
diff changeset
676 kkcc_gc_stack_push_lisp_object (VOID_TO_LISP (void_key));
ac1be85b4a5f [xemacs-hg @ 2003-07-31 13:32:24 by crestani]
crestani
parents: 1346
diff changeset
677 #else /* NOT USE_KKCC */
1292
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
678 mark_object (VOID_TO_LISP (void_key));
1598
ac1be85b4a5f [xemacs-hg @ 2003-07-31 13:32:24 by crestani]
crestani
parents: 1346
diff changeset
679 #endif /* NOT USE_KKCC */
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
680 return 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
681 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
682
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
683 void
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
684 mark_profiling_info (void)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
685 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
686 /* This function does not GC */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
687 if (big_profile_table)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
688 {
1292
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
689 profiling_lock = 1;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
690 maphash (mark_profiling_info_maphash, big_profile_table, 0);
1292
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
691 profiling_lock = 0;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
692 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
693 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
694
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
695 DEFUN ("profiling-active-p", Fprofiling_active_p, 0, 0, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
696 Return non-nil if profiling information is currently being recorded.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
697 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
698 ())
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
699 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
700 return profiling_active ? Qt : Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
701 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
702
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
703 void
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
704 syms_of_profile (void)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
705 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
706 DEFSUBR (Fstart_profiling);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
707 DEFSUBR (Fstop_profiling);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
708 DEFSUBR (Fget_profiling_info);
1123
37bdd24225ef [xemacs-hg @ 2002-11-27 07:15:02 by ben]
ben
parents: 853
diff changeset
709 DEFSUBR (Fset_profiling_info);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
710 DEFSUBR (Fclear_profiling_info);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
711 DEFSUBR (Fprofiling_active_p);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
712 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
713
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
714 void
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
715 vars_of_profile (void)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
716 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
717 DEFVAR_INT ("default-profiling-interval", &default_profiling_interval /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
718 Default CPU time in microseconds between profiling sampling.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
719 Used when the argument to `start-profiling' is nil or omitted.
1346
01c57eb70ae9 [xemacs-hg @ 2003-03-09 02:27:27 by ben]
ben
parents: 1315
diff changeset
720 Under Unix, the time in question is CPU time (when the program is executing
01c57eb70ae9 [xemacs-hg @ 2003-03-09 02:27:27 by ben]
ben
parents: 1315
diff changeset
721 or the kernel is executing on behalf of the program) and not real time.
01c57eb70ae9 [xemacs-hg @ 2003-03-09 02:27:27 by ben]
ben
parents: 1315
diff changeset
722 Under MS Windows and Cygwin, the time is real time, but time spent blocking
01c57eb70ae9 [xemacs-hg @ 2003-03-09 02:27:27 by ben]
ben
parents: 1315
diff changeset
723 while waiting for an event is ignored, to get more accurate results.
01c57eb70ae9 [xemacs-hg @ 2003-03-09 02:27:27 by ben]
ben
parents: 1315
diff changeset
724 Note that there is usually a machine-dependent limit on how small this
01c57eb70ae9 [xemacs-hg @ 2003-03-09 02:27:27 by ben]
ben
parents: 1315
diff changeset
725 value can be.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
726 */ );
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
727 default_profiling_interval = 1000;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
728
1123
37bdd24225ef [xemacs-hg @ 2002-11-27 07:15:02 by ben]
ben
parents: 853
diff changeset
729 staticpro (&Vcall_count_profile_table);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
730 Vcall_count_profile_table = Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
731
1292
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
732 staticpro (&Vgc_usage_profile_table);
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
733 Vgc_usage_profile_table = Qnil;
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
734
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
735 staticpro (&Vtotal_gc_usage_profile_table);
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
736 Vtotal_gc_usage_profile_table = Qnil;
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
737
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
738 staticpro (&Vtotal_timing_profile_table);
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
739 Vtotal_timing_profile_table = Qnil;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
740
1292
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
741 #if 0
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
742 /* #### This is supposed to be for KKCC but KKCC doesn't use this stuff
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
743 currently. */
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
744 dump_add_root_struct_ptr (&big_profile_table, &plain_hash_table_description);
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
745 #endif /* 0 */
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
746
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
747 profiling_lock = 0;
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
748
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 613
diff changeset
749 QSunknown = build_msg_string ("(unknown)");
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
750 staticpro (&QSunknown);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
751 QSprocessing_events_at_top_level =
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 613
diff changeset
752 build_msg_string ("(processing events at top level)");
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
753 staticpro (&QSprocessing_events_at_top_level);
1292
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
754 QSprofile_overhead = build_msg_string ("(profile overhead)");
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
755 staticpro (&QSprofile_overhead);
1123
37bdd24225ef [xemacs-hg @ 2002-11-27 07:15:02 by ben]
ben
parents: 853
diff changeset
756
37bdd24225ef [xemacs-hg @ 2002-11-27 07:15:02 by ben]
ben
parents: 853
diff changeset
757 DEFSYMBOL (Qtiming);
1292
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
758 DEFSYMBOL (Qtotal_timing);
1123
37bdd24225ef [xemacs-hg @ 2002-11-27 07:15:02 by ben]
ben
parents: 853
diff changeset
759 DEFSYMBOL (Qcall_count);
1292
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
760 DEFSYMBOL (Qgc_usage);
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
761 DEFSYMBOL (Qtotal_gc_usage);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
762 }