annotate src/profile.c @ 5307:c096d8051f89

Have NATNUMP give t for positive bignums; check limits appropriately. src/ChangeLog addition: 2010-11-20 Aidan Kehoe <kehoea@parhasard.net> * abbrev.c (Fexpand_abbrev): * alloc.c: * alloc.c (Fmake_list): * alloc.c (Fmake_vector): * alloc.c (Fmake_bit_vector): * alloc.c (Fmake_byte_code): * alloc.c (Fmake_string): * alloc.c (vars_of_alloc): * bytecode.c (UNUSED): * bytecode.c (Fbyte_code): * chartab.c (decode_char_table_range): * cmds.c (Fself_insert_command): * data.c (check_integer_range): * data.c (Fnatnump): * data.c (Fnonnegativep): * data.c (Fstring_to_number): * elhash.c (hash_table_size_validate): * elhash.c (decode_hash_table_size): * eval.c (Fbacktrace_frame): * event-stream.c (lisp_number_to_milliseconds): * event-stream.c (Faccept_process_output): * event-stream.c (Frecent_keys): * event-stream.c (Fdispatch_event): * events.c (Fmake_event): * events.c (Fevent_timestamp): * events.c (Fevent_timestamp_lessp): * events.h: * events.h (struct command_builder): * file-coding.c (gzip_putprop): * fns.c: * fns.c (check_sequence_range): * fns.c (Frandom): * fns.c (Fnthcdr): * fns.c (Flast): * fns.c (Fnbutlast): * fns.c (Fbutlast): * fns.c (Fmember): * fns.c (Ffill): * fns.c (Freduce): * fns.c (replace_string_range_1): * fns.c (Freplace): * font-mgr.c (Ffc_pattern_get): * frame-msw.c (msprinter_set_frame_properties): * glyphs.c (check_valid_xbm_inline): * indent.c (Fmove_to_column): * intl-win32.c (mswindows_multibyte_to_unicode_putprop): * lisp.h: * lisp.h (ARRAY_DIMENSION_LIMIT): * lread.c (decode_mode_1): * mule-ccl.c (ccl_get_compiled_code): * number.h: * process-unix.c (unix_open_multicast_group): * process.c (Fset_process_window_size): * profile.c (Fstart_profiling): * unicode.c (Funicode_to_char): Change NATNUMP to return 1 for positive bignums; changes uses of it and of CHECK_NATNUM appropriately, usually by checking for an integer in an appropriate range. Add array-dimension-limit and use it in #'make-vector, #'make-string. Add array-total-size-limit, array-rank-limit while we're at it, for the sake of any Common Lisp-oriented code that uses these limits. Rename check_int_range to check_integer_range, have it take Lisp_Objects (and thus bignums) instead. Remove bignum_butlast(), just set int_n to an appropriately large integer if N is a bignum. Accept bignums in check_sequence_range(), change the functions that use check_sequence_range() appropriately. Move the definition of NATNUMP() to number.h; document why it's a reasonable name, contradicting an old comment. tests/ChangeLog addition: 2010-11-20 Aidan Kehoe <kehoea@parhasard.net> * automated/lisp-tests.el: * automated/lisp-tests.el (featurep): * automated/lisp-tests.el (wrong-type-argument): * automated/mule-tests.el (featurep): Check for args-out-of-range errors instead of wrong-type-argument errors in various places when code is handed a large bignum instead of a fixnum. Also check for the wrong-type-argument errors when giving the same code a non-integer value.
author Aidan Kehoe <kehoea@parhasard.net>
date Sat, 20 Nov 2010 16:49:11 +0000
parents 71ee43b8a74d
children db326b8fe982 8d29f1c4bb98
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?
5169
6c6d78781d59 cleanup of code related to xfree(), better KKCC backtrace capabilities, document XD_INLINE_LISP_OBJECT_BLOCK_PTR, fix some memory leaks, other code cleanup
Ben Wing <ben@xemacs.org>
parents: 5038
diff changeset
2 Copyright (C) 1996, 2002, 2003, 2004, 2010 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"
5169
6c6d78781d59 cleanup of code related to xfree(), better KKCC backtrace capabilities, document XD_INLINE_LISP_OBJECT_BLOCK_PTR, fix some memory leaks, other code cleanup
Ben Wing <ben@xemacs.org>
parents: 5038
diff changeset
28 #include "gc.h"
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
29 #include "hash.h"
1315
70921960b980 [xemacs-hg @ 2003-02-20 08:19:28 by ben]
ben
parents: 1292
diff changeset
30 #include "profile.h"
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
31
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
32 #include "syssignal.h"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
33 #include "systime.h"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
34
611
38db05db9cb5 [xemacs-hg @ 2001-06-08 12:21:09 by ben]
ben
parents: 458
diff changeset
35 #ifndef HAVE_SETITIMER
38db05db9cb5 [xemacs-hg @ 2001-06-08 12:21:09 by ben]
ben
parents: 458
diff changeset
36 #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
37 #endif
38db05db9cb5 [xemacs-hg @ 2001-06-08 12:21:09 by ben]
ben
parents: 458
diff changeset
38
1292
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
39 #ifdef WIN32_ANY
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
40 int mswindows_is_blocking;
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
41 #endif
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
42
2367
ecf1ebac70d8 [xemacs-hg @ 2004-11-04 23:05:23 by ben]
ben
parents: 2286
diff changeset
43 /* Written by Ben Wing. */
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
44
2367
ecf1ebac70d8 [xemacs-hg @ 2004-11-04 23:05:23 by ben]
ben
parents: 2286
diff changeset
45 /*
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
46
2367
ecf1ebac70d8 [xemacs-hg @ 2004-11-04 23:05:23 by ben]
ben
parents: 2286
diff changeset
47 Documented in
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
48
2367
ecf1ebac70d8 [xemacs-hg @ 2004-11-04 23:05:23 by ben]
ben
parents: 2286
diff changeset
49 (Info-goto-node "(internals)Profiling")
1292
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
50 */
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
51
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
52 /* 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
53 handler. */
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
54 static struct hash_table *big_profile_table;
1292
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
55 Lisp_Object Vtotal_timing_profile_table;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
56 Lisp_Object Vcall_count_profile_table;
1292
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
57 Lisp_Object Vtotal_gc_usage_profile_table;
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
58 Lisp_Object Vgc_usage_profile_table;
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
59
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
60 extern int lisp_eval_depth;
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
61
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
62 extern EMACS_UINT total_consing;
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
63 static volatile EMACS_UINT total_ticks;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
64
458
c33ae14dd6d0 Import from CVS: tag r21-2-44
cvs
parents: 442
diff changeset
65 Fixnum default_profiling_interval;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
66
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
67 int profiling_active;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
68
1292
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
69 static Lisp_Object QSprocessing_events_at_top_level;
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
70 static Lisp_Object QSunknown, QSprofile_overhead;
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
71
2514
b49d38bc659d [xemacs-hg @ 2005-01-26 10:09:19 by ben]
ben
parents: 2421
diff changeset
72 #ifdef DEBUG_XEMACS
b49d38bc659d [xemacs-hg @ 2005-01-26 10:09:19 by ben]
ben
parents: 2421
diff changeset
73 /* For temporary profiling */
b49d38bc659d [xemacs-hg @ 2005-01-26 10:09:19 by ben]
ben
parents: 2421
diff changeset
74 Lisp_Object QSin_temp_spot_1;
b49d38bc659d [xemacs-hg @ 2005-01-26 10:09:19 by ben]
ben
parents: 2421
diff changeset
75 Lisp_Object QSin_temp_spot_2;
b49d38bc659d [xemacs-hg @ 2005-01-26 10:09:19 by ben]
ben
parents: 2421
diff changeset
76 Lisp_Object QSin_temp_spot_3;
b49d38bc659d [xemacs-hg @ 2005-01-26 10:09:19 by ben]
ben
parents: 2421
diff changeset
77 Lisp_Object QSin_temp_spot_4;
b49d38bc659d [xemacs-hg @ 2005-01-26 10:09:19 by ben]
ben
parents: 2421
diff changeset
78 Lisp_Object QSin_temp_spot_5;
b49d38bc659d [xemacs-hg @ 2005-01-26 10:09:19 by ben]
ben
parents: 2421
diff changeset
79 #endif /* DEBUG_XEMACS */
b49d38bc659d [xemacs-hg @ 2005-01-26 10:09:19 by ben]
ben
parents: 2421
diff changeset
80
1292
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
81 static Lisp_Object Qtiming, Qtotal_timing, Qcall_count;
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
82 static Lisp_Object Qgc_usage, Qtotal_gc_usage;
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
83
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
84 /* 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
85 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
86 #define EXTRA_BREATHING_ROOM 100
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
87
1292
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
88 /* 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
89 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
90 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
91 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
92 static volatile int profiling_lock;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
93
1292
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
94 /* 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
95 Used to indicate amount of time spent profiling. */
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
96 static int in_profiling;
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
97
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
98 #if 0 /* #### for KKCC, eventually */
1123
37bdd24225ef [xemacs-hg @ 2002-11-27 07:15:02 by ben]
ben
parents: 853
diff changeset
99
1292
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
100 static const struct memory_description hentry_description_1[] = {
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
101 { XD_LISP_OBJECT, offsetof (hentry, key) },
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
102 { XD_END }
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
103 };
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
104
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
105 static const struct sized_memory_description hentry_description = {
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
106 sizeof (hentry),
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
107 hentry_description_1
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
108 };
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
109
1292
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
110 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
111 { XD_ELEMCOUNT, offsetof (struct hash_table, size) },
2367
ecf1ebac70d8 [xemacs-hg @ 2004-11-04 23:05:23 by ben]
ben
parents: 2286
diff changeset
112 { XD_BLOCK_PTR, offsetof (struct hash_table, harray), XD_INDIRECT (0, 0),
2551
9f70af3ac939 [xemacs-hg @ 2005-02-03 16:14:02 by james]
james
parents: 2514
diff changeset
113 { &hentry_description } },
1292
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
114 { XD_END }
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
115 };
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
116
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
117 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
118 sizeof (struct hash_table),
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
119 plain_hash_table_description_1
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
120 };
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
121
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
122 #endif /* 0 */
1123
37bdd24225ef [xemacs-hg @ 2002-11-27 07:15:02 by ben]
ben
parents: 853
diff changeset
123
37bdd24225ef [xemacs-hg @ 2002-11-27 07:15:02 by ben]
ben
parents: 853
diff changeset
124 static void
37bdd24225ef [xemacs-hg @ 2002-11-27 07:15:02 by ben]
ben
parents: 853
diff changeset
125 create_timing_profile_table (void)
37bdd24225ef [xemacs-hg @ 2002-11-27 07:15:02 by ben]
ben
parents: 853
diff changeset
126 {
1292
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
127 /* 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
128 it has to grow the hash table. In this case, it calls realloc(),
5038
9410323e4b0d major dynarr fixes
Ben Wing <ben@xemacs.org>
parents: 5013
diff changeset
129 which is not (in general) reentrant. The way we deal with this is
1292
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
130 documented at the top of this file. */
1123
37bdd24225ef [xemacs-hg @ 2002-11-27 07:15:02 by ben]
ben
parents: 853
diff changeset
131 if (!big_profile_table)
1292
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
132 big_profile_table = make_hash_table (2000);
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
133 }
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 void
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
136 create_profile_tables (void)
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 create_timing_profile_table ();
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
139 if (NILP (Vtotal_timing_profile_table))
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
140 Vtotal_timing_profile_table =
5191
71ee43b8a74d Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents: 5169
diff changeset
141 make_lisp_hash_table (1000, HASH_TABLE_NON_WEAK, Qeq);
1292
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
142 if (NILP (Vcall_count_profile_table))
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
143 Vcall_count_profile_table =
5191
71ee43b8a74d Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents: 5169
diff changeset
144 make_lisp_hash_table (1000, HASH_TABLE_NON_WEAK, Qeq);
1292
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
145 if (NILP (Vgc_usage_profile_table))
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
146 Vgc_usage_profile_table =
5191
71ee43b8a74d Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents: 5169
diff changeset
147 make_lisp_hash_table (1000, HASH_TABLE_NON_WEAK, Qeq);
1292
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
148 if (NILP (Vtotal_gc_usage_profile_table))
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
149 Vtotal_gc_usage_profile_table =
5191
71ee43b8a74d Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents: 5169
diff changeset
150 make_lisp_hash_table (1000, HASH_TABLE_NON_WEAK, Qeq);
1292
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
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
153 static Lisp_Object
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
154 current_profile_function (void)
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
155 {
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
156 Lisp_Object fun;
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
157 struct backtrace *bt = backtrace_list;
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 /* 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
160 if (in_profiling >= 2)
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
161 return QSprofile_overhead;
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
162
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
163 /* 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
164 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
165 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
166 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
167 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
168 finished the preamble will not have been recorded. */
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
169 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
170 ;
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
171
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
172 if (bt)
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
173 {
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
174 fun = *bt->function;
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 if (!SYMBOLP (fun)
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
177 && !COMPILED_FUNCTIONP (fun)
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
178 && !SUBRP (fun)
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
179 && !CONSP (fun)
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
180 && !STRINGP (fun))
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
181 fun = QSunknown;
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
182 }
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
183 else
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
184 fun = QSprocessing_events_at_top_level;
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
185 return fun;
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
186 }
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 void
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
189 profile_record_consing (EMACS_INT size)
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
190 {
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
191 in_profiling++;
2421
ab71ad6ff3dd [xemacs-hg @ 2004-12-06 03:50:53 by ben]
ben
parents: 2367
diff changeset
192 inchash_eq (current_profile_function (), Vgc_usage_profile_table, size);
1292
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
193 in_profiling--;
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
194 }
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
195
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
196 void
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
197 profile_record_unconsing (EMACS_INT size)
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
198 {
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
199 /* 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
200 the totals won't be accurate. */
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
201 profile_record_consing (-size);
1123
37bdd24225ef [xemacs-hg @ 2002-11-27 07:15:02 by ben]
ben
parents: 853
diff changeset
202 }
37bdd24225ef [xemacs-hg @ 2002-11-27 07:15:02 by ben]
ben
parents: 853
diff changeset
203
1292
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
204 inline static void
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
205 profile_sow_backtrace (struct backtrace *bt)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
206 {
1292
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
207 bt->current_total_timing_val =
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
208 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
209 bt->current_total_gc_usage_val =
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
210 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
211 bt->function_being_called = 1;
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
212 /* 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
213 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
214 values; */
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
215 bt->total_consing_at_start = total_consing;
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
216 /* 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
217 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
218 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
219 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
220 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
221 executing the in_profiling++ statement in
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
222 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
223 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
224 conditions just mentioned. */
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
225 bt->total_ticks_at_start = total_ticks;
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
226 }
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
227
1292
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
228 void
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
229 profile_record_about_to_call (struct backtrace *bt)
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
230 {
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
231 in_profiling++;
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
232 profiling_lock = 1;
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
233 /* See comments in create_timing_profile_table(). */
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
234 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
235 profiling_lock = 0;
2421
ab71ad6ff3dd [xemacs-hg @ 2004-12-06 03:50:53 by ben]
ben
parents: 2367
diff changeset
236 inchash_eq (*bt->function, Vcall_count_profile_table, 1);
1292
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
237 /* 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
238 `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
239 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
240 recording ticks and consing for the function. */
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
241 if (!bt->function_being_called)
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
242 profile_sow_backtrace (bt);
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
243 in_profiling--;
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
244 }
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
245
1292
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
246 inline static void
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
247 profile_reap_backtrace (struct backtrace *bt)
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
248 {
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
249 EMACS_UINT ticks;
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
250 /* 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
251 See the comment above. */
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
252 ticks = total_ticks;
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
253 /* 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
254 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
255 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
256 bt->function_being_called = 0;
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
257 Fputhash (*bt->function,
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
258 /* 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
259 Same for total_consing below. */
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
260 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
261 + bt->current_total_timing_val),
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
262 Vtotal_timing_profile_table);
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
263 Fputhash (*bt->function,
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
264 make_int ((EMACS_INT)
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
265 (total_consing - bt->total_consing_at_start)
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
266 + bt->current_total_gc_usage_val),
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
267 Vtotal_gc_usage_profile_table);
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
268 }
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
269
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
270 void
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
271 profile_record_just_called (struct backtrace *bt)
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
272 {
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
273 in_profiling++;
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
274 profile_reap_backtrace (bt);
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
275 in_profiling--;
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
276 }
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
277
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
278 /* 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
279 note that we are exiting the function. */
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
280 void
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
281 profile_record_unwind (struct backtrace *bt)
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
282 {
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
283 /* 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
284 if (bt->function_being_called)
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
285 profile_record_just_called (bt);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
286 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
287
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
288 static SIGTYPE
2286
04bc9d2f42c7 [xemacs-hg @ 2004-09-20 19:18:55 by james]
james
parents: 1598
diff changeset
289 sigprof_handler (int UNUSED (signo))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
290 {
1292
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
291 #ifdef WIN32_ANY
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
292 /* 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
293 (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
294 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
295 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
296 if (mswindows_is_blocking)
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
297 return;
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
298 #endif
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
299
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
300 in_profiling++;
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
301 total_ticks++;
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
302
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
303 /* 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
304 or clrhash on the table. */
1292
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
305 if (!profiling_lock && !preparing_for_armageddon)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
306 {
1292
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
307 Lisp_Object fun = current_profile_function ();
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
308
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
309 /* If something below causes an error to be signaled, we'll
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
310 not correctly reset this flag. But we'll be in worse shape
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
311 than that anyways, since we'll longjmp back to the last
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
312 condition case. */
1292
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
313 profiling_lock = 1;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
314
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
315 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
316 long count;
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 434
diff changeset
317 const void *vval;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
318
5013
ae48681c47fa changes to VOID_TO_LISP et al.
Ben Wing <ben@xemacs.org>
parents: 4952
diff changeset
319 if (gethash (STORE_LISP_IN_VOID (fun), big_profile_table, &vval))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
320 count = (long) vval;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
321 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
322 count = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
323 count++;
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 434
diff changeset
324 vval = (const void *) count;
5013
ae48681c47fa changes to VOID_TO_LISP et al.
Ben Wing <ben@xemacs.org>
parents: 4952
diff changeset
325 puthash (STORE_LISP_IN_VOID (fun), (void *) vval, big_profile_table);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
326 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
327
1292
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
328 profiling_lock = 0;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
329 }
1292
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
330 in_profiling--;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
331 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
332
1292
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
333 DEFUN ("start-profiling", Fstart_profiling, 0, 1, "", /*
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
334 Start profiling, with profile queries every MICROSECS.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
335 If MICROSECS is nil or omitted, the value of `default-profiling-interval'
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
336 is used.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
337
1123
37bdd24225ef [xemacs-hg @ 2002-11-27 07:15:02 by ben]
ben
parents: 853
diff changeset
338 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
339 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
340 or the higher-level function `profile-results'.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
341
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
342 Starting and stopping profiling does not clear the currently recorded
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
343 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
344 will be properly accumulated. (To clear, use `clear-profiling-info'.)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
345 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
346 (microsecs))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
347 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
348 /* This function can GC */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
349 int msecs;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
350 struct itimerval foo;
1292
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
351 int depth;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
352
1292
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
353 if (profiling_active)
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
354 return Qnil;
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
355 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
356
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
357 create_profile_tables ();
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
358 /* 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
359 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
360 stack. */
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
361 pregrow_hash_table_if_necessary (big_profile_table,
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
362 EXTRA_BREATHING_ROOM + lisp_eval_depth);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
363
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
364 if (NILP (microsecs))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
365 msecs = default_profiling_interval;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
366 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
367 {
5307
c096d8051f89 Have NATNUMP give t for positive bignums; check limits appropriately.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5191
diff changeset
368 #ifdef HAVE_BIGNUM
c096d8051f89 Have NATNUMP give t for positive bignums; check limits appropriately.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5191
diff changeset
369 check_integer_range (microsecs, make_int (1000), make_integer (INT_MAX));
c096d8051f89 Have NATNUMP give t for positive bignums; check limits appropriately.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5191
diff changeset
370 msecs =
c096d8051f89 Have NATNUMP give t for positive bignums; check limits appropriately.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5191
diff changeset
371 BIGNUMP (microsecs) ? bignum_to_int (XBIGNUM_DATA (microsecs)) :
c096d8051f89 Have NATNUMP give t for positive bignums; check limits appropriately.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5191
diff changeset
372 XINT (microsecs);
c096d8051f89 Have NATNUMP give t for positive bignums; check limits appropriately.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5191
diff changeset
373 #else
c096d8051f89 Have NATNUMP give t for positive bignums; check limits appropriately.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5191
diff changeset
374 check_integer_range (microsecs, make_int (1000),
c096d8051f89 Have NATNUMP give t for positive bignums; check limits appropriately.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5191
diff changeset
375 make_integer (EMACS_INT_MAX));
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
376 msecs = XINT (microsecs);
5307
c096d8051f89 Have NATNUMP give t for positive bignums; check limits appropriately.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5191
diff changeset
377 #endif
428
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 if (msecs <= 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
380 msecs = 1000;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
381
613
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 611
diff changeset
382 set_timeout_signal (SIGPROF, sigprof_handler);
1292
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
383 {
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
384 struct backtrace *bt = backtrace_list;
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
385
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
386 /* 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
387 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
388 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
389 function-only and total in such cases. */
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
390 for (; bt; bt = bt->next)
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
391 profile_sow_backtrace (bt);
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
392 }
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
393 profiling_active = 1;
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
394 profiling_lock = 0;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
395 foo.it_value.tv_sec = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
396 foo.it_value.tv_usec = msecs;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
397 EMACS_NORMALIZE_TIME (foo.it_value);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
398 foo.it_interval = foo.it_value;
611
38db05db9cb5 [xemacs-hg @ 2001-06-08 12:21:09 by ben]
ben
parents: 458
diff changeset
399 qxe_setitimer (ITIMER_PROF, &foo, 0);
1292
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
400 unbind_to (depth);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
401 return Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
402 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
403
1292
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
404 DEFUN ("stop-profiling", Fstop_profiling, 0, 0, "", /*
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
405 Stop profiling.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
406 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
407 ())
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 /* This function does not GC */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
410 struct itimerval foo;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
411
1292
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
412 if (!profiling_active)
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
413 return Qnil;
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
414 in_profiling++;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
415 foo.it_value.tv_sec = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
416 foo.it_value.tv_usec = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
417 foo.it_interval = foo.it_value;
611
38db05db9cb5 [xemacs-hg @ 2001-06-08 12:21:09 by ben]
ben
parents: 458
diff changeset
418 qxe_setitimer (ITIMER_PROF, &foo, 0);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
419 profiling_active = 0;
1292
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
420 {
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
421 struct backtrace *bt = backtrace_list;
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
422
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
423 for (; bt; bt = bt->next)
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
424 profile_reap_backtrace (bt);
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
425 }
613
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 611
diff changeset
426 set_timeout_signal (SIGPROF, fatal_error_signal);
1292
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
427 in_profiling--;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
428 return Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
429 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
430
1123
37bdd24225ef [xemacs-hg @ 2002-11-27 07:15:02 by ben]
ben
parents: 853
diff changeset
431 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
432 Clear out the recorded profiling info.
37bdd24225ef [xemacs-hg @ 2002-11-27 07:15:02 by ben]
ben
parents: 853
diff changeset
433 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
434 `call-count-profile-table'.
37bdd24225ef [xemacs-hg @ 2002-11-27 07:15:02 by ben]
ben
parents: 853
diff changeset
435 */
37bdd24225ef [xemacs-hg @ 2002-11-27 07:15:02 by ben]
ben
parents: 853
diff changeset
436 ())
37bdd24225ef [xemacs-hg @ 2002-11-27 07:15:02 by ben]
ben
parents: 853
diff changeset
437 {
1292
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
438 in_profiling++;
1123
37bdd24225ef [xemacs-hg @ 2002-11-27 07:15:02 by ben]
ben
parents: 853
diff changeset
439 /* This function does not GC */
37bdd24225ef [xemacs-hg @ 2002-11-27 07:15:02 by ben]
ben
parents: 853
diff changeset
440 if (big_profile_table)
37bdd24225ef [xemacs-hg @ 2002-11-27 07:15:02 by ben]
ben
parents: 853
diff changeset
441 {
1292
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
442 profiling_lock = 1;
1123
37bdd24225ef [xemacs-hg @ 2002-11-27 07:15:02 by ben]
ben
parents: 853
diff changeset
443 clrhash (big_profile_table);
1292
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
444 profiling_lock = 0;
1123
37bdd24225ef [xemacs-hg @ 2002-11-27 07:15:02 by ben]
ben
parents: 853
diff changeset
445 }
1292
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
446 if (!NILP (Vtotal_timing_profile_table))
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
447 Fclrhash (Vtotal_timing_profile_table);
1123
37bdd24225ef [xemacs-hg @ 2002-11-27 07:15:02 by ben]
ben
parents: 853
diff changeset
448 if (!NILP (Vcall_count_profile_table))
37bdd24225ef [xemacs-hg @ 2002-11-27 07:15:02 by ben]
ben
parents: 853
diff changeset
449 Fclrhash (Vcall_count_profile_table);
1292
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
450 if (!NILP (Vgc_usage_profile_table))
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
451 Fclrhash (Vgc_usage_profile_table);
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
452 if (!NILP (Vtotal_gc_usage_profile_table))
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
453 Fclrhash (Vtotal_gc_usage_profile_table);
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
454 in_profiling--;
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
455
1123
37bdd24225ef [xemacs-hg @ 2002-11-27 07:15:02 by ben]
ben
parents: 853
diff changeset
456 return Qnil;
37bdd24225ef [xemacs-hg @ 2002-11-27 07:15:02 by ben]
ben
parents: 853
diff changeset
457 }
37bdd24225ef [xemacs-hg @ 2002-11-27 07:15:02 by ben]
ben
parents: 853
diff changeset
458
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
459 struct get_profiling_info_closure
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
460 {
1123
37bdd24225ef [xemacs-hg @ 2002-11-27 07:15:02 by ben]
ben
parents: 853
diff changeset
461 Lisp_Object timing;
428
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 static int
1123
37bdd24225ef [xemacs-hg @ 2002-11-27 07:15:02 by ben]
ben
parents: 853
diff changeset
465 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
466 void *void_val,
37bdd24225ef [xemacs-hg @ 2002-11-27 07:15:02 by ben]
ben
parents: 853
diff changeset
467 void *void_closure)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
468 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
469 /* This function does not GC */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
470 Lisp_Object key;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
471 struct get_profiling_info_closure *closure
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
472 = (struct get_profiling_info_closure *) void_closure;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
473 EMACS_INT val;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
474
5013
ae48681c47fa changes to VOID_TO_LISP et al.
Ben Wing <ben@xemacs.org>
parents: 4952
diff changeset
475 key = GET_LISP_FROM_VOID (void_key);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
476 val = (EMACS_INT) void_val;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
477
1123
37bdd24225ef [xemacs-hg @ 2002-11-27 07:15:02 by ben]
ben
parents: 853
diff changeset
478 Fputhash (key, make_int (val), closure->timing);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
479 return 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
480 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
481
1292
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
482 static Lisp_Object
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
483 copy_hash_table_or_blank (Lisp_Object table)
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
484 {
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
485 return !NILP (table) ? Fcopy_hash_table (table) :
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
486 make_lisp_hash_table (100, HASH_TABLE_NON_WEAK,
5191
71ee43b8a74d Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents: 5169
diff changeset
487 Qeq);
1292
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
488 }
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
489
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
490 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
491 Return the currently recorded profiling info.
37bdd24225ef [xemacs-hg @ 2002-11-27 07:15:02 by ben]
ben
parents: 853
diff changeset
492 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
493 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
494 are recorded
37bdd24225ef [xemacs-hg @ 2002-11-27 07:15:02 by ben]
ben
parents: 853
diff changeset
495
37bdd24225ef [xemacs-hg @ 2002-11-27 07:15:02 by ben]
ben
parents: 853
diff changeset
496 `timing'
1292
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
497 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
498 describing internal processing operations -- redisplay, garbage
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
499 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
500 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
501 `start-profiling').
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
502
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
503 `total-timing'
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
504 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
505 the function and all descendants.
1123
37bdd24225ef [xemacs-hg @ 2002-11-27 07:15:02 by ben]
ben
parents: 853
diff changeset
506
37bdd24225ef [xemacs-hg @ 2002-11-27 07:15:02 by ben]
ben
parents: 853
diff changeset
507 `call-count'
1292
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
508 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
509
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
510 `gc-usage'
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
511 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
512
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
513 `total-gc-usage'
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
514 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
515 in the function and all descendants.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
516 */
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 /* This function does not GC */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
520 struct get_profiling_info_closure closure;
1292
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
521 Lisp_Object retv;
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
522 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
523 const void *overhead;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
524
1123
37bdd24225ef [xemacs-hg @ 2002-11-27 07:15:02 by ben]
ben
parents: 853
diff changeset
525 closure.timing =
5191
71ee43b8a74d Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents: 5169
diff changeset
526 make_lisp_hash_table (100, HASH_TABLE_NON_WEAK, Qequal);
1123
37bdd24225ef [xemacs-hg @ 2002-11-27 07:15:02 by ben]
ben
parents: 853
diff changeset
527
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
528 if (big_profile_table)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
529 {
1292
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
530 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
531 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
532
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
533 /* 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
534 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
535 so make sure it looks reasonable. */
5013
ae48681c47fa changes to VOID_TO_LISP et al.
Ben Wing <ben@xemacs.org>
parents: 4952
diff changeset
536 if (!gethash (STORE_LISP_IN_VOID (QSprofile_overhead), big_profile_table,
1292
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
537 &overhead))
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
538 overhead = 0;
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
539 Fputhash (QSprofile_overhead, make_int ((EMACS_INT) overhead),
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
540 Vtotal_timing_profile_table);
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
541
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 613
diff changeset
542 unbind_to (count);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
543 }
1123
37bdd24225ef [xemacs-hg @ 2002-11-27 07:15:02 by ben]
ben
parents: 853
diff changeset
544
1292
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
545 retv = nconc2 (list6 (Qtiming, closure.timing, Qtotal_timing,
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
546 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
547 Qcall_count,
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
548 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
549 list4 (Qgc_usage,
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
550 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
551 Qtotal_gc_usage,
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
552 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
553 )));
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
554 unbind_to (depth);
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
555 return retv;
1123
37bdd24225ef [xemacs-hg @ 2002-11-27 07:15:02 by ben]
ben
parents: 853
diff changeset
556 }
37bdd24225ef [xemacs-hg @ 2002-11-27 07:15:02 by ben]
ben
parents: 853
diff changeset
557
37bdd24225ef [xemacs-hg @ 2002-11-27 07:15:02 by ben]
ben
parents: 853
diff changeset
558 static int
37bdd24225ef [xemacs-hg @ 2002-11-27 07:15:02 by ben]
ben
parents: 853
diff changeset
559 set_profiling_info_timing_maphash (Lisp_Object key,
37bdd24225ef [xemacs-hg @ 2002-11-27 07:15:02 by ben]
ben
parents: 853
diff changeset
560 Lisp_Object val,
2286
04bc9d2f42c7 [xemacs-hg @ 2004-09-20 19:18:55 by james]
james
parents: 1598
diff changeset
561 void *UNUSED (void_closure))
1123
37bdd24225ef [xemacs-hg @ 2002-11-27 07:15:02 by ben]
ben
parents: 853
diff changeset
562 {
37bdd24225ef [xemacs-hg @ 2002-11-27 07:15:02 by ben]
ben
parents: 853
diff changeset
563 /* This function does not GC */
37bdd24225ef [xemacs-hg @ 2002-11-27 07:15:02 by ben]
ben
parents: 853
diff changeset
564 if (!INTP (val))
37bdd24225ef [xemacs-hg @ 2002-11-27 07:15:02 by ben]
ben
parents: 853
diff changeset
565 invalid_argument_2
37bdd24225ef [xemacs-hg @ 2002-11-27 07:15:02 by ben]
ben
parents: 853
diff changeset
566 ("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
567 key, val);
37bdd24225ef [xemacs-hg @ 2002-11-27 07:15:02 by ben]
ben
parents: 853
diff changeset
568
5013
ae48681c47fa changes to VOID_TO_LISP et al.
Ben Wing <ben@xemacs.org>
parents: 4952
diff changeset
569 puthash (STORE_LISP_IN_VOID (key), (void *) XINT (val), big_profile_table);
1123
37bdd24225ef [xemacs-hg @ 2002-11-27 07:15:02 by ben]
ben
parents: 853
diff changeset
570
37bdd24225ef [xemacs-hg @ 2002-11-27 07:15:02 by ben]
ben
parents: 853
diff changeset
571 return 0;
37bdd24225ef [xemacs-hg @ 2002-11-27 07:15:02 by ben]
ben
parents: 853
diff changeset
572 }
37bdd24225ef [xemacs-hg @ 2002-11-27 07:15:02 by ben]
ben
parents: 853
diff changeset
573
37bdd24225ef [xemacs-hg @ 2002-11-27 07:15:02 by ben]
ben
parents: 853
diff changeset
574 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
575 Set the currently recorded profiling info.
37bdd24225ef [xemacs-hg @ 2002-11-27 07:15:02 by ben]
ben
parents: 853
diff changeset
576 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
577 as described there.
37bdd24225ef [xemacs-hg @ 2002-11-27 07:15:02 by ben]
ben
parents: 853
diff changeset
578 */
37bdd24225ef [xemacs-hg @ 2002-11-27 07:15:02 by ben]
ben
parents: 853
diff changeset
579 (info))
37bdd24225ef [xemacs-hg @ 2002-11-27 07:15:02 by ben]
ben
parents: 853
diff changeset
580 {
1292
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
581 int depth;
1123
37bdd24225ef [xemacs-hg @ 2002-11-27 07:15:02 by ben]
ben
parents: 853
diff changeset
582 /* This function does not GC */
37bdd24225ef [xemacs-hg @ 2002-11-27 07:15:02 by ben]
ben
parents: 853
diff changeset
583 Fclear_profiling_info ();
37bdd24225ef [xemacs-hg @ 2002-11-27 07:15:02 by ben]
ben
parents: 853
diff changeset
584
1292
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
585 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
586 {
37bdd24225ef [xemacs-hg @ 2002-11-27 07:15:02 by ben]
ben
parents: 853
diff changeset
587 EXTERNAL_PROPERTY_LIST_LOOP_3 (key, value, info)
37bdd24225ef [xemacs-hg @ 2002-11-27 07:15:02 by ben]
ben
parents: 853
diff changeset
588 {
37bdd24225ef [xemacs-hg @ 2002-11-27 07:15:02 by ben]
ben
parents: 853
diff changeset
589 if (EQ (key, Qtiming))
37bdd24225ef [xemacs-hg @ 2002-11-27 07:15:02 by ben]
ben
parents: 853
diff changeset
590 {
37bdd24225ef [xemacs-hg @ 2002-11-27 07:15:02 by ben]
ben
parents: 853
diff changeset
591 CHECK_HASH_TABLE (value);
37bdd24225ef [xemacs-hg @ 2002-11-27 07:15:02 by ben]
ben
parents: 853
diff changeset
592 create_timing_profile_table ();
1292
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
593 profiling_lock = 1;
1123
37bdd24225ef [xemacs-hg @ 2002-11-27 07:15:02 by ben]
ben
parents: 853
diff changeset
594 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
595 NULL);
1292
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
596 profiling_lock = 0;
1123
37bdd24225ef [xemacs-hg @ 2002-11-27 07:15:02 by ben]
ben
parents: 853
diff changeset
597 }
37bdd24225ef [xemacs-hg @ 2002-11-27 07:15:02 by ben]
ben
parents: 853
diff changeset
598 else if (EQ (key, Qcall_count))
1292
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
599 Vcall_count_profile_table = Fcopy_hash_table (value);
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
600 else if (EQ (key, Qtotal_timing))
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
601 Vtotal_timing_profile_table = Fcopy_hash_table (value);
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
602 else if (EQ (key, Qgc_usage))
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
603 Vgc_usage_profile_table = Fcopy_hash_table (value);
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
604 else if (EQ (key, Qtotal_gc_usage))
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
605 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
606 else
37bdd24225ef [xemacs-hg @ 2002-11-27 07:15:02 by ben]
ben
parents: 853
diff changeset
607 invalid_constant ("Unrecognized profiling-info keyword", key);
37bdd24225ef [xemacs-hg @ 2002-11-27 07:15:02 by ben]
ben
parents: 853
diff changeset
608 }
37bdd24225ef [xemacs-hg @ 2002-11-27 07:15:02 by ben]
ben
parents: 853
diff changeset
609 }
37bdd24225ef [xemacs-hg @ 2002-11-27 07:15:02 by ben]
ben
parents: 853
diff changeset
610
1292
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
611 unbind_to (depth);
1123
37bdd24225ef [xemacs-hg @ 2002-11-27 07:15:02 by ben]
ben
parents: 853
diff changeset
612 return Qnil;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
613 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
614
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
615 static int
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 434
diff changeset
616 mark_profiling_info_maphash (const void *void_key,
2286
04bc9d2f42c7 [xemacs-hg @ 2004-09-20 19:18:55 by james]
james
parents: 1598
diff changeset
617 void *UNUSED (void_val),
04bc9d2f42c7 [xemacs-hg @ 2004-09-20 19:18:55 by james]
james
parents: 1598
diff changeset
618 void *UNUSED (void_closure))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
619 {
1598
ac1be85b4a5f [xemacs-hg @ 2003-07-31 13:32:24 by crestani]
crestani
parents: 1346
diff changeset
620 #ifdef USE_KKCC
5169
6c6d78781d59 cleanup of code related to xfree(), better KKCC backtrace capabilities, document XD_INLINE_LISP_OBJECT_BLOCK_PTR, fix some memory leaks, other code cleanup
Ben Wing <ben@xemacs.org>
parents: 5038
diff changeset
621 kkcc_gc_stack_push_lisp_object_0 (GET_LISP_FROM_VOID (void_key));
1598
ac1be85b4a5f [xemacs-hg @ 2003-07-31 13:32:24 by crestani]
crestani
parents: 1346
diff changeset
622 #else /* NOT USE_KKCC */
5013
ae48681c47fa changes to VOID_TO_LISP et al.
Ben Wing <ben@xemacs.org>
parents: 4952
diff changeset
623 mark_object (GET_LISP_FROM_VOID (void_key));
1598
ac1be85b4a5f [xemacs-hg @ 2003-07-31 13:32:24 by crestani]
crestani
parents: 1346
diff changeset
624 #endif /* NOT USE_KKCC */
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
625 return 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
626 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
627
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
628 void
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
629 mark_profiling_info (void)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
630 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
631 /* This function does not GC */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
632 if (big_profile_table)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
633 {
1292
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
634 profiling_lock = 1;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
635 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
636 profiling_lock = 0;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
637 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
638 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
639
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
640 DEFUN ("profiling-active-p", Fprofiling_active_p, 0, 0, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
641 Return non-nil if profiling information is currently being recorded.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
642 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
643 ())
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
644 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
645 return profiling_active ? Qt : Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
646 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
647
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
648 void
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
649 syms_of_profile (void)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
650 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
651 DEFSUBR (Fstart_profiling);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
652 DEFSUBR (Fstop_profiling);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
653 DEFSUBR (Fget_profiling_info);
1123
37bdd24225ef [xemacs-hg @ 2002-11-27 07:15:02 by ben]
ben
parents: 853
diff changeset
654 DEFSUBR (Fset_profiling_info);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
655 DEFSUBR (Fclear_profiling_info);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
656 DEFSUBR (Fprofiling_active_p);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
657 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
658
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
659 void
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
660 vars_of_profile (void)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
661 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
662 DEFVAR_INT ("default-profiling-interval", &default_profiling_interval /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
663 Default CPU time in microseconds between profiling sampling.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
664 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
665 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
666 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
667 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
668 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
669 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
670 value can be.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
671 */ );
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
672 default_profiling_interval = 1000;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
673
1123
37bdd24225ef [xemacs-hg @ 2002-11-27 07:15:02 by ben]
ben
parents: 853
diff changeset
674 staticpro (&Vcall_count_profile_table);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
675 Vcall_count_profile_table = Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
676
1292
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
677 staticpro (&Vgc_usage_profile_table);
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
678 Vgc_usage_profile_table = Qnil;
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
679
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
680 staticpro (&Vtotal_gc_usage_profile_table);
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
681 Vtotal_gc_usage_profile_table = Qnil;
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
682
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
683 staticpro (&Vtotal_timing_profile_table);
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
684 Vtotal_timing_profile_table = Qnil;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
685
1292
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
686 #if 0
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
687 /* #### 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
688 currently. */
2367
ecf1ebac70d8 [xemacs-hg @ 2004-11-04 23:05:23 by ben]
ben
parents: 2286
diff changeset
689 dump_add_root_block_ptr (&big_profile_table, &plain_hash_table_description);
1292
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
690 #endif /* 0 */
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
691
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
692 profiling_lock = 0;
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
693
2514
b49d38bc659d [xemacs-hg @ 2005-01-26 10:09:19 by ben]
ben
parents: 2421
diff changeset
694 #ifdef DEBUG_XEMACS
4952
19a72041c5ed Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents: 2645
diff changeset
695 QSin_temp_spot_1 = build_defer_string ("(in temp spot 1)");
2514
b49d38bc659d [xemacs-hg @ 2005-01-26 10:09:19 by ben]
ben
parents: 2421
diff changeset
696 staticpro (&QSin_temp_spot_1);
b49d38bc659d [xemacs-hg @ 2005-01-26 10:09:19 by ben]
ben
parents: 2421
diff changeset
697
4952
19a72041c5ed Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents: 2645
diff changeset
698 QSin_temp_spot_2 = build_defer_string ("(in temp spot 2)");
2514
b49d38bc659d [xemacs-hg @ 2005-01-26 10:09:19 by ben]
ben
parents: 2421
diff changeset
699 staticpro (&QSin_temp_spot_2);
b49d38bc659d [xemacs-hg @ 2005-01-26 10:09:19 by ben]
ben
parents: 2421
diff changeset
700
4952
19a72041c5ed Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents: 2645
diff changeset
701 QSin_temp_spot_3 = build_defer_string ("(in temp spot 3)");
2514
b49d38bc659d [xemacs-hg @ 2005-01-26 10:09:19 by ben]
ben
parents: 2421
diff changeset
702 staticpro (&QSin_temp_spot_3);
b49d38bc659d [xemacs-hg @ 2005-01-26 10:09:19 by ben]
ben
parents: 2421
diff changeset
703
4952
19a72041c5ed Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents: 2645
diff changeset
704 QSin_temp_spot_4 = build_defer_string ("(in temp spot 4)");
2514
b49d38bc659d [xemacs-hg @ 2005-01-26 10:09:19 by ben]
ben
parents: 2421
diff changeset
705 staticpro (&QSin_temp_spot_4);
b49d38bc659d [xemacs-hg @ 2005-01-26 10:09:19 by ben]
ben
parents: 2421
diff changeset
706
4952
19a72041c5ed Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents: 2645
diff changeset
707 QSin_temp_spot_5 = build_defer_string ("(in temp spot 5)");
2514
b49d38bc659d [xemacs-hg @ 2005-01-26 10:09:19 by ben]
ben
parents: 2421
diff changeset
708 staticpro (&QSin_temp_spot_5);
b49d38bc659d [xemacs-hg @ 2005-01-26 10:09:19 by ben]
ben
parents: 2421
diff changeset
709 #endif /* DEBUG_XEMACS */
b49d38bc659d [xemacs-hg @ 2005-01-26 10:09:19 by ben]
ben
parents: 2421
diff changeset
710
4952
19a72041c5ed Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents: 2645
diff changeset
711 QSunknown = build_defer_string ("(unknown)");
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
712 staticpro (&QSunknown);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
713 QSprocessing_events_at_top_level =
4952
19a72041c5ed Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents: 2645
diff changeset
714 build_defer_string ("(processing events at top level)");
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
715 staticpro (&QSprocessing_events_at_top_level);
4952
19a72041c5ed Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents: 2645
diff changeset
716 QSprofile_overhead = build_defer_string ("(profile overhead)");
1292
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
717 staticpro (&QSprofile_overhead);
1123
37bdd24225ef [xemacs-hg @ 2002-11-27 07:15:02 by ben]
ben
parents: 853
diff changeset
718
37bdd24225ef [xemacs-hg @ 2002-11-27 07:15:02 by ben]
ben
parents: 853
diff changeset
719 DEFSYMBOL (Qtiming);
1292
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
720 DEFSYMBOL (Qtotal_timing);
1123
37bdd24225ef [xemacs-hg @ 2002-11-27 07:15:02 by ben]
ben
parents: 853
diff changeset
721 DEFSYMBOL (Qcall_count);
1292
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
722 DEFSYMBOL (Qgc_usage);
f3437b56874d [xemacs-hg @ 2003-02-13 09:57:04 by ben]
ben
parents: 1123
diff changeset
723 DEFSYMBOL (Qtotal_gc_usage);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
724 }