new built-in predicate global_trie_statistics/0.
This commit is contained in:
parent
ddb1cd8604
commit
467dd91b32
@ -65,6 +65,7 @@ static Int p_show_table(void);
|
|||||||
static Int p_show_all_tables(void);
|
static Int p_show_all_tables(void);
|
||||||
#ifdef GLOBAL_TRIE
|
#ifdef GLOBAL_TRIE
|
||||||
static Int p_show_global_trie(void);
|
static Int p_show_global_trie(void);
|
||||||
|
static Int p_global_trie_statistics(void);
|
||||||
#endif /* GLOBAL_TRIE */
|
#endif /* GLOBAL_TRIE */
|
||||||
static Int p_table_statistics(void);
|
static Int p_table_statistics(void);
|
||||||
static Int p_tabling_statistics(void);
|
static Int p_tabling_statistics(void);
|
||||||
@ -154,6 +155,7 @@ void Yap_init_optyap_preds(void) {
|
|||||||
Yap_InitCPred("show_all_tables", 0, p_show_all_tables, SafePredFlag|SyncPredFlag);
|
Yap_InitCPred("show_all_tables", 0, p_show_all_tables, SafePredFlag|SyncPredFlag);
|
||||||
#ifdef GLOBAL_TRIE
|
#ifdef GLOBAL_TRIE
|
||||||
Yap_InitCPred("show_global_trie", 0, p_show_global_trie, SafePredFlag|SyncPredFlag);
|
Yap_InitCPred("show_global_trie", 0, p_show_global_trie, SafePredFlag|SyncPredFlag);
|
||||||
|
Yap_InitCPred("global_trie_statistics", 0, p_global_trie_statistics, SafePredFlag|SyncPredFlag);
|
||||||
#endif /* GLOBAL_TRIE */
|
#endif /* GLOBAL_TRIE */
|
||||||
Yap_InitCPred("$c_table_statistics", 2, p_table_statistics, SafePredFlag|SyncPredFlag|HiddenPredFlag);
|
Yap_InitCPred("$c_table_statistics", 2, p_table_statistics, SafePredFlag|SyncPredFlag|HiddenPredFlag);
|
||||||
Yap_InitCPred("tabling_statistics", 0, p_tabling_statistics, SafePredFlag|SyncPredFlag);
|
Yap_InitCPred("tabling_statistics", 0, p_tabling_statistics, SafePredFlag|SyncPredFlag);
|
||||||
@ -767,7 +769,7 @@ Int p_show_tabled_predicates(void) {
|
|||||||
tab_ent = GLOBAL_root_tab_ent;
|
tab_ent = GLOBAL_root_tab_ent;
|
||||||
fprintf(Yap_stdout, "Tabled predicates\n");
|
fprintf(Yap_stdout, "Tabled predicates\n");
|
||||||
if (tab_ent == NULL)
|
if (tab_ent == NULL)
|
||||||
fprintf(Yap_stdout, " none\n");
|
fprintf(Yap_stdout, " 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));
|
fprintf(Yap_stdout, " %s/%d\n", AtomName(TabEnt_atom(tab_ent)), TabEnt_arity(tab_ent));
|
||||||
@ -811,7 +813,13 @@ Int p_show_all_tables(void) {
|
|||||||
#ifdef GLOBAL_TRIE
|
#ifdef GLOBAL_TRIE
|
||||||
static
|
static
|
||||||
Int p_show_global_trie(void) {
|
Int p_show_global_trie(void) {
|
||||||
show_global_trie();
|
show_global_trie(SHOW_MODE_STRUCTURE);
|
||||||
|
return (TRUE);
|
||||||
|
}
|
||||||
|
|
||||||
|
static
|
||||||
|
Int p_global_trie_statistics(void) {
|
||||||
|
show_global_trie(SHOW_MODE_STATISTICS);
|
||||||
return (TRUE);
|
return (TRUE);
|
||||||
}
|
}
|
||||||
#endif /* GLOBAL_TRIE */
|
#endif /* GLOBAL_TRIE */
|
||||||
|
@ -82,7 +82,7 @@ void free_answer_trie_branch(ans_node_ptr, int);
|
|||||||
void update_answer_trie(sg_fr_ptr);
|
void update_answer_trie(sg_fr_ptr);
|
||||||
void show_table(tab_ent_ptr, int);
|
void show_table(tab_ent_ptr, int);
|
||||||
#ifdef GLOBAL_TRIE
|
#ifdef GLOBAL_TRIE
|
||||||
void show_global_trie(void);
|
void show_global_trie(int);
|
||||||
#endif /* GLOBAL_TRIE */
|
#endif /* GLOBAL_TRIE */
|
||||||
void private_completion(sg_fr_ptr);
|
void private_completion(sg_fr_ptr);
|
||||||
#endif /* TABLING */
|
#endif /* TABLING */
|
||||||
|
@ -89,6 +89,7 @@ static struct trie_statistics{
|
|||||||
#ifdef GLOBAL_TRIE
|
#ifdef GLOBAL_TRIE
|
||||||
long global_trie_terms;
|
long global_trie_terms;
|
||||||
long global_trie_nodes;
|
long global_trie_nodes;
|
||||||
|
long global_trie_references;
|
||||||
#endif /* GLOBAL_TRIE */
|
#endif /* GLOBAL_TRIE */
|
||||||
} trie_stats;
|
} trie_stats;
|
||||||
|
|
||||||
@ -103,6 +104,7 @@ static struct trie_statistics{
|
|||||||
#define TrStat_ans_nodes trie_stats.answer_trie_nodes
|
#define TrStat_ans_nodes trie_stats.answer_trie_nodes
|
||||||
#define TrStat_gt_terms trie_stats.global_trie_terms
|
#define TrStat_gt_terms trie_stats.global_trie_terms
|
||||||
#define TrStat_gt_nodes trie_stats.global_trie_nodes
|
#define TrStat_gt_nodes trie_stats.global_trie_nodes
|
||||||
|
#define TrStat_gt_refs trie_stats.global_trie_references
|
||||||
#define SHOW_TABLE_STR_ARRAY_SIZE 100000
|
#define SHOW_TABLE_STR_ARRAY_SIZE 100000
|
||||||
#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...) \
|
||||||
@ -496,7 +498,7 @@ static void traverse_global_trie(gt_node_ptr current_node, char *str, int str_in
|
|||||||
else {
|
else {
|
||||||
TrStat_gt_terms++;
|
TrStat_gt_terms++;
|
||||||
str[str_index] = 0;
|
str[str_index] = 0;
|
||||||
SHOW_TABLE_STRUCTURE(" TERM (x%ld): %s\n", (unsigned long int) TrNode_child(current_node), str);
|
SHOW_TABLE_STRUCTURE(" TERMx%ld: %s\n", (unsigned long int) TrNode_child(current_node), str);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* restore the initial state and continue with sibling nodes */
|
/* restore the initial state and continue with sibling nodes */
|
||||||
@ -816,6 +818,7 @@ static inline void traverse_trie_node(Term t, char *str, int *str_index_ptr, int
|
|||||||
} else if (IsVarTerm(t)) {
|
} else if (IsVarTerm(t)) {
|
||||||
#ifdef GLOBAL_TRIE
|
#ifdef GLOBAL_TRIE
|
||||||
if (t > VarIndexOfTableTerm(MAX_TABLE_VARS)) {
|
if (t > VarIndexOfTableTerm(MAX_TABLE_VARS)) {
|
||||||
|
TrStat_gt_refs++;
|
||||||
traverse_global_trie_for_term((gt_node_ptr) t, str, &str_index, arity, &mode, type);
|
traverse_global_trie_for_term((gt_node_ptr) t, str, &str_index, arity, &mode, type);
|
||||||
} else
|
} else
|
||||||
#endif /* GLOBAL_TRIE */
|
#endif /* GLOBAL_TRIE */
|
||||||
@ -1335,8 +1338,11 @@ void show_table(tab_ent_ptr tab_ent, int show_mode) {
|
|||||||
TrStat_answers_pruned = 0;
|
TrStat_answers_pruned = 0;
|
||||||
#endif /* TABLING_INNER_CUTS */
|
#endif /* TABLING_INNER_CUTS */
|
||||||
TrStat_ans_nodes = 0;
|
TrStat_ans_nodes = 0;
|
||||||
|
#ifdef GLOBAL_TRIE
|
||||||
|
TrStat_gt_refs = 0;
|
||||||
|
#endif /* GLOBAL_TRIE */
|
||||||
fprintf(Yap_stdout, "Table statistics for predicate '%s/%d'\n", AtomName(TabEnt_atom(tab_ent)), TabEnt_arity(tab_ent));
|
fprintf(Yap_stdout, "Table statistics for predicate '%s/%d'\n", AtomName(TabEnt_atom(tab_ent)), TabEnt_arity(tab_ent));
|
||||||
} else { /* show_mode == 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));
|
fprintf(Yap_stdout, "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));
|
||||||
@ -1383,20 +1389,25 @@ void show_table(tab_ent_ptr tab_ent, int show_mode) {
|
|||||||
fprintf(Yap_stdout, " Answers 'TRUE': %ld\n", TrStat_answers_true);
|
fprintf(Yap_stdout, " Answers 'TRUE': %ld\n", TrStat_answers_true);
|
||||||
fprintf(Yap_stdout, " Answers 'NO': %ld\n", TrStat_answers_no);
|
fprintf(Yap_stdout, " Answers 'NO': %ld\n", TrStat_answers_no);
|
||||||
fprintf(Yap_stdout, " Answer trie nodes: %ld\n", TrStat_ans_nodes);
|
fprintf(Yap_stdout, " Answer trie nodes: %ld\n", TrStat_ans_nodes);
|
||||||
fprintf(Yap_stdout, " Total memory in use: %ld bytes\n",
|
#ifdef GLOBAL_TRIE
|
||||||
sizeof(struct table_entry) + TrStat_sg_nodes * sizeof(struct subgoal_trie_node) +
|
fprintf(Yap_stdout, " Global trie references: %ld\n", TrStat_gt_refs);
|
||||||
TrStat_ans_nodes * sizeof(struct answer_trie_node) + TrStat_subgoals * sizeof(struct subgoal_frame));
|
#endif /* GLOBAL_TRIE */
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#ifdef GLOBAL_TRIE
|
#ifdef GLOBAL_TRIE
|
||||||
void show_global_trie(void) {
|
void show_global_trie(int show_mode) {
|
||||||
TrStat_show = SHOW_MODE_STRUCTURE;
|
TrStat_show = show_mode;
|
||||||
TrStat_gt_terms = 0;
|
if (show_mode == SHOW_MODE_STATISTICS) {
|
||||||
TrStat_gt_nodes = 1;
|
TrStat_gt_terms = 0;
|
||||||
fprintf(Yap_stdout, "Global trie structure\n");
|
TrStat_gt_nodes = 1;
|
||||||
|
TrStat_gt_refs = 0;
|
||||||
|
fprintf(Yap_stdout, "Global trie statistics\n");
|
||||||
|
} else { /* SHOW_MODE_STRUCTURE */
|
||||||
|
fprintf(Yap_stdout, "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);
|
||||||
int *arity = (int *) malloc(sizeof(int) * SHOW_TABLE_ARITY_ARRAY_SIZE);
|
int *arity = (int *) malloc(sizeof(int) * SHOW_TABLE_ARITY_ARRAY_SIZE);
|
||||||
@ -1406,10 +1417,11 @@ void show_global_trie(void) {
|
|||||||
free(arity);
|
free(arity);
|
||||||
} else
|
} else
|
||||||
SHOW_TABLE_STRUCTURE(" EMPTY\n");
|
SHOW_TABLE_STRUCTURE(" EMPTY\n");
|
||||||
fprintf(Yap_stdout, "Global trie statistics\n");
|
if (show_mode == SHOW_MODE_STATISTICS) {
|
||||||
fprintf(Yap_stdout, " Terms: %ld\n", TrStat_gt_terms);
|
fprintf(Yap_stdout, " Terms: %ld\n", TrStat_gt_terms);
|
||||||
fprintf(Yap_stdout, " Global trie nodes: %ld\n", TrStat_gt_nodes);
|
fprintf(Yap_stdout, " Global trie nodes: %ld\n", TrStat_gt_nodes);
|
||||||
fprintf(Yap_stdout, " Total memory in use: %ld bytes\n", TrStat_gt_nodes * sizeof(struct global_trie_node));
|
fprintf(Yap_stdout, " Global trie auto references: %ld\n", TrStat_gt_refs);
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
#endif /* GLOBAL_TRIE */
|
#endif /* GLOBAL_TRIE */
|
||||||
|
Reference in New Issue
Block a user