2
** Author(s): Luis Castro
3
** Contact: xsb-contact@cs.sunysb.edu
5
** Copyright (C) The Research Foundation of SUNY, 1986, 1993-1998
6
** Copyright (C) ECRC, Germany, 1990
8
** XSB is free software; you can redistribute it and/or modify it under the
9
** terms of the GNU Library General Public License as published by the Free
10
** Software Foundation; either version 2 of the License, or (at your option)
13
** XSB is distributed in the hope that it will be useful, but WITHOUT ANY
14
** WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
15
** FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for
18
** You should have received a copy of the GNU Library General Public License
19
** along with XSB; if not, write to the Free Software Foundation,
20
** Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
22
** $Id: gc_profile.h,v 1.9 2006/04/27 21:08:47 tswift Exp $
27
#define GC_PROFILE_PRE_REPORT \
29
/* first, run the heap & collect info */ \
32
unsigned long heap_traversed=0; \
36
tag_examined[i] = 0; \
40
for (cell_ptr = (CPtr) glstack.low; cell_ptr < hreg; cell_ptr++) { \
42
tag = cell_tag(*cell_ptr); \
43
if (tag == XSB_REF || tag == XSB_REF1) { \
44
if (points_into_heap((CPtr) *cell_ptr)) { \
45
if (cell_ptr == (CPtr) *cell_ptr) { \
48
tag_examined[tag]++; \
50
} else if (points_into_heap((CPtr) cell_ptr)) { \
53
fprintf(stddbg,"+++ outside pointer %p in %p.\n", \
54
*(CPtr*)cell_ptr, (CPtr)cell_ptr); \
57
++tag_examined[tag]; \
61
fprintf(stddbg,"\n\n\n{GC} Prior to GC:\n"); \
62
fprintf(stddbg,"{GC} Cells visited:\n"); \
63
fprintf(stddbg, "{GC} %ld variables.\n", tag_examined[8]); \
64
fprintf(stddbg, "{GC} %ld reference cells.\n", \
65
tag_examined[XSB_REF] + tag_examined[XSB_REF1]); \
66
fprintf(stddbg, "{GC} %ld references from the local stack.\n", \
68
fprintf(stddbg, "{GC} %ld atom cells.\n", tag_examined[XSB_STRING]); \
69
fprintf(stddbg, "{GC} %ld integer cells.\n", tag_examined[XSB_INT]); \
70
fprintf(stddbg, "{GC} %ld float cells.\n", tag_examined[XSB_FLOAT]); \
71
fprintf(stddbg, "{GC} %ld list cells.\n", tag_examined[XSB_LIST]); \
72
fprintf(stddbg, "{GC} %ld structure cells.\n", \
73
tag_examined[XSB_STRUCT]); \
74
fprintf(stddbg, "{GC} %ld functor cells.\n",functor); \
75
fprintf(stddbg, "{GC} %ld attributed variable cells.\n", \
76
tag_examined[XSB_ATTV]); \
77
fprintf(stddbg, "{GC} %ld heap cells traversed.\n", \
84
for (i=0; i<64; i++) \
90
for (i=0; i<9; i++) { \
92
/* tag_examined_current[i]=0; */ \
94
chain_from_ls = functor = 0; \
95
current_mark = deep_mark=0; \
96
start_hbreg = cp_hreg(breg); \
97
old_gens = ((unsigned long) start_hbreg - (unsigned long) glstack.low) / \
99
current_gen = ((unsigned long) hreg - (unsigned long) start_hbreg) / \
106
#define INIT_GC_PROFILE \
107
verbose_gc=pflags[VERBOSE_GC]; \
108
examine_data=pflags[EXAMINE_DATA]; \
109
count_chains=pflags[COUNT_CHAINS]
111
#define DECL_GC_PROFILE \
112
unsigned long begin_slidetime, begin_copy_time
114
#define GC_PROFILE_START_SUMMARY \
117
xsb_dbgmsg((LOG_GC,"{GC} Heap gc - arity = %d - used = %d - left = %d - #gc = %d\n", \
118
arity,hreg+1-(CPtr)glstack.low,ereg-hreg,num_gc)); \
122
#define GC_PROFILE_MARK_SUMMARY \
125
xsb_dbgmsg((LOG_GC, "{GC} Heap gc - marking finished - #marked = %d - start compact\n", \
130
#define GC_PROFILE_QUIT_MSG \
133
xsb_dbgmsg((LOG_GC, "{GC} Heap gc - marked too much - quitting gc\n")); \
137
#define GC_PROFILE_SLIDE_START_TIME begin_slidetime = end_marktime
139
#define GC_PROFILE_SLIDE_FINAL_SUMMARY \
142
xsb_dbgmsg((LOG_GC, "{GC} Heap gc end - mark time = %f; slide time = %f; total = %f\n", \
143
(double)(end_marktime - begin_marktime)*1000/CLOCKS_PER_SEC, \
144
(double)(end_slidetime - begin_slidetime)*1000/CLOCKS_PER_SEC, \
149
#define GC_PROFILE_COPY_START_TIME begin_copy_time = end_marktime
151
#define GC_PROFILE_COPY_FINAL_SUMMARY \
154
fprintf(stddbg,"{GC} Heap gc end - mark time = %f; copy_time = %f; total = %f\n", \
155
(double)(end_marktime - begin_marktime)*1000/CLOCKS_PER_SEC, \
156
(double)(end_copy_time - begin_copy_time)*1000/CLOCKS_PER_SEC, \
161
#define GC_PROFILE_POST_REPORT \
163
if (count_chains|examine_data) { \
164
fprintf(stddbg, "\n{GC} Heap Garbage Collection #%d\n",num_gc); \
165
fprintf(stddbg, "{GC} Heap early reset reclaimed %d cells.\n", \
167
fprintf(stddbg, "{GC} Local early reset reclaimed %d cells.\n", \
171
if (count_chains) { \
173
fprintf(stddbg,"{GC} Reference Chains: \n"); \
174
for (i=0; i<64; i++) \
176
fprintf(stddbg, "{GC} chain[%d]=%ld\n",i,chains[i]); \
179
if (examine_data) { \
180
fprintf(stddbg,"{GC} Active Choice-points: %ld\n", active_cps); \
181
fprintf(stddbg,"{GC} Frozen Choice-points: %ld\n",frozen_cps); \
182
fprintf(stddbg,"{GC} Local stack size: %d\n", ls_bot - ls_top); \
183
fprintf(stddbg,"{GC} CP stack size: %d\n", cp_bot - cp_top); \
184
fprintf(stddbg,"{GC} Trail stack size: %d\n", tr_top - tr_bot); \
185
fprintf(stddbg,"{GC} Cells visited:\n"); \
186
fprintf(stddbg, "{GC} %ld variables.\n", tag_examined[8]); \
187
fprintf(stddbg, "{GC} %ld reference cells.\n", \
188
tag_examined[XSB_REF] + tag_examined[XSB_REF1]); \
189
fprintf(stddbg, "{GC} %ld references from the local stack.\n", \
191
fprintf(stddbg, "{GC} %ld atom cells.\n", tag_examined[XSB_STRING]); \
192
fprintf(stddbg, "{GC} %ld integer cells.\n", tag_examined[XSB_INT]); \
193
fprintf(stddbg, "{GC} %ld float cells.\n", tag_examined[XSB_FLOAT]); \
194
fprintf(stddbg, "{GC} %ld list cells.\n", tag_examined[XSB_LIST]); \
195
fprintf(stddbg, "{GC} %ld structure cells.\n", \
196
tag_examined[XSB_STRUCT]); \
197
fprintf(stddbg, "{GC} %ld functor cells.\n",functor); \
198
fprintf(stddbg, "{GC} %ld attributed variable cells.\n", \
199
tag_examined[XSB_ATTV]); \
201
if (current_gen > 0) \
202
fprintf(stddbg, "{GC} Cells marked on current generation: %ld / %ld = %ld / 100\n", \
203
current_mark, current_gen, (current_mark*100/current_gen)); \
205
fprintf(stddbg, "{GC} Cells marked on deep generations: %ld / %ld = %ld / 100\n", \
206
deep_mark, old_gens, (deep_mark*100/old_gens)); \
207
if (current_gen + old_gens > 0) \
208
fprintf(stddbg, "{GC} Total cells marked: %ld / %ld = %ld / 100\n", \
209
deep_mark + current_mark, current_gen + old_gens, \
210
((deep_mark+current_mark)*100/(current_gen+old_gens))); \
214
#define GC_PROFILE_PRE_REPORT
215
#define INIT_GC_PROFILE
216
#define DECL_GC_PROFILE
217
#define GC_PROFILE_START_SUMMARY
218
#define GC_PROFILE_MARK_SUMMARY
219
#define GC_PROFILE_QUIT_MSG
220
#define GC_PROFILE_SLIDE_START_TIME
221
#define GC_PROFILE_SLIDE_FINAL_SUMMARY
222
#define GC_PROFILE_COPY_START_TIME
223
#define GC_PROFILE_COPY_FINAL_SUMMARY
224
#define GC_PROFILE_POST_REPORT
229
inline static void inspect_chain(CPtr cell_ptr)
232
tag = cell_tag(*cell_ptr);
235
if ((tag == XSB_REF || tag == XSB_REF1) &&
236
points_into_heap((CPtr)*cell_ptr)) {
238
CPtr ptr = (CPtr) *cell_ptr;
239
if (points_into_ls(cell_ptr)) {
241
ptr = (CPtr) follow(ptr);
244
while (isref(ptr) && points_into_heap(ptr) &&
245
ptr != (CPtr) follow(ptr)) {
247
ptr = (CPtr) follow(ptr);
250
xsb_abort("Chain too long when inspecting cell in %p.\n", cell_ptr);
256
inline static void inspect_ptr(CPtr cell_ptr)
259
tag = cell_tag(*cell_ptr);
261
inspect_chain(cell_ptr);
264
if (tag == XSB_REF || tag == XSB_REF1) {
265
if (points_into_heap((CPtr) *cell_ptr)) {
266
if (cell_ptr == (CPtr) *cell_ptr)
271
else if (points_into_heap((CPtr) cell_ptr))
274
fprintf(stddbg,"+++ outside pointer %p in %p.\n",
275
*(CPtr*)cell_ptr, (CPtr)cell_ptr);
278
if ((unsigned long) cell_ptr < (unsigned long) start_hbreg)
287
/* the following cannot be "static inline" since it's used in
288
emu/trace_xsb.c and also uses global variables in heap_xsb.c
290
void print_gc_statistics(CTXTdecl)
292
char *which = (slide) ? "sliding" : "copying" ;
294
printf("%4d heap garbage collections by %s: collected %ld cells in %lf secs\n\n",
295
num_gc, which, total_collected, total_time_gc);