1292
|
1 /* Profiling.
|
|
2 Copyright (C) 2003 Ben Wing.
|
|
3
|
|
4 This file is part of XEmacs.
|
|
5
|
|
6 XEmacs is free software; you can redistribute it and/or modify it
|
|
7 under the terms of the GNU General Public License as published by the
|
|
8 Free Software Foundation; either version 2, or (at your option) any
|
|
9 later version.
|
|
10
|
|
11 XEmacs is distributed in the hope that it will be useful, but WITHOUT
|
|
12 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
14 for more details.
|
|
15
|
|
16 You should have received a copy of the GNU General Public License
|
|
17 along with XEmacs; see the file COPYING. If not, write to
|
|
18 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
19 Boston, MA 02111-1307, USA. */
|
|
20
|
|
21 /* Synched up with: Not in FSF. */
|
|
22
|
|
23 /* Authorship:
|
|
24
|
|
25 Ben Wing: Feb 2003.
|
|
26 */
|
|
27
|
|
28 #include "backtrace.h"
|
|
29
|
|
30 void mark_profiling_info (void);
|
|
31 void profile_record_unwind (struct backtrace *);
|
|
32 void profile_record_about_to_call (struct backtrace *);
|
|
33 void profile_record_just_called (struct backtrace *);
|
|
34 void profile_record_consing (EMACS_INT size);
|
|
35 void profile_record_unconsing (EMACS_INT size);
|
|
36 extern int profiling_active;
|
|
37
|
|
38 /* We call about_to_call() and just_called() depending on the current
|
|
39 *dynamic* value of profiling_active (which could change as a result of
|
|
40 calling the function) but if we push a backtrace, we must pop it later,
|
|
41 so we need to remember the status of this. */
|
|
42 #define PROFILE_DECLARE() \
|
|
43 int do_backtrace = profiling_active || backtrace_with_internal_sections; \
|
|
44 struct backtrace backtrace
|
|
45
|
|
46 /* As just mentioned, we rely on the dynamic value of profiling_active.
|
|
47 This ensures correct behavior (e.g. we never modify the profiling info
|
|
48 when profiling is not active) because we seed and reap all functions
|
|
49 currently on the stack when starting and stopping. See
|
|
50 `start-profiling'. */
|
|
51 #define PROFILE_ENTER_FUNCTION() \
|
|
52 do \
|
|
53 { \
|
|
54 if (profiling_active) \
|
|
55 profile_record_about_to_call (&backtrace); \
|
|
56 } \
|
|
57 while (0)
|
|
58
|
|
59 #define PROFILE_EXIT_FUNCTION() \
|
|
60 do \
|
|
61 { \
|
|
62 if (profiling_active) \
|
|
63 profile_record_just_called (&backtrace); \
|
|
64 } \
|
|
65 while (0)
|
|
66
|
|
67 /* We are entering a section that we would like to record profile information
|
|
68 about. We put this information into the backtrace list, just like
|
|
69 normal functions do. That is one easy way to make sure that we always
|
|
70 record info on the innermost section or function, whether section or
|
|
71 function. (To do this, we always need some sort of collusion between
|
|
72 profile and eval; this is one way.) */
|
|
73
|
|
74 #define PROFILE_RECORD_ENTERING_SECTION(var) \
|
|
75 do \
|
|
76 { \
|
|
77 if (do_backtrace) \
|
|
78 { \
|
|
79 backtrace.function = &var; \
|
|
80 backtrace.args = NULL; \
|
|
81 backtrace.nargs = UNEVALLED; \
|
|
82 backtrace.evalargs = 0; \
|
|
83 backtrace.pdlcount = specpdl_depth (); \
|
|
84 backtrace.debug_on_exit = 0; \
|
|
85 backtrace.function_being_called = 0; \
|
|
86 PUSH_BACKTRACE (backtrace); \
|
|
87 } \
|
|
88 PROFILE_ENTER_FUNCTION (); \
|
|
89 } while (0)
|
|
90
|
|
91 #define PROFILE_RECORD_EXITING_SECTION(var) \
|
|
92 do \
|
|
93 { \
|
|
94 PROFILE_EXIT_FUNCTION (); \
|
|
95 if (do_backtrace) \
|
|
96 POP_BACKTRACE (backtrace); \
|
|
97 } while (0)
|
2514
|
98
|
|
99 #define RETURN_EXIT_PROFILING(tag, type, expr) \
|
|
100 do \
|
|
101 { \
|
|
102 type _ret_exitpr_ = (expr); \
|
|
103 PROFILE_RECORD_EXITING_SECTION (tag); \
|
|
104 RETURN_SANS_WARNINGS _ret_exitpr_; \
|
|
105 } while (0)
|
|
106
|
|
107 #define RETURN_LISP_EXIT_PROFILING(tag, expr) \
|
|
108 RETURN_EXIT_PROFILING (tag, Lisp_Object, expr)
|
|
109
|
|
110 #define RETURN_UNGCPRO_EXIT_PROFILING(tag, expr) \
|
|
111 { \
|
|
112 Lisp_Object ret_ungc_val = (expr); \
|
|
113 UNGCPRO; \
|
|
114 PROFILE_RECORD_EXITING_SECTION (tag); \
|
|
115 RETURN_SANS_WARNINGS ret_ungc_val; \
|
|
116 } while (0)
|
|
117
|
|
118 #ifdef DEBUG_XEMACS
|
|
119 extern Lisp_Object QSin_temp_spot_1;
|
|
120 extern Lisp_Object QSin_temp_spot_2;
|
|
121 extern Lisp_Object QSin_temp_spot_3;
|
|
122 extern Lisp_Object QSin_temp_spot_4;
|
|
123 extern Lisp_Object QSin_temp_spot_5;
|
|
124 #endif /* DEBUG_XEMACS */
|