use SWI's IOSTREAM for output

This commit is contained in:
Ricardo Rocha 2011-05-25 18:38:46 +01:00
parent 14bdc262df
commit 1d4fdd53c0
8 changed files with 335 additions and 253 deletions

View File

@ -457,7 +457,7 @@ extern int Yap_page_size;
************************************************************************/ ************************************************************************/
#define INFORMATION_MESSAGE(MESSAGE,ARGS...) \ #define INFORMATION_MESSAGE(MESSAGE,ARGS...) \
fprintf(stderr, "[ " MESSAGE " ]\n", ##ARGS) Sfprintf(Serror, "[ " MESSAGE " ]\n", ##ARGS)
#ifdef YAPOR #ifdef YAPOR
#define ERROR_MESSAGE(MESSAGE) \ #define ERROR_MESSAGE(MESSAGE) \

View File

@ -17,13 +17,9 @@
#include "Yap.h" #include "Yap.h"
#if defined(YAPOR) || defined(TABLING) #if defined(YAPOR) || defined(TABLING)
#include <stdio.h>
#if HAVE_STRING_H
#include <string.h>
#endif /* HAVE_STRING_H */
#include "Yatom.h" #include "Yatom.h"
#include "YapHeap.h" #include "YapHeap.h"
#include "yapio.h" #include "SWI-Prolog.h"
#ifdef YAPOR #ifdef YAPOR
#if HAVE_SYS_TIME_H #if HAVE_SYS_TIME_H
#include <sys/time.h> #include <sys/time.h>
@ -76,26 +72,26 @@ static inline void answer_to_stdout(char *answer);
#endif /* YAPOR */ #endif /* YAPOR */
#ifdef TABLING #ifdef TABLING
static inline long show_statistics_table_entries(void); static inline long show_statistics_table_entries(IOSTREAM *out);
static inline long show_statistics_subgoal_frames(void); static inline long show_statistics_subgoal_frames(IOSTREAM *out);
static inline long show_statistics_dependency_frames(void); static inline long show_statistics_dependency_frames(IOSTREAM *out);
static inline long show_statistics_subgoal_trie_nodes(void); static inline long show_statistics_subgoal_trie_nodes(IOSTREAM *out);
static inline long show_statistics_answer_trie_nodes(void); static inline long show_statistics_answer_trie_nodes(IOSTREAM *out);
static inline long show_statistics_subgoal_trie_hashes(void); static inline long show_statistics_subgoal_trie_hashes(IOSTREAM *out);
static inline long show_statistics_answer_trie_hashes(void); static inline long show_statistics_answer_trie_hashes(IOSTREAM *out);
static inline long show_statistics_global_trie_nodes(void); static inline long show_statistics_global_trie_nodes(IOSTREAM *out);
static inline long show_statistics_global_trie_hashes(void); static inline long show_statistics_global_trie_hashes(IOSTREAM *out);
#endif /* TABLING */ #endif /* TABLING */
#ifdef YAPOR #ifdef YAPOR
static inline long show_statistics_or_frames(void); static inline long show_statistics_or_frames(IOSTREAM *out);
static inline long show_statistics_query_goal_solution_frames(void); static inline long show_statistics_query_goal_solution_frames(IOSTREAM *out);
static inline long show_statistics_query_goal_answer_frames(void); static inline long show_statistics_query_goal_answer_frames(IOSTREAM *out);
#endif /* YAPOR */ #endif /* YAPOR */
#if defined(YAPOR) && defined(TABLING) #if defined(YAPOR) && defined(TABLING)
static inline long show_statistics_suspension_frames(void); static inline long show_statistics_suspension_frames(IOSTREAM *out);
#ifdef TABLING_INNER_CUTS #ifdef TABLING_INNER_CUTS
static inline long show_statistics_table_subgoal_solution_frames(void); static inline long show_statistics_table_subgoal_solution_frames(IOSTREAM *out);
static inline long show_statistics_table_subgoal_answer_frames(void); static inline long show_statistics_table_subgoal_answer_frames(IOSTREAM *out);
#endif /* TABLING_INNER_CUTS */ #endif /* TABLING_INNER_CUTS */
#endif /* YAPOR && TABLING */ #endif /* YAPOR && TABLING */
@ -129,13 +125,13 @@ void Yap_init_optyap_preds(void) {
Yap_InitCPred("$c_tabling_mode", 3, p_tabling_mode, SafePredFlag|SyncPredFlag|HiddenPredFlag); Yap_InitCPred("$c_tabling_mode", 3, p_tabling_mode, SafePredFlag|SyncPredFlag|HiddenPredFlag);
Yap_InitCPred("$c_abolish_table", 2, p_abolish_table, SafePredFlag|SyncPredFlag|HiddenPredFlag); Yap_InitCPred("$c_abolish_table", 2, p_abolish_table, SafePredFlag|SyncPredFlag|HiddenPredFlag);
Yap_InitCPred("abolish_all_tables", 0, p_abolish_all_tables, SafePredFlag|SyncPredFlag); Yap_InitCPred("abolish_all_tables", 0, p_abolish_all_tables, SafePredFlag|SyncPredFlag);
Yap_InitCPred("show_tabled_predicates", 0, p_show_tabled_predicates, SafePredFlag|SyncPredFlag); Yap_InitCPred("show_tabled_predicates", 1, p_show_tabled_predicates, SafePredFlag|SyncPredFlag);
Yap_InitCPred("$c_show_table", 2, p_show_table, SafePredFlag|SyncPredFlag|HiddenPredFlag); Yap_InitCPred("$c_show_table", 3, p_show_table, SafePredFlag|SyncPredFlag|HiddenPredFlag);
Yap_InitCPred("show_all_tables", 0, p_show_all_tables, SafePredFlag|SyncPredFlag); Yap_InitCPred("show_all_tables", 1, p_show_all_tables, SafePredFlag|SyncPredFlag);
Yap_InitCPred("show_global_trie", 0, p_show_global_trie, SafePredFlag|SyncPredFlag); Yap_InitCPred("show_global_trie", 1, p_show_global_trie, SafePredFlag|SyncPredFlag);
Yap_InitCPred("$c_table_statistics", 2, p_show_statistics_table, SafePredFlag|SyncPredFlag|HiddenPredFlag); Yap_InitCPred("$c_table_statistics", 3, p_show_statistics_table, SafePredFlag|SyncPredFlag|HiddenPredFlag);
Yap_InitCPred("tabling_statistics", 0, p_show_statistics_tabling, SafePredFlag|SyncPredFlag); Yap_InitCPred("tabling_statistics", 1, p_show_statistics_tabling, SafePredFlag|SyncPredFlag);
Yap_InitCPred("global_trie_statistics", 0, p_show_statistics_global_trie, SafePredFlag|SyncPredFlag); Yap_InitCPred("global_trie_statistics", 1, p_show_statistics_global_trie, SafePredFlag|SyncPredFlag);
#endif /* TABLING */ #endif /* TABLING */
Yap_InitCPred("$c_yapor_threads", 1, p_yapor_threads, SafePredFlag|SyncPredFlag|HiddenPredFlag); Yap_InitCPred("$c_yapor_threads", 1, p_yapor_threads, SafePredFlag|SyncPredFlag|HiddenPredFlag);
#ifdef YAPOR #ifdef YAPOR
@ -147,10 +143,10 @@ void Yap_init_optyap_preds(void) {
Yap_InitCPred("performance", 1, p_performance, SafePredFlag|SyncPredFlag); Yap_InitCPred("performance", 1, p_performance, SafePredFlag|SyncPredFlag);
Yap_InitCPred("$c_parallel_new_answer", 1, p_parallel_new_answer, SafePredFlag|SyncPredFlag|HiddenPredFlag); Yap_InitCPred("$c_parallel_new_answer", 1, p_parallel_new_answer, SafePredFlag|SyncPredFlag|HiddenPredFlag);
Yap_InitCPred("$c_parallel_yes_answer", 0, p_parallel_yes_answer, SafePredFlag|SyncPredFlag|HiddenPredFlag); Yap_InitCPred("$c_parallel_yes_answer", 0, p_parallel_yes_answer, SafePredFlag|SyncPredFlag|HiddenPredFlag);
Yap_InitCPred("or_statistics", 0, p_show_statistics_or, SafePredFlag|SyncPredFlag); Yap_InitCPred("or_statistics", 1, p_show_statistics_or, SafePredFlag|SyncPredFlag);
#endif /* YAPOR */ #endif /* YAPOR */
#if defined(YAPOR) && defined(TABLING) #if defined(YAPOR) && defined(TABLING)
Yap_InitCPred("opt_statistics", 0, p_show_statistics_opt, SafePredFlag|SyncPredFlag); Yap_InitCPred("opt_statistics", 1, p_show_statistics_opt, SafePredFlag|SyncPredFlag);
#endif /* YAPOR && TABLING */ #endif /* YAPOR && TABLING */
Yap_InitCPred("$c_get_optyap_statistics", 3, p_get_optyap_statistics, SafePredFlag|SyncPredFlag|HiddenPredFlag); Yap_InitCPred("$c_get_optyap_statistics", 3, p_get_optyap_statistics, SafePredFlag|SyncPredFlag|HiddenPredFlag);
} }
@ -385,15 +381,18 @@ static Int p_abolish_all_tables( USES_REGS1 ) {
static Int p_show_tabled_predicates( USES_REGS1 ) { static Int p_show_tabled_predicates( USES_REGS1 ) {
IOSTREAM *out;
tab_ent_ptr tab_ent; tab_ent_ptr tab_ent;
if ((out = YAP_TermToStream(Deref(ARG1))) == NULL)
return (FALSE);
tab_ent = GLOBAL_root_tab_ent; tab_ent = GLOBAL_root_tab_ent;
fprintf(Yap_stdout, "Tabled predicates\n"); Sfprintf(out, "Tabled predicates\n");
if (tab_ent == NULL) if (tab_ent == NULL)
fprintf(Yap_stdout, " NONE\n"); Sfprintf(out, " NONE\n");
else else
while(tab_ent) { while(tab_ent) {
fprintf(Yap_stdout, " %s/%d\n", AtomName(TabEnt_atom(tab_ent)), TabEnt_arity(tab_ent)); Sfprintf(out, " %s/%d\n", AtomName(TabEnt_atom(tab_ent)), TabEnt_arity(tab_ent));
tab_ent = TabEnt_next(tab_ent); tab_ent = TabEnt_next(tab_ent);
} }
return (TRUE); return (TRUE);
@ -401,28 +400,34 @@ static Int p_show_tabled_predicates( USES_REGS1 ) {
static Int p_show_table( USES_REGS1 ) { static Int p_show_table( USES_REGS1 ) {
IOSTREAM *out;
Term mod, t; Term mod, t;
tab_ent_ptr tab_ent; tab_ent_ptr tab_ent;
mod = Deref(ARG1); if ((out = YAP_TermToStream(Deref(ARG1))) == NULL)
t = Deref(ARG2); return (FALSE);
mod = Deref(ARG2);
t = Deref(ARG3);
if (IsAtomTerm(t)) if (IsAtomTerm(t))
tab_ent = RepPredProp(PredPropByAtom(AtomOfTerm(t), mod))->TableOfPred; tab_ent = RepPredProp(PredPropByAtom(AtomOfTerm(t), mod))->TableOfPred;
else if (IsApplTerm(t)) else if (IsApplTerm(t))
tab_ent = RepPredProp(PredPropByFunc(FunctorOfTerm(t), mod))->TableOfPred; tab_ent = RepPredProp(PredPropByFunc(FunctorOfTerm(t), mod))->TableOfPred;
else else
return (FALSE); return (FALSE);
show_table(tab_ent, SHOW_MODE_STRUCTURE); show_table(tab_ent, SHOW_MODE_STRUCTURE, out);
return (TRUE); return (TRUE);
} }
static Int p_show_all_tables( USES_REGS1 ) { static Int p_show_all_tables( USES_REGS1 ) {
IOSTREAM *out;
tab_ent_ptr tab_ent; tab_ent_ptr tab_ent;
if ((out = YAP_TermToStream(Deref(ARG1))) == NULL)
return (FALSE);
tab_ent = GLOBAL_root_tab_ent; tab_ent = GLOBAL_root_tab_ent;
while(tab_ent) { while(tab_ent) {
show_table(tab_ent, SHOW_MODE_STRUCTURE); show_table(tab_ent, SHOW_MODE_STRUCTURE, out);
tab_ent = TabEnt_next(tab_ent); tab_ent = TabEnt_next(tab_ent);
} }
return (TRUE); return (TRUE);
@ -430,67 +435,79 @@ static Int p_show_all_tables( USES_REGS1 ) {
static Int p_show_global_trie( USES_REGS1 ) { static Int p_show_global_trie( USES_REGS1 ) {
show_global_trie(SHOW_MODE_STRUCTURE); IOSTREAM *out;
if ((out = YAP_TermToStream(Deref(ARG1))) == NULL)
return (FALSE);
show_global_trie(SHOW_MODE_STRUCTURE, out);
return (TRUE); return (TRUE);
} }
static Int p_show_statistics_table( USES_REGS1 ) { static Int p_show_statistics_table( USES_REGS1 ) {
IOSTREAM *out;
Term mod, t; Term mod, t;
tab_ent_ptr tab_ent; tab_ent_ptr tab_ent;
mod = Deref(ARG1); if ((out = YAP_TermToStream(Deref(ARG1))) == NULL)
t = Deref(ARG2); return (FALSE);
mod = Deref(ARG2);
t = Deref(ARG3);
if (IsAtomTerm(t)) if (IsAtomTerm(t))
tab_ent = RepPredProp(PredPropByAtom(AtomOfTerm(t), mod))->TableOfPred; tab_ent = RepPredProp(PredPropByAtom(AtomOfTerm(t), mod))->TableOfPred;
else if (IsApplTerm(t)) else if (IsApplTerm(t))
tab_ent = RepPredProp(PredPropByFunc(FunctorOfTerm(t), mod))->TableOfPred; tab_ent = RepPredProp(PredPropByFunc(FunctorOfTerm(t), mod))->TableOfPred;
else else
return (FALSE); return (FALSE);
show_table(tab_ent, SHOW_MODE_STATISTICS); show_table(tab_ent, SHOW_MODE_STATISTICS, out);
return (TRUE); return (TRUE);
} }
static Int p_show_statistics_tabling( USES_REGS1 ) { static Int p_show_statistics_tabling( USES_REGS1 ) {
IOSTREAM *out;
long total_bytes = 0, aux_bytes; long total_bytes = 0, aux_bytes;
if ((out = YAP_TermToStream(Deref(ARG1))) == NULL)
return (FALSE);
aux_bytes = 0; aux_bytes = 0;
fprintf(Yap_stdout, "Execution data structures\n"); Sfprintf(out, "Execution data structures\n");
aux_bytes += show_statistics_table_entries(); aux_bytes += show_statistics_table_entries(out);
aux_bytes += show_statistics_subgoal_frames(); aux_bytes += show_statistics_subgoal_frames(out);
aux_bytes += show_statistics_dependency_frames(); aux_bytes += show_statistics_dependency_frames(out);
fprintf(Yap_stdout, " Memory in use (I): %10ld bytes\n\n", aux_bytes); Sfprintf(out, " Memory in use (I): %10ld bytes\n\n", aux_bytes);
total_bytes += aux_bytes; total_bytes += aux_bytes;
aux_bytes = 0; aux_bytes = 0;
fprintf(Yap_stdout, "Local trie data structures\n"); Sfprintf(out, "Local trie data structures\n");
aux_bytes += show_statistics_subgoal_trie_nodes(); aux_bytes += show_statistics_subgoal_trie_nodes(out);
aux_bytes += show_statistics_answer_trie_nodes(); aux_bytes += show_statistics_answer_trie_nodes(out);
aux_bytes += show_statistics_subgoal_trie_hashes(); aux_bytes += show_statistics_subgoal_trie_hashes(out);
aux_bytes += show_statistics_answer_trie_hashes(); aux_bytes += show_statistics_answer_trie_hashes(out);
fprintf(Yap_stdout, " Memory in use (II): %10ld bytes\n\n", aux_bytes); Sfprintf(out, " Memory in use (II): %10ld bytes\n\n", aux_bytes);
total_bytes += aux_bytes; total_bytes += aux_bytes;
aux_bytes = 0; aux_bytes = 0;
fprintf(Yap_stdout, "Global trie data structures\n"); Sfprintf(out, "Global trie data structures\n");
aux_bytes += show_statistics_global_trie_nodes(); aux_bytes += show_statistics_global_trie_nodes(out);
aux_bytes += show_statistics_global_trie_hashes(); aux_bytes += show_statistics_global_trie_hashes(out);
fprintf(Yap_stdout, " Memory in use (III): %10ld bytes\n\n", aux_bytes); Sfprintf(out, " Memory in use (III): %10ld bytes\n\n", aux_bytes);
total_bytes += aux_bytes; total_bytes += aux_bytes;
#ifdef USE_PAGES_MALLOC #ifdef USE_PAGES_MALLOC
fprintf(Yap_stdout, "Total memory in use (I+II+III): %10ld bytes (%ld pages in use)\n", Sfprintf(out, "Total memory in use (I+II+III): %10ld bytes (%ld pages in use)\n",
total_bytes, Pg_str_in_use(GLOBAL_pages_void)); total_bytes, Pg_str_in_use(GLOBAL_pages_void));
fprintf(Yap_stdout, "Total memory allocated: %10ld bytes (%ld pages in total)\n", Sfprintf(out, "Total memory allocated: %10ld bytes (%ld pages in total)\n",
Pg_pg_alloc(GLOBAL_pages_void) * Yap_page_size, Pg_pg_alloc(GLOBAL_pages_void)); Pg_pg_alloc(GLOBAL_pages_void) * Yap_page_size, Pg_pg_alloc(GLOBAL_pages_void));
#else #else
fprintf(Yap_stdout, "Total memory in use (I+II+III): %10ld bytes\n", total_bytes); Sfprintf(out, "Total memory in use (I+II+III): %10ld bytes\n", total_bytes);
#endif /* USE_PAGES_MALLOC */ #endif /* USE_PAGES_MALLOC */
fflush(Yap_stdout);
return (TRUE); return (TRUE);
} }
static Int p_show_statistics_global_trie( USES_REGS1 ) { static Int p_show_statistics_global_trie( USES_REGS1 ) {
show_global_trie(SHOW_MODE_STATISTICS); IOSTREAM *out;
if ((out = YAP_TermToStream(Deref(ARG1))) == NULL)
return (FALSE);
show_global_trie(SHOW_MODE_STATISTICS, out);
return (TRUE); return (TRUE);
} }
#endif /* TABLING */ #endif /* TABLING */
@ -640,32 +657,33 @@ static Int p_performance( USES_REGS1 ) {
return(FALSE); return(FALSE);
if (GLOBAL_number_goals) { if (GLOBAL_number_goals) {
fprintf(Yap_stdout, "[\n Best execution times:\n"); Sfprintf(Soutput, "[\n Best execution times:\n");
for (i = 1; i <= GLOBAL_number_goals; i++) { for (i = 1; i <= GLOBAL_number_goals; i++) {
fprintf(Yap_stdout, " %d. time: %f seconds", i, GLOBAL_best_times(i)); Sfprintf(Soutput, " %d. time: %f seconds", i, GLOBAL_best_times(i));
if (one_worker_execution_time != 0) if (one_worker_execution_time != 0)
fprintf(Yap_stdout, " --> speedup %f (%6.2f %% )\n", Sfprintf(Soutput, " --> speedup %f (%6.2f %% )\n",
one_worker_execution_time / GLOBAL_best_times(i), one_worker_execution_time / GLOBAL_best_times(i),
one_worker_execution_time / GLOBAL_best_times(i) / GLOBAL_number_workers* 100 ); one_worker_execution_time / GLOBAL_best_times(i) / GLOBAL_number_workers* 100 );
else fprintf(Yap_stdout, "\n"); else Sfprintf(Soutput, "\n");
} }
fprintf(Yap_stdout, " Average : %f seconds", Sfprintf(Soutput, " Average : %f seconds",
GLOBAL_best_times(0) / GLOBAL_number_goals); GLOBAL_best_times(0) / GLOBAL_number_goals);
if (one_worker_execution_time != 0) if (one_worker_execution_time != 0)
fprintf(Yap_stdout, " --> speedup %f (%6.2f %% )", Sfprintf(Soutput, " --> speedup %f (%6.2f %% )",
one_worker_execution_time * GLOBAL_number_goals / GLOBAL_best_times(0), one_worker_execution_time * GLOBAL_number_goals / GLOBAL_best_times(0),
one_worker_execution_time * GLOBAL_number_goals / GLOBAL_best_times(0) / GLOBAL_number_workers* 100 ); one_worker_execution_time * GLOBAL_number_goals / GLOBAL_best_times(0) / GLOBAL_number_workers* 100 );
if (GLOBAL_number_goals >= 3) { if (GLOBAL_number_goals >= 3) {
fprintf(Yap_stdout, "\n Average (best three): %f seconds", Sfprintf(Soutput, "\n Average (best three): %f seconds",
(GLOBAL_best_times(1) + GLOBAL_best_times(2) + GLOBAL_best_times(3)) / 3); (GLOBAL_best_times(1) + GLOBAL_best_times(2) + GLOBAL_best_times(3)) / 3);
if (one_worker_execution_time != 0) if (one_worker_execution_time != 0)
fprintf(Yap_stdout, " --> speedup %f (%6.2f %% ) ]\n\n", Sfprintf(Soutput, " --> speedup %f (%6.2f %% ) ]\n\n",
one_worker_execution_time * 3 / (GLOBAL_best_times(1) + GLOBAL_best_times(2) + GLOBAL_best_times(3)), one_worker_execution_time * 3 / (GLOBAL_best_times(1) + GLOBAL_best_times(2) + GLOBAL_best_times(3)),
one_worker_execution_time * 3 / (GLOBAL_best_times(1) + GLOBAL_best_times(2) + GLOBAL_best_times(3)) / GLOBAL_number_workers* 100 ); one_worker_execution_time * 3 / (GLOBAL_best_times(1) + GLOBAL_best_times(2) + GLOBAL_best_times(3)) / GLOBAL_number_workers* 100 );
else fprintf(Yap_stdout, "\n]\n\n"); else Sfprintf(Soutput, "\n]\n\n");
} else fprintf(Yap_stdout, "\n]\n\n"); } else Sfprintf(Soutput, "\n]\n\n");
Sflush(Soutput);
return (TRUE); return (TRUE);
} }
return (FALSE); return (FALSE);
@ -700,28 +718,30 @@ static Int p_parallel_yes_answer( USES_REGS1 ) {
static Int p_show_statistics_or( USES_REGS1 ) { static Int p_show_statistics_or( USES_REGS1 ) {
IOSTREAM *out;
long total_bytes = 0, aux_bytes; long total_bytes = 0, aux_bytes;
if ((out = YAP_TermToStream(Deref(ARG1))) == NULL)
return (FALSE);
aux_bytes = 0; aux_bytes = 0;
fprintf(Yap_stdout, "Execution data structures\n"); Sfprintf(out, "Execution data structures\n");
aux_bytes += show_statistics_or_frames(); aux_bytes += show_statistics_or_frames(out);
fprintf(Yap_stdout, " Memory in use (I): %10ld bytes\n\n", aux_bytes); Sfprintf(out, " Memory in use (I): %10ld bytes\n\n", aux_bytes);
total_bytes += aux_bytes; total_bytes += aux_bytes;
aux_bytes = 0; aux_bytes = 0;
fprintf(Yap_stdout, "Cut support data structures\n"); Sfprintf(out, "Cut support data structures\n");
aux_bytes += show_statistics_query_goal_solution_frames(); aux_bytes += show_statistics_query_goal_solution_frames(out);
aux_bytes += show_statistics_query_goal_answer_frames(); aux_bytes += show_statistics_query_goal_answer_frames(out);
fprintf(Yap_stdout, " Memory in use (II): %10ld bytes\n\n", aux_bytes); Sfprintf(out, " Memory in use (II): %10ld bytes\n\n", aux_bytes);
total_bytes += aux_bytes; total_bytes += aux_bytes;
#ifdef USE_PAGES_MALLOC #ifdef USE_PAGES_MALLOC
fprintf(Yap_stdout, "Total memory in use (I+II+III): %10ld bytes (%ld pages in use)\n", Sfprintf(out, "Total memory in use (I+II+III): %10ld bytes (%ld pages in use)\n",
total_bytes, Pg_str_in_use(GLOBAL_pages_void)); total_bytes, Pg_str_in_use(GLOBAL_pages_void));
fprintf(Yap_stdout, "Total memory allocated: %10ld bytes (%ld pages in total)\n", Sfprintf(out, "Total memory allocated: %10ld bytes (%ld pages in total)\n",
Pg_pg_alloc(GLOBAL_pages_void) * Yap_page_size, Pg_pg_alloc(GLOBAL_pages_void)); Pg_pg_alloc(GLOBAL_pages_void) * Yap_page_size, Pg_pg_alloc(GLOBAL_pages_void));
#else #else
fprintf(Yap_stdout, "Total memory in use (I+II+III): %10ld bytes\n", total_bytes); Sfprintf(out, "Total memory in use (I+II+III): %10ld bytes\n", total_bytes);
#endif /* USE_PAGES_MALLOC */ #endif /* USE_PAGES_MALLOC */
return (TRUE); return (TRUE);
} }
#endif /* YAPOR */ #endif /* YAPOR */
@ -734,50 +754,52 @@ static Int p_show_statistics_or( USES_REGS1 ) {
#if defined(YAPOR) && defined(TABLING) #if defined(YAPOR) && defined(TABLING)
static Int p_show_statistics_opt( USES_REGS1 ) { static Int p_show_statistics_opt( USES_REGS1 ) {
IOSTREAM *out;
long total_bytes = 0, aux_bytes; long total_bytes = 0, aux_bytes;
if ((out = YAP_TermToStream(Deref(ARG1))) == NULL)
return (FALSE);
aux_bytes = 0; aux_bytes = 0;
fprintf(Yap_stdout, "Execution data structures\n"); Sfprintf(out, "Execution data structures\n");
aux_bytes += show_statistics_table_entries(); aux_bytes += show_statistics_table_entries(out);
aux_bytes += show_statistics_subgoal_frames(); aux_bytes += show_statistics_subgoal_frames(out);
aux_bytes += show_statistics_dependency_frames(); aux_bytes += show_statistics_dependency_frames(out);
aux_bytes += show_statistics_or_frames(); aux_bytes += show_statistics_or_frames(out);
aux_bytes += show_statistics_suspension_frames(); aux_bytes += show_statistics_suspension_frames(out);
fprintf(Yap_stdout, " Memory in use (I): %10ld bytes\n\n", aux_bytes); Sfprintf(out, " Memory in use (I): %10ld bytes\n\n", aux_bytes);
total_bytes += aux_bytes; total_bytes += aux_bytes;
aux_bytes = 0; aux_bytes = 0;
fprintf(Yap_stdout, "Local trie data structures\n"); Sfprintf(out, "Local trie data structures\n");
aux_bytes += show_statistics_subgoal_trie_nodes(); aux_bytes += show_statistics_subgoal_trie_nodes(out);
aux_bytes += show_statistics_answer_trie_nodes(); aux_bytes += show_statistics_answer_trie_nodes(out);
aux_bytes += show_statistics_subgoal_trie_hashes(); aux_bytes += show_statistics_subgoal_trie_hashes(out);
aux_bytes += show_statistics_answer_trie_hashes(); aux_bytes += show_statistics_answer_trie_hashes(out);
fprintf(Yap_stdout, " Memory in use (II): %10ld bytes\n\n", aux_bytes); Sfprintf(out, " Memory in use (II): %10ld bytes\n\n", aux_bytes);
total_bytes += aux_bytes; total_bytes += aux_bytes;
aux_bytes = 0; aux_bytes = 0;
fprintf(Yap_stdout, "Global trie data structures\n"); Sfprintf(out, "Global trie data structures\n");
aux_bytes += show_statistics_global_trie_nodes(); aux_bytes += show_statistics_global_trie_nodes(out);
aux_bytes += show_statistics_global_trie_hashes(); aux_bytes += show_statistics_global_trie_hashes(out);
fprintf(Yap_stdout, " Memory in use (III): %10ld bytes\n\n", aux_bytes); Sfprintf(out, " Memory in use (III): %10ld bytes\n\n", aux_bytes);
total_bytes += aux_bytes; total_bytes += aux_bytes;
aux_bytes = 0; aux_bytes = 0;
fprintf(Yap_stdout, "Cut support data structures\n"); Sfprintf(out, "Cut support data structures\n");
aux_bytes += show_statistics_query_goal_solution_frames(); aux_bytes += show_statistics_query_goal_solution_frames(out);
aux_bytes += show_statistics_query_goal_answer_frames(); aux_bytes += show_statistics_query_goal_answer_frames(out);
#ifdef TABLING_INNER_CUTS #ifdef TABLING_INNER_CUTS
aux_bytes += show_statistics_table_subgoal_solution_frames(); aux_bytes += show_statistics_table_subgoal_solution_frames(out);
aux_bytes += show_statistics_table_subgoal_answer_frames(); aux_bytes += show_statistics_table_subgoal_answer_frames(out);
#endif /* TABLING_INNER_CUTS */ #endif /* TABLING_INNER_CUTS */
fprintf(Yap_stdout, " Memory in use (IV): %10ld bytes\n\n", aux_bytes); Sfprintf(out, " Memory in use (IV): %10ld bytes\n\n", aux_bytes);
total_bytes += aux_bytes; total_bytes += aux_bytes;
#ifdef USE_PAGES_MALLOC #ifdef USE_PAGES_MALLOC
fprintf(Yap_stdout, "Total memory in use (I+II+III+IV): %10ld bytes (%ld pages in use)\n", Sfprintf(out, "Total memory in use (I+II+III+IV): %10ld bytes (%ld pages in use)\n",
total_bytes, Pg_str_in_use(GLOBAL_pages_void)); total_bytes, Pg_str_in_use(GLOBAL_pages_void));
fprintf(Yap_stdout, "Total memory allocated: %10ld bytes (%ld pages in total)\n", Sfprintf(out, "Total memory allocated: %10ld bytes (%ld pages in total)\n",
Pg_pg_alloc(GLOBAL_pages_void) * Yap_page_size, Pg_pg_alloc(GLOBAL_pages_void)); Pg_pg_alloc(GLOBAL_pages_void) * Yap_page_size, Pg_pg_alloc(GLOBAL_pages_void));
#else #else
fprintf(Yap_stdout, "Total memory in use (I+II+III+IV): %10ld bytes\n", total_bytes); Sfprintf(out, "Total memory in use (I+II+III+IV): %10ld bytes\n", total_bytes);
#endif /* USE_PAGES_MALLOC */ #endif /* USE_PAGES_MALLOC */
return (TRUE); return (TRUE);
} }
#endif /* YAPOR && TABLING */ #endif /* YAPOR && TABLING */
@ -945,19 +967,20 @@ static inline void show_answers(void) {
} }
switch(GLOBAL_answers) { switch(GLOBAL_answers) {
case YES_ANSWER: case YES_ANSWER:
fprintf(Yap_stderr, "[ yes"); Sfprintf(Serror, "[ yes");
break; break;
case NO_ANSWER: case NO_ANSWER:
fprintf(Yap_stderr, "[ no"); Sfprintf(Serror, "[ no");
break; break;
case 1: case 1:
fprintf(Yap_stderr, "[ 1 answer found"); Sfprintf(Serror, "[ 1 answer found");
break; break;
default: default:
fprintf(Yap_stderr, "[ %d answers found", GLOBAL_answers); Sfprintf(Serror, "[ %d answers found", GLOBAL_answers);
break; break;
} }
fprintf(Yap_stderr, " (in %f seconds) ]\n\n", GLOBAL_execution_time); Sfprintf(Serror, " (in %f seconds) ]\n\n", GLOBAL_execution_time);
Sflush(Serror);
if (GLOBAL_performance_mode == PERFORMANCE_ON) { if (GLOBAL_performance_mode == PERFORMANCE_ON) {
for (i = GLOBAL_number_goals; i > 0; i--) { for (i = GLOBAL_number_goals; i > 0; i--) {
@ -1017,14 +1040,15 @@ static inline void answer_to_stdout(char *answer) {
else break; else break;
} }
output[length_output] = 0; output[length_output] = 0;
fprintf(Yap_stderr, " %s\n", output); Sfprintf(Serror, " %s\n", output);
Sflush(Serror);
return; return;
} }
#endif /* YAPOR */ #endif /* YAPOR */
#ifdef TABLING #ifdef TABLING
static inline long show_statistics_table_entries(void) { static inline long show_statistics_table_entries(IOSTREAM *out) {
#ifdef USE_PAGES_MALLOC #ifdef USE_PAGES_MALLOC
#ifdef DEBUG_TABLING #ifdef DEBUG_TABLING
pg_hd_ptr pg_hd; pg_hd_ptr pg_hd;
@ -1042,17 +1066,17 @@ static inline long show_statistics_table_entries(void) {
} }
TABLING_ERROR_CHECKING(statistics_table_entries, Pg_str_free(GLOBAL_pages_tab_ent) != cont); TABLING_ERROR_CHECKING(statistics_table_entries, Pg_str_free(GLOBAL_pages_tab_ent) != cont);
#endif /* DEBUG_TABLING */ #endif /* DEBUG_TABLING */
fprintf(Yap_stdout, " Table entries: %10ld bytes (%ld pages and %ld structs in use)\n", Sfprintf(out, " Table entries: %10ld bytes (%ld pages and %ld structs in use)\n",
Pg_str_in_use(GLOBAL_pages_tab_ent) * sizeof(struct table_entry), Pg_pg_alloc(GLOBAL_pages_tab_ent), Pg_str_in_use(GLOBAL_pages_tab_ent)); Pg_str_in_use(GLOBAL_pages_tab_ent) * sizeof(struct table_entry), Pg_pg_alloc(GLOBAL_pages_tab_ent), Pg_str_in_use(GLOBAL_pages_tab_ent));
#else #else
fprintf(Yap_stdout, " Table entries: %10ld bytes (%ld structs in use)\n", Sfprintf(out, " Table entries: %10ld bytes (%ld structs in use)\n",
Pg_str_in_use(GLOBAL_pages_tab_ent) * sizeof(struct table_entry), Pg_str_in_use(GLOBAL_pages_tab_ent)); Pg_str_in_use(GLOBAL_pages_tab_ent) * sizeof(struct table_entry), Pg_str_in_use(GLOBAL_pages_tab_ent));
#endif /* USE_PAGES_MALLOC */ #endif /* USE_PAGES_MALLOC */
return Pg_str_in_use(GLOBAL_pages_tab_ent) * sizeof(struct table_entry); return Pg_str_in_use(GLOBAL_pages_tab_ent) * sizeof(struct table_entry);
} }
static inline long show_statistics_subgoal_frames(void) { static inline long show_statistics_subgoal_frames(IOSTREAM *out) {
#ifdef USE_PAGES_MALLOC #ifdef USE_PAGES_MALLOC
#ifdef DEBUG_TABLING #ifdef DEBUG_TABLING
pg_hd_ptr pg_hd; pg_hd_ptr pg_hd;
@ -1070,17 +1094,17 @@ static inline long show_statistics_subgoal_frames(void) {
} }
TABLING_ERROR_CHECKING(statistics_subgoal_frames, Pg_str_free(GLOBAL_pages_sg_fr) != cont); TABLING_ERROR_CHECKING(statistics_subgoal_frames, Pg_str_free(GLOBAL_pages_sg_fr) != cont);
#endif /* DEBUG_TABLING */ #endif /* DEBUG_TABLING */
fprintf(Yap_stdout, " Subgoal frames: %10ld bytes (%ld pages and %ld structs in use)\n", Sfprintf(out, " Subgoal frames: %10ld bytes (%ld pages and %ld structs in use)\n",
Pg_str_in_use(GLOBAL_pages_sg_fr) * sizeof(struct subgoal_frame), Pg_pg_alloc(GLOBAL_pages_sg_fr), Pg_str_in_use(GLOBAL_pages_sg_fr)); Pg_str_in_use(GLOBAL_pages_sg_fr) * sizeof(struct subgoal_frame), Pg_pg_alloc(GLOBAL_pages_sg_fr), Pg_str_in_use(GLOBAL_pages_sg_fr));
#else #else
fprintf(Yap_stdout, " Subgoal frames: %10ld bytes (%ld structs in use)\n", Sfprintf(out, " Subgoal frames: %10ld bytes (%ld structs in use)\n",
Pg_str_in_use(GLOBAL_pages_sg_fr) * sizeof(struct subgoal_frame), Pg_str_in_use(GLOBAL_pages_sg_fr)); Pg_str_in_use(GLOBAL_pages_sg_fr) * sizeof(struct subgoal_frame), Pg_str_in_use(GLOBAL_pages_sg_fr));
#endif /* USE_PAGES_MALLOC */ #endif /* USE_PAGES_MALLOC */
return Pg_str_in_use(GLOBAL_pages_sg_fr) * sizeof(struct subgoal_frame); return Pg_str_in_use(GLOBAL_pages_sg_fr) * sizeof(struct subgoal_frame);
} }
static inline long show_statistics_dependency_frames(void) { static inline long show_statistics_dependency_frames(IOSTREAM *out) {
#ifdef USE_PAGES_MALLOC #ifdef USE_PAGES_MALLOC
#ifdef DEBUG_TABLING #ifdef DEBUG_TABLING
pg_hd_ptr pg_hd; pg_hd_ptr pg_hd;
@ -1098,17 +1122,17 @@ static inline long show_statistics_dependency_frames(void) {
} }
TABLING_ERROR_CHECKING(statistics_dependency_frames, Pg_str_free(GLOBAL_pages_dep_fr) != cont); TABLING_ERROR_CHECKING(statistics_dependency_frames, Pg_str_free(GLOBAL_pages_dep_fr) != cont);
#endif /* DEBUG_TABLING */ #endif /* DEBUG_TABLING */
fprintf(Yap_stdout, " Dependency frames: %10ld bytes (%ld pages and %ld structs in use)\n", Sfprintf(out, " Dependency frames: %10ld bytes (%ld pages and %ld structs in use)\n",
Pg_str_in_use(GLOBAL_pages_dep_fr) * sizeof(struct dependency_frame), Pg_pg_alloc(GLOBAL_pages_dep_fr), Pg_str_in_use(GLOBAL_pages_dep_fr)); Pg_str_in_use(GLOBAL_pages_dep_fr) * sizeof(struct dependency_frame), Pg_pg_alloc(GLOBAL_pages_dep_fr), Pg_str_in_use(GLOBAL_pages_dep_fr));
#else #else
fprintf(Yap_stdout, " Dependency frames: %10ld bytes (%ld structs in use)\n", Sfprintf(out, " Dependency frames: %10ld bytes (%ld structs in use)\n",
Pg_str_in_use(GLOBAL_pages_dep_fr) * sizeof(struct dependency_frame), Pg_str_in_use(GLOBAL_pages_dep_fr)); Pg_str_in_use(GLOBAL_pages_dep_fr) * sizeof(struct dependency_frame), Pg_str_in_use(GLOBAL_pages_dep_fr));
#endif /* USE_PAGES_MALLOC */ #endif /* USE_PAGES_MALLOC */
return Pg_str_in_use(GLOBAL_pages_dep_fr) * sizeof(struct dependency_frame); return Pg_str_in_use(GLOBAL_pages_dep_fr) * sizeof(struct dependency_frame);
} }
static inline long show_statistics_subgoal_trie_nodes(void) { static inline long show_statistics_subgoal_trie_nodes(IOSTREAM *out) {
#ifdef USE_PAGES_MALLOC #ifdef USE_PAGES_MALLOC
#ifdef DEBUG_TABLING #ifdef DEBUG_TABLING
pg_hd_ptr pg_hd; pg_hd_ptr pg_hd;
@ -1126,17 +1150,17 @@ static inline long show_statistics_subgoal_trie_nodes(void) {
} }
TABLING_ERROR_CHECKING(statistics_subgoal_trie_nodes, Pg_str_free(GLOBAL_pages_sg_node) != cont); TABLING_ERROR_CHECKING(statistics_subgoal_trie_nodes, Pg_str_free(GLOBAL_pages_sg_node) != cont);
#endif /* DEBUG_TABLING */ #endif /* DEBUG_TABLING */
fprintf(Yap_stdout, " Subgoal trie nodes: %10ld bytes (%ld pages and %ld structs in use)\n", Sfprintf(out, " Subgoal trie nodes: %10ld bytes (%ld pages and %ld structs in use)\n",
Pg_str_in_use(GLOBAL_pages_sg_node) * sizeof(struct subgoal_trie_node), Pg_pg_alloc(GLOBAL_pages_sg_node), Pg_str_in_use(GLOBAL_pages_sg_node)); Pg_str_in_use(GLOBAL_pages_sg_node) * sizeof(struct subgoal_trie_node), Pg_pg_alloc(GLOBAL_pages_sg_node), Pg_str_in_use(GLOBAL_pages_sg_node));
#else #else
fprintf(Yap_stdout, " Subgoal trie nodes: %10ld bytes (%ld structs in use)\n", Sfprintf(out, " Subgoal trie nodes: %10ld bytes (%ld structs in use)\n",
Pg_str_in_use(GLOBAL_pages_sg_node) * sizeof(struct subgoal_trie_node), Pg_str_in_use(GLOBAL_pages_sg_node)); Pg_str_in_use(GLOBAL_pages_sg_node) * sizeof(struct subgoal_trie_node), Pg_str_in_use(GLOBAL_pages_sg_node));
#endif /* USE_PAGES_MALLOC */ #endif /* USE_PAGES_MALLOC */
return Pg_str_in_use(GLOBAL_pages_sg_node) * sizeof(struct subgoal_trie_node); return Pg_str_in_use(GLOBAL_pages_sg_node) * sizeof(struct subgoal_trie_node);
} }
static inline long show_statistics_answer_trie_nodes(void) { static inline long show_statistics_answer_trie_nodes(IOSTREAM *out) {
#ifdef USE_PAGES_MALLOC #ifdef USE_PAGES_MALLOC
#ifdef DEBUG_TABLING #ifdef DEBUG_TABLING
pg_hd_ptr pg_hd; pg_hd_ptr pg_hd;
@ -1154,17 +1178,17 @@ static inline long show_statistics_answer_trie_nodes(void) {
} }
TABLING_ERROR_CHECKING(statistics_answer_trie_nodes, Pg_str_free(GLOBAL_pages_ans_node) != cont); TABLING_ERROR_CHECKING(statistics_answer_trie_nodes, Pg_str_free(GLOBAL_pages_ans_node) != cont);
#endif /* DEBUG_TABLING */ #endif /* DEBUG_TABLING */
fprintf(Yap_stdout, " Answer trie nodes: %10ld bytes (%ld pages and %ld structs in use)\n", Sfprintf(out, " Answer trie nodes: %10ld bytes (%ld pages and %ld structs in use)\n",
Pg_str_in_use(GLOBAL_pages_ans_node) * sizeof(struct answer_trie_node), Pg_pg_alloc(GLOBAL_pages_ans_node), Pg_str_in_use(GLOBAL_pages_ans_node)); Pg_str_in_use(GLOBAL_pages_ans_node) * sizeof(struct answer_trie_node), Pg_pg_alloc(GLOBAL_pages_ans_node), Pg_str_in_use(GLOBAL_pages_ans_node));
#else #else
fprintf(Yap_stdout, " Answer trie nodes: %10ld bytes (%ld structs in use)\n", Sfprintf(out, " Answer trie nodes: %10ld bytes (%ld structs in use)\n",
Pg_str_in_use(GLOBAL_pages_ans_node) * sizeof(struct answer_trie_node), Pg_str_in_use(GLOBAL_pages_ans_node)); Pg_str_in_use(GLOBAL_pages_ans_node) * sizeof(struct answer_trie_node), Pg_str_in_use(GLOBAL_pages_ans_node));
#endif /* USE_PAGES_MALLOC */ #endif /* USE_PAGES_MALLOC */
return Pg_str_in_use(GLOBAL_pages_ans_node) * sizeof(struct answer_trie_node); return Pg_str_in_use(GLOBAL_pages_ans_node) * sizeof(struct answer_trie_node);
} }
static inline long show_statistics_subgoal_trie_hashes(void) { static inline long show_statistics_subgoal_trie_hashes(IOSTREAM *out) {
#ifdef USE_PAGES_MALLOC #ifdef USE_PAGES_MALLOC
#ifdef DEBUG_TABLING #ifdef DEBUG_TABLING
pg_hd_ptr pg_hd; pg_hd_ptr pg_hd;
@ -1182,17 +1206,17 @@ static inline long show_statistics_subgoal_trie_hashes(void) {
} }
TABLING_ERROR_CHECKING(statistics_subgoal_trie_hashes, Pg_str_free(GLOBAL_pages_sg_hash) != cont); TABLING_ERROR_CHECKING(statistics_subgoal_trie_hashes, Pg_str_free(GLOBAL_pages_sg_hash) != cont);
#endif /* DEBUG_TABLING */ #endif /* DEBUG_TABLING */
fprintf(Yap_stdout, " Subgoal trie hashes: %10ld bytes (%ld pages and %ld structs in use)\n", Sfprintf(out, " Subgoal trie hashes: %10ld bytes (%ld pages and %ld structs in use)\n",
Pg_str_in_use(GLOBAL_pages_sg_hash) * sizeof(struct subgoal_trie_hash), Pg_pg_alloc(GLOBAL_pages_sg_hash), Pg_str_in_use(GLOBAL_pages_sg_hash)); Pg_str_in_use(GLOBAL_pages_sg_hash) * sizeof(struct subgoal_trie_hash), Pg_pg_alloc(GLOBAL_pages_sg_hash), Pg_str_in_use(GLOBAL_pages_sg_hash));
#else #else
fprintf(Yap_stdout, " Subgoal trie hashes: %10ld bytes (%ld structs in use)\n", Sfprintf(out, " Subgoal trie hashes: %10ld bytes (%ld structs in use)\n",
Pg_str_in_use(GLOBAL_pages_sg_hash) * sizeof(struct subgoal_trie_hash), Pg_str_in_use(GLOBAL_pages_sg_hash)); Pg_str_in_use(GLOBAL_pages_sg_hash) * sizeof(struct subgoal_trie_hash), Pg_str_in_use(GLOBAL_pages_sg_hash));
#endif /* USE_PAGES_MALLOC */ #endif /* USE_PAGES_MALLOC */
return Pg_str_in_use(GLOBAL_pages_sg_hash) * sizeof(struct subgoal_trie_hash); return Pg_str_in_use(GLOBAL_pages_sg_hash) * sizeof(struct subgoal_trie_hash);
} }
static inline long show_statistics_answer_trie_hashes(void) { static inline long show_statistics_answer_trie_hashes(IOSTREAM *out) {
#ifdef USE_PAGES_MALLOC #ifdef USE_PAGES_MALLOC
#ifdef DEBUG_TABLING #ifdef DEBUG_TABLING
pg_hd_ptr pg_hd; pg_hd_ptr pg_hd;
@ -1210,17 +1234,17 @@ static inline long show_statistics_answer_trie_hashes(void) {
} }
TABLING_ERROR_CHECKING(statistics_answer_trie_hashes, Pg_str_free(GLOBAL_pages_ans_hash) != cont); TABLING_ERROR_CHECKING(statistics_answer_trie_hashes, Pg_str_free(GLOBAL_pages_ans_hash) != cont);
#endif /* DEBUG_TABLING */ #endif /* DEBUG_TABLING */
fprintf(Yap_stdout, " Answer trie hashes: %10ld bytes (%ld pages and %ld structs in use)\n", Sfprintf(out, " Answer trie hashes: %10ld bytes (%ld pages and %ld structs in use)\n",
Pg_str_in_use(GLOBAL_pages_ans_hash) * sizeof(struct answer_trie_hash), Pg_pg_alloc(GLOBAL_pages_ans_hash), Pg_str_in_use(GLOBAL_pages_ans_hash)); Pg_str_in_use(GLOBAL_pages_ans_hash) * sizeof(struct answer_trie_hash), Pg_pg_alloc(GLOBAL_pages_ans_hash), Pg_str_in_use(GLOBAL_pages_ans_hash));
#else #else
fprintf(Yap_stdout, " Answer trie hashes: %10ld bytes (%ld structs in use)\n", Sfprintf(out, " Answer trie hashes: %10ld bytes (%ld structs in use)\n",
Pg_str_in_use(GLOBAL_pages_ans_hash) * sizeof(struct answer_trie_hash), Pg_str_in_use(GLOBAL_pages_ans_hash)); Pg_str_in_use(GLOBAL_pages_ans_hash) * sizeof(struct answer_trie_hash), Pg_str_in_use(GLOBAL_pages_ans_hash));
#endif /* USE_PAGES_MALLOC */ #endif /* USE_PAGES_MALLOC */
return Pg_str_in_use(GLOBAL_pages_ans_hash) * sizeof(struct answer_trie_hash); return Pg_str_in_use(GLOBAL_pages_ans_hash) * sizeof(struct answer_trie_hash);
} }
static inline long show_statistics_global_trie_nodes(void) { static inline long show_statistics_global_trie_nodes(IOSTREAM *out) {
#ifdef USE_PAGES_MALLOC #ifdef USE_PAGES_MALLOC
#ifdef DEBUG_TABLING #ifdef DEBUG_TABLING
pg_hd_ptr pg_hd; pg_hd_ptr pg_hd;
@ -1238,17 +1262,17 @@ static inline long show_statistics_global_trie_nodes(void) {
} }
TABLING_ERROR_CHECKING(statistics_global_trie_nodes, Pg_str_free(GLOBAL_pages_gt_node) != cont); TABLING_ERROR_CHECKING(statistics_global_trie_nodes, Pg_str_free(GLOBAL_pages_gt_node) != cont);
#endif /* DEBUG_TABLING */ #endif /* DEBUG_TABLING */
fprintf(Yap_stdout, " Global trie nodes: %10ld bytes (%ld pages and %ld structs in use)\n", Sfprintf(out, " Global trie nodes: %10ld bytes (%ld pages and %ld structs in use)\n",
Pg_str_in_use(GLOBAL_pages_gt_node) * sizeof(struct global_trie_node), Pg_pg_alloc(GLOBAL_pages_gt_node), Pg_str_in_use(GLOBAL_pages_gt_node)); Pg_str_in_use(GLOBAL_pages_gt_node) * sizeof(struct global_trie_node), Pg_pg_alloc(GLOBAL_pages_gt_node), Pg_str_in_use(GLOBAL_pages_gt_node));
#else #else
fprintf(Yap_stdout, " Global trie nodes: %10ld bytes (%ld structs in use)\n", Sfprintf(out, " Global trie nodes: %10ld bytes (%ld structs in use)\n",
Pg_str_in_use(GLOBAL_pages_gt_node) * sizeof(struct global_trie_node), Pg_str_in_use(GLOBAL_pages_gt_node)); Pg_str_in_use(GLOBAL_pages_gt_node) * sizeof(struct global_trie_node), Pg_str_in_use(GLOBAL_pages_gt_node));
#endif /* USE_PAGES_MALLOC */ #endif /* USE_PAGES_MALLOC */
return Pg_str_in_use(GLOBAL_pages_gt_node) * sizeof(struct global_trie_node); return Pg_str_in_use(GLOBAL_pages_gt_node) * sizeof(struct global_trie_node);
} }
static inline long show_statistics_global_trie_hashes(void) { static inline long show_statistics_global_trie_hashes(IOSTREAM *out) {
#ifdef USE_PAGES_MALLOC #ifdef USE_PAGES_MALLOC
#ifdef DEBUG_TABLING #ifdef DEBUG_TABLING
pg_hd_ptr pg_hd; pg_hd_ptr pg_hd;
@ -1266,10 +1290,10 @@ static inline long show_statistics_global_trie_hashes(void) {
} }
TABLING_ERROR_CHECKING(statistics_global_trie_hashes, Pg_str_free(GLOBAL_pages_gt_hash) != cont); TABLING_ERROR_CHECKING(statistics_global_trie_hashes, Pg_str_free(GLOBAL_pages_gt_hash) != cont);
#endif /* DEBUG_TABLING */ #endif /* DEBUG_TABLING */
fprintf(Yap_stdout, " Global trie hashes: %10ld bytes (%ld pages and %ld structs in use)\n", Sfprintf(out, " Global trie hashes: %10ld bytes (%ld pages and %ld structs in use)\n",
Pg_str_in_use(GLOBAL_pages_gt_hash) * sizeof(struct global_trie_hash), Pg_pg_alloc(GLOBAL_pages_gt_hash), Pg_str_in_use(GLOBAL_pages_gt_hash)); Pg_str_in_use(GLOBAL_pages_gt_hash) * sizeof(struct global_trie_hash), Pg_pg_alloc(GLOBAL_pages_gt_hash), Pg_str_in_use(GLOBAL_pages_gt_hash));
#else #else
fprintf(Yap_stdout, " Global trie hashes: %10ld bytes (%ld structs in use)\n", Sfprintf(out, " Global trie hashes: %10ld bytes (%ld structs in use)\n",
Pg_str_in_use(GLOBAL_pages_gt_hash) * sizeof(struct global_trie_hash), Pg_str_in_use(GLOBAL_pages_gt_hash)); Pg_str_in_use(GLOBAL_pages_gt_hash) * sizeof(struct global_trie_hash), Pg_str_in_use(GLOBAL_pages_gt_hash));
#endif /* USE_PAGES_MALLOC */ #endif /* USE_PAGES_MALLOC */
return Pg_str_in_use(GLOBAL_pages_gt_hash) * sizeof(struct global_trie_hash); return Pg_str_in_use(GLOBAL_pages_gt_hash) * sizeof(struct global_trie_hash);
@ -1278,7 +1302,7 @@ static inline long show_statistics_global_trie_hashes(void) {
#ifdef YAPOR #ifdef YAPOR
static inline long show_statistics_or_frames(void) { static inline long show_statistics_or_frames(IOSTREAM *out) {
#ifdef USE_PAGES_MALLOC #ifdef USE_PAGES_MALLOC
#ifdef DEBUG_YAPOR #ifdef DEBUG_YAPOR
pg_hd_ptr pg_hd; pg_hd_ptr pg_hd;
@ -1296,17 +1320,17 @@ static inline long show_statistics_or_frames(void) {
} }
YAPOR_ERROR_CHECKING(statistics_or_frames, Pg_str_free(GLOBAL_pages_or_fr ) != cont); YAPOR_ERROR_CHECKING(statistics_or_frames, Pg_str_free(GLOBAL_pages_or_fr ) != cont);
#endif /* DEBUG_YAPOR */ #endif /* DEBUG_YAPOR */
fprintf(Yap_stdout, " Or-frames: %10ld bytes (%ld pages and %ld structs in use)\n", Sfprintf(out, " Or-frames: %10ld bytes (%ld pages and %ld structs in use)\n",
Pg_str_in_use(GLOBAL_pages_or_fr ) * sizeof(struct or_frame), Pg_pg_alloc(GLOBAL_pages_or_fr ), Pg_str_in_use(GLOBAL_pages_or_fr )); Pg_str_in_use(GLOBAL_pages_or_fr ) * sizeof(struct or_frame), Pg_pg_alloc(GLOBAL_pages_or_fr ), Pg_str_in_use(GLOBAL_pages_or_fr ));
#else #else
fprintf(Yap_stdout, " Or-frames: %10ld bytes (%ld structs in use)\n", Sfprintf(out, " Or-frames: %10ld bytes (%ld structs in use)\n",
Pg_str_in_use(GLOBAL_pages_or_fr ) * sizeof(struct or_frame), Pg_str_in_use(GLOBAL_pages_or_fr )); Pg_str_in_use(GLOBAL_pages_or_fr ) * sizeof(struct or_frame), Pg_str_in_use(GLOBAL_pages_or_fr ));
#endif /* USE_PAGES_MALLOC */ #endif /* USE_PAGES_MALLOC */
return Pg_str_in_use(GLOBAL_pages_or_fr ) * sizeof(struct or_frame); return Pg_str_in_use(GLOBAL_pages_or_fr ) * sizeof(struct or_frame);
} }
static inline long show_statistics_query_goal_solution_frames(void) { static inline long show_statistics_query_goal_solution_frames(IOSTREAM *out) {
#ifdef USE_PAGES_MALLOC #ifdef USE_PAGES_MALLOC
#ifdef DEBUG_YAPOR #ifdef DEBUG_YAPOR
pg_hd_ptr pg_hd; pg_hd_ptr pg_hd;
@ -1324,17 +1348,17 @@ static inline long show_statistics_query_goal_solution_frames(void) {
} }
YAPOR_ERROR_CHECKING(statistics_query_goal_solution_frames, Pg_str_free(GLOBAL_pages_qg_sol_fr ) != cont); YAPOR_ERROR_CHECKING(statistics_query_goal_solution_frames, Pg_str_free(GLOBAL_pages_qg_sol_fr ) != cont);
#endif /* DEBUG_YAPOR */ #endif /* DEBUG_YAPOR */
fprintf(Yap_stdout, " Query goal solution frames: %10ld bytes (%ld pages and %ld structs in use)\n", Sfprintf(out, " Query goal solution frames: %10ld bytes (%ld pages and %ld structs in use)\n",
Pg_str_in_use(GLOBAL_pages_qg_sol_fr ) * sizeof(struct query_goal_solution_frame), Pg_pg_alloc(GLOBAL_pages_qg_sol_fr ), Pg_str_in_use(GLOBAL_pages_qg_sol_fr )); Pg_str_in_use(GLOBAL_pages_qg_sol_fr ) * sizeof(struct query_goal_solution_frame), Pg_pg_alloc(GLOBAL_pages_qg_sol_fr ), Pg_str_in_use(GLOBAL_pages_qg_sol_fr ));
#else #else
fprintf(Yap_stdout, " Query goal solution frames: %10ld bytes (%ld structs in use)\n", Sfprintf(out, " Query goal solution frames: %10ld bytes (%ld structs in use)\n",
Pg_str_in_use(GLOBAL_pages_qg_sol_fr ) * sizeof(struct query_goal_solution_frame), Pg_str_in_use(GLOBAL_pages_qg_sol_fr )); Pg_str_in_use(GLOBAL_pages_qg_sol_fr ) * sizeof(struct query_goal_solution_frame), Pg_str_in_use(GLOBAL_pages_qg_sol_fr ));
#endif /* USE_PAGES_MALLOC */ #endif /* USE_PAGES_MALLOC */
return Pg_str_in_use(GLOBAL_pages_qg_sol_fr ) * sizeof(struct query_goal_solution_frame); return Pg_str_in_use(GLOBAL_pages_qg_sol_fr ) * sizeof(struct query_goal_solution_frame);
} }
static inline long show_statistics_query_goal_answer_frames(void) { static inline long show_statistics_query_goal_answer_frames(IOSTREAM *out) {
#ifdef USE_PAGES_MALLOC #ifdef USE_PAGES_MALLOC
#ifdef DEBUG_YAPOR #ifdef DEBUG_YAPOR
pg_hd_ptr pg_hd; pg_hd_ptr pg_hd;
@ -1352,10 +1376,10 @@ static inline long show_statistics_query_goal_answer_frames(void) {
} }
YAPOR_ERROR_CHECKING(statistics_query_goal_answer_frames, Pg_str_free(GLOBAL_pages_qg_ans_fr) != cont); YAPOR_ERROR_CHECKING(statistics_query_goal_answer_frames, Pg_str_free(GLOBAL_pages_qg_ans_fr) != cont);
#endif /* DEBUG_YAPOR */ #endif /* DEBUG_YAPOR */
fprintf(Yap_stdout, " Query goal answer frames: %10ld bytes (%ld pages and %ld structs in use)\n", Sfprintf(out, " Query goal answer frames: %10ld bytes (%ld pages and %ld structs in use)\n",
Pg_str_in_use(GLOBAL_pages_qg_ans_fr) * sizeof(struct query_goal_answer_frame), Pg_pg_alloc(GLOBAL_pages_qg_ans_fr), Pg_str_in_use(GLOBAL_pages_qg_ans_fr)); Pg_str_in_use(GLOBAL_pages_qg_ans_fr) * sizeof(struct query_goal_answer_frame), Pg_pg_alloc(GLOBAL_pages_qg_ans_fr), Pg_str_in_use(GLOBAL_pages_qg_ans_fr));
#else #else
fprintf(Yap_stdout, " Query goal answer frames: %10ld bytes (%ld structs in use)\n", Sfprintf(out, " Query goal answer frames: %10ld bytes (%ld structs in use)\n",
Pg_str_in_use(GLOBAL_pages_qg_ans_fr) * sizeof(struct query_goal_answer_frame), Pg_str_in_use(GLOBAL_pages_qg_ans_fr)); Pg_str_in_use(GLOBAL_pages_qg_ans_fr) * sizeof(struct query_goal_answer_frame), Pg_str_in_use(GLOBAL_pages_qg_ans_fr));
#endif /* USE_PAGES_MALLOC */ #endif /* USE_PAGES_MALLOC */
return Pg_str_in_use(GLOBAL_pages_qg_ans_fr) * sizeof(struct query_goal_answer_frame); return Pg_str_in_use(GLOBAL_pages_qg_ans_fr) * sizeof(struct query_goal_answer_frame);
@ -1364,7 +1388,7 @@ static inline long show_statistics_query_goal_answer_frames(void) {
#if defined(YAPOR) && defined(TABLING) #if defined(YAPOR) && defined(TABLING)
static inline long show_statistics_suspension_frames(void) { static inline long show_statistics_suspension_frames(IOSTREAM *out) {
#ifdef USE_PAGES_MALLOC #ifdef USE_PAGES_MALLOC
#ifdef DEBUG_OPTYAP #ifdef DEBUG_OPTYAP
pg_hd_ptr pg_hd; pg_hd_ptr pg_hd;
@ -1382,10 +1406,10 @@ static inline long show_statistics_suspension_frames(void) {
} }
OPTYAP_ERROR_CHECKING(statistics_suspension_frames, Pg_str_free(GLOBAL_pages_susp_fr) != cont); OPTYAP_ERROR_CHECKING(statistics_suspension_frames, Pg_str_free(GLOBAL_pages_susp_fr) != cont);
#endif /* DEBUG_OPTYAP */ #endif /* DEBUG_OPTYAP */
fprintf(Yap_stdout, " Suspension frames: %10ld bytes (%ld pages and %ld structs in use)\n", Sfprintf(out, " Suspension frames: %10ld bytes (%ld pages and %ld structs in use)\n",
Pg_str_in_use(GLOBAL_pages_susp_fr) * sizeof(struct suspension_frame), Pg_pg_alloc(GLOBAL_pages_susp_fr), Pg_str_in_use(GLOBAL_pages_susp_fr)); Pg_str_in_use(GLOBAL_pages_susp_fr) * sizeof(struct suspension_frame), Pg_pg_alloc(GLOBAL_pages_susp_fr), Pg_str_in_use(GLOBAL_pages_susp_fr));
#else #else
fprintf(Yap_stdout, " Suspension frames: %10ld bytes (%ld structs in use)\n", Sfprintf(out, " Suspension frames: %10ld bytes (%ld structs in use)\n",
Pg_str_in_use(GLOBAL_pages_susp_fr) * sizeof(struct suspension_frame), Pg_str_in_use(GLOBAL_pages_susp_fr)); Pg_str_in_use(GLOBAL_pages_susp_fr) * sizeof(struct suspension_frame), Pg_str_in_use(GLOBAL_pages_susp_fr));
#endif /* USE_PAGES_MALLOC */ #endif /* USE_PAGES_MALLOC */
return Pg_str_in_use(GLOBAL_pages_susp_fr) * sizeof(struct suspension_frame); return Pg_str_in_use(GLOBAL_pages_susp_fr) * sizeof(struct suspension_frame);
@ -1393,7 +1417,7 @@ static inline long show_statistics_suspension_frames(void) {
#ifdef TABLING_INNER_CUTS #ifdef TABLING_INNER_CUTS
static inline long show_statistics_table_subgoal_solution_frames(void) { static inline long show_statistics_table_subgoal_solution_frames(IOSTREAM *out) {
#ifdef USE_PAGES_MALLOC #ifdef USE_PAGES_MALLOC
#ifdef DEBUG_OPTYAP #ifdef DEBUG_OPTYAP
pg_hd_ptr pg_hd; pg_hd_ptr pg_hd;
@ -1411,17 +1435,17 @@ static inline long show_statistics_table_subgoal_solution_frames(void) {
} }
OPTYAP_ERROR_CHECKING(statistics_table_subgoal_solution_frames, Pg_str_free(GLOBAL_pages_tg_sol_fr) != cont); OPTYAP_ERROR_CHECKING(statistics_table_subgoal_solution_frames, Pg_str_free(GLOBAL_pages_tg_sol_fr) != cont);
#endif /* DEBUG_OPTYAP */ #endif /* DEBUG_OPTYAP */
fprintf(Yap_stdout, " Table subgoal solution frames: %10ld bytes (%ld pages and %ld structs in use)\n", Sfprintf(out, " Table subgoal solution frames: %10ld bytes (%ld pages and %ld structs in use)\n",
Pg_str_in_use(GLOBAL_pages_tg_sol_fr) * sizeof(struct table_subgoal_solution_frame), Pg_pg_alloc(GLOBAL_pages_tg_sol_fr), Pg_str_in_use(GLOBAL_pages_tg_sol_fr)); Pg_str_in_use(GLOBAL_pages_tg_sol_fr) * sizeof(struct table_subgoal_solution_frame), Pg_pg_alloc(GLOBAL_pages_tg_sol_fr), Pg_str_in_use(GLOBAL_pages_tg_sol_fr));
#else #else
fprintf(Yap_stdout, " Table subgoal solution frames: %10ld bytes (%ld structs in use)\n", Sfprintf(out, " Table subgoal solution frames: %10ld bytes (%ld structs in use)\n",
Pg_str_in_use(GLOBAL_pages_tg_sol_fr) * sizeof(struct table_subgoal_solution_frame), Pg_str_in_use(GLOBAL_pages_tg_sol_fr)); Pg_str_in_use(GLOBAL_pages_tg_sol_fr) * sizeof(struct table_subgoal_solution_frame), Pg_str_in_use(GLOBAL_pages_tg_sol_fr));
#endif /* USE_PAGES_MALLOC */ #endif /* USE_PAGES_MALLOC */
return Pg_str_in_use(GLOBAL_pages_tg_sol_fr) * sizeof(struct table_subgoal_solution_frame); return Pg_str_in_use(GLOBAL_pages_tg_sol_fr) * sizeof(struct table_subgoal_solution_frame);
} }
static inline long show_statistics_table_subgoal_answer_frames(void) { static inline long show_statistics_table_subgoal_answer_frames(IOSTREAM *out) {
#ifdef USE_PAGES_MALLOC #ifdef USE_PAGES_MALLOC
#ifdef DEBUG_OPTYAP #ifdef DEBUG_OPTYAP
pg_hd_ptr pg_hd; pg_hd_ptr pg_hd;
@ -1439,10 +1463,10 @@ static inline long show_statistics_table_subgoal_answer_frames(void) {
} }
OPTYAP_ERROR_CHECKING(statistics_table_subgoal_answer_frames, Pg_str_free(GLOBAL_pages_tg_ans_fr) != cont); OPTYAP_ERROR_CHECKING(statistics_table_subgoal_answer_frames, Pg_str_free(GLOBAL_pages_tg_ans_fr) != cont);
#endif /* DEBUG_OPTYAP */ #endif /* DEBUG_OPTYAP */
fprintf(Yap_stdout, " Table subgoal answer frames: %10ld bytes (%ld pages and %ld structs in use)\n", Sfprintf(out, " Table subgoal answer frames: %10ld bytes (%ld pages and %ld structs in use)\n",
Pg_str_in_use(GLOBAL_pages_tg_ans_fr) * sizeof(struct table_subgoal_answer_frame), Pg_pg_alloc(GLOBAL_pages_tg_ans_fr), Pg_str_in_use(GLOBAL_pages_tg_ans_fr)); Pg_str_in_use(GLOBAL_pages_tg_ans_fr) * sizeof(struct table_subgoal_answer_frame), Pg_pg_alloc(GLOBAL_pages_tg_ans_fr), Pg_str_in_use(GLOBAL_pages_tg_ans_fr));
#else #else
fprintf(Yap_stdout, " Table subgoal answer frames: %10ld bytes (%ld structs in use)\n", Sfprintf(out, " Table subgoal answer frames: %10ld bytes (%ld structs in use)\n",
Pg_str_in_use(GLOBAL_pages_tg_ans_fr) * sizeof(struct table_subgoal_answer_frame), Pg_str_in_use(GLOBAL_pages_tg_ans_fr)); Pg_str_in_use(GLOBAL_pages_tg_ans_fr) * sizeof(struct table_subgoal_answer_frame), Pg_str_in_use(GLOBAL_pages_tg_ans_fr));
#endif /* USE_PAGES_MALLOC */ #endif /* USE_PAGES_MALLOC */
return Pg_str_in_use(GLOBAL_pages_tg_ans_fr) * sizeof(struct table_subgoal_answer_frame); return Pg_str_in_use(GLOBAL_pages_tg_ans_fr) * sizeof(struct table_subgoal_answer_frame);

View File

@ -11,6 +11,12 @@
** ** ** **
************************************************************************/ ************************************************************************/
#ifdef TABLING
#include "SWI-Stream.h"
#endif /* TABLING */
/*************************** /***************************
** opt.memory.c ** ** opt.memory.c **
***************************/ ***************************/
@ -58,8 +64,8 @@ void free_subgoal_trie(sg_node_ptr, int, int);
void free_answer_trie(ans_node_ptr, int, int); void free_answer_trie(ans_node_ptr, int, int);
void free_subgoal_hash_chain(sg_hash_ptr); void free_subgoal_hash_chain(sg_hash_ptr);
void free_answer_hash_chain(ans_hash_ptr); void free_answer_hash_chain(ans_hash_ptr);
void show_table(tab_ent_ptr, int); void show_table(tab_ent_ptr, int, IOSTREAM *);
void show_global_trie(int); void show_global_trie(int, IOSTREAM *);
#endif /* TABLING */ #endif /* TABLING */

View File

@ -304,7 +304,7 @@
-> we need a shared data structure to avoid redundant computations! -> we need a shared data structure to avoid redundant computations!
UNLOCK_OR_FRAME(LOCAL_top_or_fr); UNLOCK_OR_FRAME(LOCAL_top_or_fr);
#else #else
fprintf(stderr,"PROBLEM: cp_last_answer field is local to the cp!\n"); Sfprintf(Serror, "PROBLEM: cp_last_answer field is local to the cp!\n");
exit(1); exit(1);
#endif #endif
} }

View File

@ -17,13 +17,8 @@
#include "Yap.h" #include "Yap.h"
#ifdef TABLING #ifdef TABLING
#include <stdio.h>
#ifdef HAVE_STRING_H
#include <string.h>
#endif /* HAVE_STRING_H */
#include "Yatom.h" #include "Yatom.h"
#include "YapHeap.h" #include "YapHeap.h"
#include "yapio.h"
#include "tab.macros.h" #include "tab.macros.h"
static inline sg_node_ptr subgoal_trie_check_insert_entry(tab_ent_ptr, sg_node_ptr, Term); static inline sg_node_ptr subgoal_trie_check_insert_entry(tab_ent_ptr, sg_node_ptr, Term);
@ -78,6 +73,7 @@ static inline void traverse_update_arity(char *, int *, int *);
*******************************/ *******************************/
static struct trie_statistics{ static struct trie_statistics{
IOSTREAM *out;
int show; int show;
long subgoals; long subgoals;
long subgoals_incomplete; long subgoals_incomplete;
@ -94,6 +90,7 @@ static struct trie_statistics{
long global_trie_references; long global_trie_references;
} trie_stats; } trie_stats;
#define TrStat_out trie_stats.out
#define TrStat_show trie_stats.show #define TrStat_show trie_stats.show
#define TrStat_subgoals trie_stats.subgoals #define TrStat_subgoals trie_stats.subgoals
#define TrStat_sg_incomplete trie_stats.subgoals_incomplete #define TrStat_sg_incomplete trie_stats.subgoals_incomplete
@ -110,7 +107,7 @@ static struct trie_statistics{
#define SHOW_TABLE_ARITY_ARRAY_SIZE 10000 #define SHOW_TABLE_ARITY_ARRAY_SIZE 10000
#define SHOW_TABLE_STRUCTURE(MESG, ARGS...) \ #define SHOW_TABLE_STRUCTURE(MESG, ARGS...) \
if (TrStat_show == SHOW_MODE_STRUCTURE) \ if (TrStat_show == SHOW_MODE_STRUCTURE) \
fprintf(Yap_stdout, MESG, ##ARGS) Sfprintf(TrStat_out, MESG, ##ARGS)
#define CHECK_DECREMENT_GLOBAL_TRIE_REFERENCE(REF,MODE) \ #define CHECK_DECREMENT_GLOBAL_TRIE_REFERENCE(REF,MODE) \
if (MODE == TRAVERSE_MODE_NORMAL && IsVarTerm(REF) && REF > VarIndexOfTableTerm(MAX_TABLE_VARS)) { \ if (MODE == TRAVERSE_MODE_NORMAL && IsVarTerm(REF) && REF > VarIndexOfTableTerm(MAX_TABLE_VARS)) { \
@ -1297,9 +1294,10 @@ void free_answer_hash_chain(ans_hash_ptr hash) {
} }
void show_table(tab_ent_ptr tab_ent, int show_mode) { void show_table(tab_ent_ptr tab_ent, int show_mode, IOSTREAM *out) {
sg_node_ptr sg_node; sg_node_ptr sg_node;
TrStat_out = out;
TrStat_show = show_mode; TrStat_show = show_mode;
if (show_mode == SHOW_MODE_STATISTICS) { if (show_mode == SHOW_MODE_STATISTICS) {
TrStat_subgoals = 0; TrStat_subgoals = 0;
@ -1313,9 +1311,9 @@ void show_table(tab_ent_ptr tab_ent, int show_mode) {
#endif /* TABLING_INNER_CUTS */ #endif /* TABLING_INNER_CUTS */
TrStat_ans_nodes = 0; TrStat_ans_nodes = 0;
TrStat_gt_refs = 0; TrStat_gt_refs = 0;
fprintf(Yap_stdout, "Table statistics for predicate '%s/%d'\n", AtomName(TabEnt_atom(tab_ent)), TabEnt_arity(tab_ent)); Sfprintf(TrStat_out, "Table statistics for predicate '%s/%d'\n", AtomName(TabEnt_atom(tab_ent)), TabEnt_arity(tab_ent));
} else { /* SHOW_MODE_STRUCTURE */ } else { /* SHOW_MODE_STRUCTURE */
fprintf(Yap_stdout, "Table structure for predicate '%s/%d'\n", AtomName(TabEnt_atom(tab_ent)), TabEnt_arity(tab_ent)); Sfprintf(TrStat_out, "Table structure for predicate '%s/%d'\n", AtomName(TabEnt_atom(tab_ent)), TabEnt_arity(tab_ent));
} }
sg_node = TrNode_child(TabEnt_subgoal_trie(tab_ent)); sg_node = TrNode_child(TabEnt_subgoal_trie(tab_ent));
if (sg_node) { if (sg_node) {
@ -1349,34 +1347,34 @@ void show_table(tab_ent_ptr tab_ent, int show_mode) {
} else } else
SHOW_TABLE_STRUCTURE(" EMPTY\n"); SHOW_TABLE_STRUCTURE(" EMPTY\n");
if (show_mode == SHOW_MODE_STATISTICS) { if (show_mode == SHOW_MODE_STATISTICS) {
fprintf(Yap_stdout, " Subgoal trie structure\n"); Sfprintf(TrStat_out, " Subgoal trie structure\n");
fprintf(Yap_stdout, " Subgoals: %ld (%ld incomplete)\n", TrStat_subgoals, TrStat_sg_incomplete); Sfprintf(TrStat_out, " Subgoals: %ld (%ld incomplete)\n", TrStat_subgoals, TrStat_sg_incomplete);
fprintf(Yap_stdout, " Subgoal trie nodes: %ld\n", TrStat_sg_nodes); Sfprintf(TrStat_out, " Subgoal trie nodes: %ld\n", TrStat_sg_nodes);
fprintf(Yap_stdout, " Answer trie structure(s)\n"); Sfprintf(TrStat_out, " Answer trie structure(s)\n");
#ifdef TABLING_INNER_CUTS #ifdef TABLING_INNER_CUTS
fprintf(Yap_stdout, " Answers: %ld (%ld pruned)\n", TrStat_answers, TrStat_answers_pruned); Sfprintf(TrStat_out, " Answers: %ld (%ld pruned)\n", TrStat_answers, TrStat_answers_pruned);
#else #else
fprintf(Yap_stdout, " Answers: %ld\n", TrStat_answers); Sfprintf(TrStat_out, " Answers: %ld\n", TrStat_answers);
#endif /* TABLING_INNER_CUTS */ #endif /* TABLING_INNER_CUTS */
fprintf(Yap_stdout, " Answers 'TRUE': %ld\n", TrStat_answers_true); Sfprintf(TrStat_out, " Answers 'TRUE': %ld\n", TrStat_answers_true);
fprintf(Yap_stdout, " Answers 'NO': %ld\n", TrStat_answers_no); Sfprintf(TrStat_out, " Answers 'NO': %ld\n", TrStat_answers_no);
fprintf(Yap_stdout, " Answer trie nodes: %ld\n", TrStat_ans_nodes); Sfprintf(TrStat_out, " Answer trie nodes: %ld\n", TrStat_ans_nodes);
fprintf(Yap_stdout, " Global trie references: %ld\n", TrStat_gt_refs); Sfprintf(TrStat_out, " Global trie references: %ld\n", TrStat_gt_refs);
} }
fflush(Yap_stdout);
return; return;
} }
void show_global_trie(int show_mode) { void show_global_trie(int show_mode, IOSTREAM *out) {
TrStat_out = out;
TrStat_show = show_mode; TrStat_show = show_mode;
if (show_mode == SHOW_MODE_STATISTICS) { if (show_mode == SHOW_MODE_STATISTICS) {
TrStat_gt_terms = 0; TrStat_gt_terms = 0;
TrStat_gt_nodes = 1; TrStat_gt_nodes = 1;
TrStat_gt_refs = 0; TrStat_gt_refs = 0;
fprintf(Yap_stdout, "Global trie statistics\n"); Sfprintf(TrStat_out, "Global trie statistics\n");
} else { /* SHOW_MODE_STRUCTURE */ } else { /* SHOW_MODE_STRUCTURE */
fprintf(Yap_stdout, "Global trie structure\n"); Sfprintf(TrStat_out, "Global trie structure\n");
} }
if (TrNode_child(GLOBAL_root_gt)) { if (TrNode_child(GLOBAL_root_gt)) {
char *str = (char *) malloc(sizeof(char) * SHOW_TABLE_STR_ARRAY_SIZE); char *str = (char *) malloc(sizeof(char) * SHOW_TABLE_STR_ARRAY_SIZE);
@ -1388,9 +1386,9 @@ void show_global_trie(int show_mode) {
} else } else
SHOW_TABLE_STRUCTURE(" EMPTY\n"); SHOW_TABLE_STRUCTURE(" EMPTY\n");
if (show_mode == SHOW_MODE_STATISTICS) { if (show_mode == SHOW_MODE_STATISTICS) {
fprintf(Yap_stdout, " Terms: %ld\n", TrStat_gt_terms); Sfprintf(TrStat_out, " Terms: %ld\n", TrStat_gt_terms);
fprintf(Yap_stdout, " Global trie nodes: %ld\n", TrStat_gt_nodes); Sfprintf(TrStat_out, " Global trie nodes: %ld\n", TrStat_gt_nodes);
fprintf(Yap_stdout, " Global trie auto references: %ld\n", TrStat_gt_refs); Sfprintf(TrStat_out, " Global trie auto references: %ld\n", TrStat_gt_refs);
} }
return; return;
} }

@ -1 +1 @@
Subproject commit b2eb894ce3e41925070215f800d6df3a356dc29d Subproject commit bf6525f85cfcf3c08fff8cf91fb189fe71dc34fd

View File

@ -17,8 +17,67 @@
tabling_mode(:,?), tabling_mode(:,?),
abolish_table(:), abolish_table(:),
show_table(:), show_table(:),
show_table(?,:),
table_statistics(:), table_statistics(:),
table_statistics(:,:). table_statistics(?,:).
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% show_tabled_predicates/0 %%
%% show_global_trie/0 %%
%% show_all_tables/0 %%
%% global_trie_statistics/0 %%
%% tabling_statistics/0 %%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
show_tabled_predicates :-
current_output(Stream),
show_tabled_predicates(Stream).
show_global_trie :-
current_output(Stream),
show_global_trie(Stream).
show_all_tables :-
current_output(Stream),
show_all_tables(Stream).
global_trie_statistics :-
current_output(Stream),
global_trie_statistics(Stream).
tabling_statistics :-
current_output(Stream),
tabling_statistics(Stream).
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% tabling_statistics/2 %%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% should match with code in OPTYap/opt.preds.c
tabling_statistics(total_memory,[BytesInUse,BytesAllocated]) :-
'$c_get_optyap_statistics'(0,BytesInUse,BytesAllocated).
tabling_statistics(table_entries,[BytesInUse,StructsInUse]) :-
'$c_get_optyap_statistics'(1,BytesInUse,StructsInUse).
tabling_statistics(subgoal_frames,[BytesInUse,StructsInUse]) :-
'$c_get_optyap_statistics'(2,BytesInUse,StructsInUse).
tabling_statistics(dependency_frames,[BytesInUse,StructsInUse]) :-
'$c_get_optyap_statistics'(3,BytesInUse,StructsInUse).
tabling_statistics(subgoal_trie_nodes,[BytesInUse,StructsInUse]) :-
'$c_get_optyap_statistics'(6,BytesInUse,StructsInUse).
tabling_statistics(answer_trie_nodes,[BytesInUse,StructsInUse]) :-
'$c_get_optyap_statistics'(7,BytesInUse,StructsInUse).
tabling_statistics(subgoal_trie_hashes,[BytesInUse,StructsInUse]) :-
'$c_get_optyap_statistics'(8,BytesInUse,StructsInUse).
tabling_statistics(answer_trie_hashes,[BytesInUse,StructsInUse]) :-
'$c_get_optyap_statistics'(9,BytesInUse,StructsInUse).
tabling_statistics(global_trie_nodes,[BytesInUse,StructsInUse]) :-
'$c_get_optyap_statistics'(10,BytesInUse,StructsInUse).
tabling_statistics(global_trie_hashes,[BytesInUse,StructsInUse]) :-
'$c_get_optyap_statistics'(11,BytesInUse,StructsInUse).
@ -195,98 +254,80 @@ abolish_table(Pred) :-
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% show_table/1 %% %% show_table/1 %%
%% show_table/2 %%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
show_table(Pred) :- show_table(Pred) :-
'$current_module'(Mod), current_output(Stream),
'$do_show_table'(Mod,Pred). show_table(Stream,Pred).
'$do_show_table'(Mod,Pred) :- show_table(Stream,Pred) :-
'$current_module'(Mod),
'$do_show_table'(Stream,Mod,Pred).
'$do_show_table'(_,Mod,Pred) :-
var(Pred), !, var(Pred), !,
'$do_error'(instantiation_error,show_table(Mod:Pred)). '$do_error'(instantiation_error,show_table(Mod:Pred)).
'$do_show_table'(_,Mod:Pred) :- !, '$do_show_table'(Stream,_,Mod:Pred) :- !,
'$do_show_table'(Mod,Pred). '$do_show_table'(Stream,Mod,Pred).
'$do_show_table'(_,[]) :- !. '$do_show_table'(_,_,[]) :- !.
'$do_show_table'(Mod,[HPred|TPred]) :- !, '$do_show_table'(Stream,Mod,[HPred|TPred]) :- !,
'$do_show_table'(Mod,HPred), '$do_show_table'(Stream,Mod,HPred),
'$do_show_table'(Mod,TPred). '$do_show_table'(Stream,Mod,TPred).
'$do_show_table'(Mod,(Pred1,Pred2)) :- !, '$do_show_table'(Stream,Mod,(Pred1,Pred2)) :- !,
'$do_show_table'(Mod,Pred1), '$do_show_table'(Stream,Mod,Pred1),
'$do_show_table'(Mod,Pred2). '$do_show_table'(Stream,Mod,Pred2).
'$do_show_table'(Mod,PredName/PredArity) :- '$do_show_table'(Stream,Mod,PredName/PredArity) :-
atom(PredName), atom(PredName),
integer(PredArity), integer(PredArity),
functor(PredFunctor,PredName,PredArity), functor(PredFunctor,PredName,PredArity),
'$flags'(PredFunctor,Mod,Flags,Flags), !, '$flags'(PredFunctor,Mod,Flags,Flags), !,
( (
Flags /\ 0x000040 =\= 0, !, '$c_show_table'(Mod,PredFunctor) Flags /\ 0x000040 =\= 0, !, '$c_show_table'(Stream,Mod,PredFunctor)
; ;
'$do_error'(domain_error(table,Mod:PredName/PredArity),show_table(Mod:PredName/PredArity)) '$do_error'(domain_error(table,Mod:PredName/PredArity),show_table(Mod:PredName/PredArity))
). ).
'$do_show_table'(Mod,Pred) :- '$do_show_table'(_,Mod,Pred) :-
'$do_error'(type_error(callable,Mod:Pred),show_table(Mod:Pred)). '$do_error'(type_error(callable,Mod:Pred),show_table(Mod:Pred)).
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% table_statistics/1 %% %% table_statistics/1 %%
%% table_statistics/2 %%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
table_statistics(Pred) :- table_statistics(Pred) :-
'$current_module'(Mod), current_output(Stream),
'$do_table_statistics'(Mod,Pred). table_statistics(Stream,Pred).
'$do_table_statistics'(Mod,Pred) :- table_statistics(Stream,Pred) :-
'$current_module'(Mod),
'$do_table_statistics'(Stream,Mod,Pred).
'$do_table_statistics'(_,Mod,Pred) :-
var(Pred), !, var(Pred), !,
'$do_error'(instantiation_error,table_statistics(Mod:Pred)). '$do_error'(instantiation_error,table_statistics(Mod:Pred)).
'$do_table_statistics'(_,Mod:Pred) :- !, '$do_table_statistics'(Stream,_,Mod:Pred) :- !,
'$do_table_statistics'(Mod,Pred). '$do_table_statistics'(Stream,Mod,Pred).
'$do_table_statistics'(_,[]) :- !. '$do_table_statistics'(_,_,[]) :- !.
'$do_table_statistics'(Mod,[HPred|TPred]) :- !, '$do_table_statistics'(Stream,Mod,[HPred|TPred]) :- !,
'$do_table_statistics'(Mod,HPred), '$do_table_statistics'(Stream,Mod,HPred),
'$do_table_statistics'(Mod,TPred). '$do_table_statistics'(Stream,Mod,TPred).
'$do_table_statistics'(Mod,(Pred1,Pred2)) :- !, '$do_table_statistics'(Stream,Mod,(Pred1,Pred2)) :- !,
'$do_table_statistics'(Mod,Pred1), '$do_table_statistics'(Stream,Mod,Pred1),
'$do_table_statistics'(Mod,Pred2). '$do_table_statistics'(Stream,Mod,Pred2).
'$do_table_statistics'(Mod,PredName/PredArity) :- '$do_table_statistics'(Stream,Mod,PredName/PredArity) :-
atom(PredName), atom(PredName),
integer(PredArity), integer(PredArity),
functor(PredFunctor,PredName,PredArity), functor(PredFunctor,PredName,PredArity),
'$flags'(PredFunctor,Mod,Flags,Flags), !, '$flags'(PredFunctor,Mod,Flags,Flags), !,
( (
Flags /\ 0x000040 =\= 0, !, '$c_table_statistics'(Mod,PredFunctor) Flags /\ 0x000040 =\= 0, !, '$c_table_statistics'(Stream,Mod,PredFunctor)
; ;
'$do_error'(domain_error(table,Mod:PredName/PredArity),table_statistics(Mod:PredName/PredArity)) '$do_error'(domain_error(table,Mod:PredName/PredArity),table_statistics(Mod:PredName/PredArity))
). ).
'$do_table_statistics'(Mod,Pred) :- '$do_table_statistics'(_,Mod,Pred) :-
'$do_error'(type_error(callable,Mod:Pred),table_statistics(Mod:Pred)). '$do_error'(type_error(callable,Mod:Pred),table_statistics(Mod:Pred)).
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% tabling_statistics/2 %%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% should match with code in OPTYap/opt.preds.c
tabling_statistics(total_memory,[BytesInUse,BytesAllocated]) :-
'$c_get_optyap_statistics'(0,BytesInUse,BytesAllocated).
tabling_statistics(table_entries,[BytesInUse,StructsInUse]) :-
'$c_get_optyap_statistics'(1,BytesInUse,StructsInUse).
tabling_statistics(subgoal_frames,[BytesInUse,StructsInUse]) :-
'$c_get_optyap_statistics'(2,BytesInUse,StructsInUse).
tabling_statistics(dependency_frames,[BytesInUse,StructsInUse]) :-
'$c_get_optyap_statistics'(3,BytesInUse,StructsInUse).
tabling_statistics(subgoal_trie_nodes,[BytesInUse,StructsInUse]) :-
'$c_get_optyap_statistics'(6,BytesInUse,StructsInUse).
tabling_statistics(answer_trie_nodes,[BytesInUse,StructsInUse]) :-
'$c_get_optyap_statistics'(7,BytesInUse,StructsInUse).
tabling_statistics(subgoal_trie_hashes,[BytesInUse,StructsInUse]) :-
'$c_get_optyap_statistics'(8,BytesInUse,StructsInUse).
tabling_statistics(answer_trie_hashes,[BytesInUse,StructsInUse]) :-
'$c_get_optyap_statistics'(9,BytesInUse,StructsInUse).
tabling_statistics(global_trie_nodes,[BytesInUse,StructsInUse]) :-
'$c_get_optyap_statistics'(10,BytesInUse,StructsInUse).
tabling_statistics(global_trie_hashes,[BytesInUse,StructsInUse]) :-
'$c_get_optyap_statistics'(11,BytesInUse,StructsInUse).
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

View File

@ -12,12 +12,25 @@
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
:- meta_predicate :- meta_predicate
or_statistics(:,:),
opt_statistics(:,:),
default_sequential(:). default_sequential(:).
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% or_statistics/0 %%
%% opt_statistics/0 %%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
or_statistics :-
current_output(Stream),
or_statistics(Stream).
opt_statistics :-
current_output(Stream),
opt_statistics(Stream).
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% or_statistics/2 %% %% or_statistics/2 %%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%