34 #include "../base/ver.h"
38 #include "../base/str.h"
41 #ifndef CHECK_INCLUDED
42 #include "../base/check.h"
46 #include "../base/idiv.h"
50 #include "../mem/page.h"
53 #ifndef STRTAB_INCLUDED
54 #include "../dom/strtab.h"
57 #ifndef ATOMTAB_INCLUDED
58 #include "../dom/atomtab.h"
62 #include "../rel/rel.h"
79 static void set_verbose(
bool verbose) {
84 static void set_answer_limit(
long max_answers) {
85 if(max_answers <= 1) {
91 AnswerLimit = max_answers + 1;
101 static void set_debug(
bool debug) {
108 static void set_summary(
bool summary,
bool newline) {
110 Summary_NewLine = newline;
114 static void set_rel(
bool rel) {
119 static void set_mem_pools(
bool mem_pools) {
120 MemPools = mem_pools;
124 static void set_dump(
bool dump) {
134 static bool show_rel() {
139 static bool show_dump() {
154 static inline void verbose_msg(
str_t msg) {
160 static inline void verbose_int(
int i) {
166 static inline void verbose_long(
long n) {
172 static inline void verbose_fact_1(
str_t pred,
int arg1) {
174 print_fact_1(pred, arg1);
178 static inline void verbose_fact_2(
str_t pred,
int arg1,
int arg2) {
180 print_fact_2(pred, arg1, arg2);
184 static inline void verbose_nl() {
191 static inline void verbose_hrule() {
193 print_str(
"----------------------------------------");
194 print_str(
"---------------------------------------\n");
199 static inline void verbose_headline(
str_t test_id) {
201 print_str(
"----------------------------------------");
202 print_str(
"---------------------------------------\n");
203 print_str(
"--- TEST \"");
206 print_str(
"----------------------------------------");
207 print_str(
"---------------------------------------\n");
212 static inline void verbose_time(
str_t name,
long realtime,
long cpu) {
215 print_long(realtime);
224 static inline void verbose_success(
str_t test_id) {
228 print_str(
"' successfully finished.\n");
233 static inline void verbose_bad_ok(
str_t test_id) {
237 print_str(
"' returned ok status,");
238 print_str(
"but an error was detected.\n");
243 static inline void verbose_failure(
str_t test_id) {
245 print_str(
"*** TEST '");
247 print_str(
" FAILED! ***\n");
252 static inline void verbose_benchmark(
str_t bench_name) {
254 print_str(
"Benchmark: '");
255 print_str(bench_name);
261 static inline void verbose_input(
str_t file_name) {
263 print_str(
"Input File: '");
264 print_str(file_name);
270 static inline void verbose_result(
long eval_result) {
272 print_str(
"Number of result rows: ");
273 print_long(eval_result);
279 static inline void verbose_cannot_check() {
281 print_str(
"Result cannot be checked, ");
282 print_str(
"expected result unknown.\n");
287 static inline void verbose_bench_ok() {
289 print_str(
"Benchmark was successfully executed.\n");
294 static inline void verbose_real_gt_cpu(
long realtime,
long cputime) {
296 print_str(
"Warning: Wallclock time (");
297 print_long(realtime);
298 print_str(
" ms) much more than CPU time (");
305 static inline void verbose_cpu_gt_real(
long realtime,
long cputime) {
307 print_str(
"Warning: CPU time (");
309 print_str(
" ms) is more than Wallclock time (");
310 print_long(realtime);
316 static inline void verbose_test_failed(
str_t msg) {
318 print_str(
"*** TEST FAILED: ");
325 static inline void verbose_wrong_result(
str_t fun,
long result,
326 long expected_result) {
328 print_str(
"*** TEST FAILED: ");
329 print_str(
"Function ");
331 print_str(
" returned ");
333 print_str(
" (expected: ");
334 print_long(expected_result);
335 print_str(
") ***\n");
340 static inline void verbose_error_row(
int row_num,
str_t row_text) {
342 print_str(
"*** TEST FAILED AT ROW ");
346 print_str(
". ***\n");
351 static inline void verbose_num_rows(
int num_rows) {
353 print_str(
"Number of rows: ");
360 static inline void verbose_num_cols(
int bound_args,
int free_args) {
362 print_str(
"Number of columns: ");
363 print_int(bound_args + free_args);
364 print_str(
" (bound: ");
365 print_int(bound_args);
366 print_str(
", free: ");
367 print_int(free_args);
374 static inline void verbose_implementation(
str_t impl_name) {
376 print_str(
"Implementation: ");
377 print_str(impl_name);
383 static inline void verbose_hashtab_size(
int hash_size) {
385 print_str(
"Hash table size: ");
386 print_int(hash_size);
392 static inline void verbose_hashtab_usage(
int hash_size,
395 print_str(
"Used entries: ");
396 print_int(entries_used);
405 static inline void verbose_hashtab_chain(
int num_rows,
408 print_str(
"Avg. chain length: ");
409 if(entries_used == 0)
412 print_int(
IDIV_WHOLE(num_rows, entries_used));
414 print_int(
IDIV_TENTH(num_rows, entries_used));
422 static inline void verbose_bucket_size(
int num_entries,
int bytes) {
424 print_str(
"Bucket size: ");
425 print_int(num_entries);
429 print_str(
" Bytes)");
436 static inline void verbose_total_buckets(
int total_buckets) {
438 print_str(
"Total buckets: ");
439 print_int(total_buckets);
445 static inline void verbose_overflow_buckets(
int overflow_buckets) {
447 print_str(
"Overflow buckets: ");
448 print_int(overflow_buckets);
454 static inline void verbose_rows_per_bucket(
int num_rows,
455 int total_buckets,
int bucket_size) {
456 if(Verbose && total_buckets > 0) {
457 print_str(
"Rows per bucket: ");
458 print_int(
IDIV_WHOLE(num_rows, total_buckets));
460 print_int(
IDIV_TENTH(num_rows, total_buckets));
461 if(bucket_size > 0) {
462 int rows_per_bucket =
476 static inline void verbose_mem_pages(
int num_pages) {
478 print_str(
"Used memory pages: ");
479 print_int(num_pages);
481 print_int(PAGE_KB(num_pages));
488 static inline void verbose_obj_size(
int obj_size) {
490 print_str(
"Object size: ");
498 static inline void verbose_bytes_per_row(
int num_pages,
int obj_size,
500 if(Verbose && num_rows > 0) {
501 int bytes = PAGE_KB(num_pages) * 1024 + obj_size;
502 print_str(
"Bytes per row: ");
516 static inline void answer_1(
long no,
int arg1) {
517 if(AnswerOutput && no <= AnswerLimit) {
518 if(no < AnswerLimit) {
520 print_fact_1(
"answer", arg1);
522 else if( AnswerLimit > 1) {
523 print_answer_limit();
529 static inline void answer_2(
long no,
int arg1,
int arg2) {
530 if(AnswerOutput && no <= AnswerLimit) {
531 if(no < AnswerLimit) {
533 print_fact_2(
"answer", arg1, arg2);
535 else if( AnswerLimit > 1) {
536 print_answer_limit();
542 static inline void answer_s(
long no,
str_t arg1) {
543 if(AnswerOutput && no <= AnswerLimit) {
544 if(no < AnswerLimit) {
546 print_fact_s(
"answer", arg1);
548 else if( AnswerLimit > 1) {
549 print_answer_limit();
555 static inline void answer_5s(
long no,
str_t arg1,
str_t arg2,
557 if(AnswerOutput && no <= AnswerLimit) {
558 if(no < AnswerLimit) {
560 print_fact_5s(
"answer", arg1, arg2, arg3,
563 else if( AnswerLimit > 1) {
564 print_answer_limit();
574 static inline void rel_size_headline() {
577 print_str(
"Relations and Domains:\n");
578 print_str(
"--------------------- \n");
583 static inline void rel_size(
rel_t rel) {
585 print_rel_size(rel->name(), rel->num_rows(),
591 static inline void rel_size_nonstd(
str_t name,
long num_rows,
594 print_rel_size(name, num_rows, num_pages);
599 static inline void rel_size_strtab(
strtab_t tab) {
601 print_rel_size_strtab(tab);
606 static inline void rel_size_atomtab(
atomtab_t tab) {
608 print_rel_size_atomtab(tab);
613 static inline void rel_size_done() {
624 static inline void mem_pools_tab(
str_t headline =
STR_NULL) {
626 print_mem_pools_tab(headline);
635 static inline void summary(
str_t bench_id,
long load_time,
636 long eval_time,
long total_time,
str_t result) {
638 print_summary(bench_id, load_time, eval_time,
647 static inline void debug_msg(
str_t msg) {
653 static inline void debug_int(
int i) {
659 static inline void debug_long(
long n) {
665 static inline void debug_nl() {
671 static inline void debug_fact_1(
str_t pred,
int arg1) {
673 print_fact_1(pred, arg1);
677 static inline void debug_fact_2(
str_t pred,
int arg1,
int arg2) {
679 print_fact_2(pred, arg1, arg2);
683 static inline void debug_ival(
str_t attr,
int i) {
692 static inline void debug_lval(
str_t attr,
long n) {
701 static inline void debug_sval(
str_t attr,
str_t s) {
712 static inline void debug_mempages(
str_t attr,
int num_pages) {
715 print_int(num_pages);
717 print_int(PAGE_KB(num_pages));
724 static inline void debug_hashusage(
str_t attr,
int entries_used,
728 print_int(entries_used);
737 static inline void debug_hashchain(
str_t attr,
int entries_used,
741 print_int(entries_used);
742 print_int(
IDIV_WHOLE(num_rows, entries_used));
744 print_int(
IDIV_TENTH(num_rows, entries_used));
755 static void debug_trace_iteration(
int stacksize)
758 print_str(
"NEXT ITERATION [Stacksize: ");
759 print_int(stacksize);
766 static void debug_trace_label(
str_t type,
int label,
770 static const int LABEL_WIDTH = 3;
776 print_str(
str_fill(label, LABEL_WIDTH));
779 print_str(fact_type);
785 static void debug_trace_assign(
str_t var,
int value)
797 static void debug_trace_pop_var(
str_t var,
int value)
804 print_str(
" [Restored from Stack]");
809 static void debug_trace_rule_app(
int call_depth,
str_t rule,
810 str_t pred,
int num_args,
814 while(call_depth-- > 0)
832 static void debug_trace_call(
int call_depth,
str_t pred,
int num_args,
836 while(call_depth-- > 0)
852 #if VER_DEBUG_OUT_ENABLED
855 #define OUT_TRACE_ITERATION(STACKSIZE) \
856 (out_c::debug_trace_iteration((STACKSIZE)))
857 #define OUT_TRACE_START(LABEL, RULE, FACT_TYPE) \
858 (out_c::debug_trace_label("START ", (LABEL), (RULE), (FACT_TYPE)))
859 #define OUT_TRACE_START_REC(LABEL, RULE, FACT_TYPE) \
860 (out_c::debug_trace_label("START_R", (LABEL), (RULE), (FACT_TYPE)))
861 #define OUT_TRACE_CONT(LABEL, RULE, FACT_TYPE) \
862 (out_c::debug_trace_label("CONT ", (LABEL), (RULE), (FACT_TYPE)))
863 #define OUT_TRACE_ANSWER(LABEL, RULE, FACT_TYPE) \
864 (out_c::debug_trace_label("ANSWER ", (LABEL), (RULE), (FACT_TYPE)))
865 #define OUT_TRACE_RESTORE(LABEL, RULE, FACT_TYPE) \
866 (out_c::debug_trace_label("RESTORE", (LABEL), (RULE), (FACT_TYPE)))
867 #define OUT_TRACE_ASSIGN(VAR, VALUE) \
868 (out_c::debug_trace_assign((VAR), (VALUE)))
869 #define OUT_TRACE_POP_VAR(VAR, VALUE) \
870 (out_c::debug_trace_pop_var((VAR), (VALUE)))
873 #define OUT_TRACE_DEPTH_DECL \
874 int out_call_depth_global
875 #define OUT_TRACE_DEPTH_INIT \
876 (out_call_depth_global = 0)
877 #define OUT_TRACE_DEPTH \
878 int out_call_depth_local = (this->out_call_depth_global + 1)
880 #define OUT_TRACE_RULE_APP_0(RULE, PRED) \
881 (out_c::debug_trace_rule_app(out_call_depth_local, \
882 (RULE), (PRED), 0, 0, 0))
883 #define OUT_TRACE_RULE_APP_1(RULE, PRED, ARG1) \
884 (out_c::debug_trace_rule_app(out_call_depth_local, \
885 (RULE), (PRED), 1, (ARG1), 0))
886 #define OUT_TRACE_RULE_APP_2(RULE, PRED, ARG1, ARG2) \
887 (out_c::debug_trace_rule_app(out_call_depth_local, \
888 (RULE), (PRED), 2, (ARG1), (ARG2)))
890 #define OUT_TRACE_CALL_0(PRED) \
891 (this->out_call_depth_global = out_call_depth_local, \
892 out_c::debug_trace_call(out_call_depth_local, \
894 #define OUT_TRACE_CALL_1(PRED, ARG1) \
895 (this->out_call_depth_global = out_call_depth_local, \
896 out_c::debug_trace_call(out_call_depth_local, \
897 (PRED), 1, (ARG1), 0))
898 #define OUT_TRACE_CALL_2(PRED, ARG1, ARG2) \
899 (this->out_call_depth_global = out_call_depth_local, \
900 out_c::debug_trace_call(out_call_depth_local, \
901 (PRED), 2, (ARG1), (ARG2)))
906 #define OUT_TRACE_ITERATION(STACKSIZE) \
908 #define OUT_TRACE_START(LABEL, RULE, FACT_TYPE) \
910 #define OUT_TRACE_START_REC(LABEL, RULE, FACT_TYPE) \
912 #define OUT_TRACE_CONT(LABEL, RULE, FACT_TYPE) \
914 #define OUT_TRACE_ANSWER(LABEL, RULE, FACT_TYPE) \
916 #define OUT_TRACE_RESTORE(LABEL, RULE, FACT_TYPE) \
918 #define OUT_TRACE_ASSIGN(VAR, VALUE) \
920 #define OUT_TRACE_POP_VAR(VAR, VALUE) \
923 #define OUT_TRACE_DEPTH_DECL \
924 void out_depth_not_used()
927 #define OUT_TRACE_DEPTH_INIT \
929 #define OUT_TRACE_DEPTH \
932 #define OUT_TRACE_RULE_APP_0(RULE, PRED) \
934 #define OUT_TRACE_RULE_APP_1(RULE, PRED, ARG1) \
936 #define OUT_TRACE_RULE_APP_2(RULE, PRED, ARG1, ARG2) \
939 #define OUT_TRACE_CALL_0(PRED) \
941 #define OUT_TRACE_CALL_1(PRED, ARG1) \
943 #define OUT_TRACE_CALL_2(PRED, ARG1, ARG2) \
954 static inline void help_line(
str_t line) {
960 static inline void help_test(
str_t id,
str_t name) {
961 static const int ID_WIDTH = 15;
976 static void print_str(
str_t msg);
979 static void print_int(
int i);
982 static void print_long(
long n);
985 static void print_nl();
988 static void print_fact_1(
str_t pred,
int arg1);
991 static void print_fact_2(
str_t pred,
int arg1,
int arg2);
994 static void print_fact_s(
str_t pred,
str_t arg1);
1001 static void print_answer_limit();
1004 static void print_answer_no(
long no);
1007 static void print_summary(
str_t bench_id,
long load_time,
1008 long eval_time,
long total_time,
str_t result);
1011 static void print_rel_size(
str_t name,
long num_rows,
long num_pages);
1014 static void print_rel_size_strtab(
strtab_t tab);
1017 static void print_rel_size_atomtab(
atomtab_t tab);
1020 static void print_mem_pools_tab(
str_t headline);
1047 static bool Verbose;
1050 static bool AnswerOutput;
1053 static long AnswerLimit;
1059 static bool Summary;
1062 static bool Summary_NewLine;
1070 static bool MemPools;
str_t str_indent(int n)
Definition: str.cpp:150
#define IDIV_TENTH(X, Y)
Definition: idiv.h:98
int str_len(register str_t str)
Definition: str.cpp:34
str_t str_fill(int n, int field_width)
Definition: str.cpp:286
#define IDIV_WHOLE(X, Y)
Definition: idiv.h:85
const char * str_t
Definition: str.h:41
#define STR_NULL
Definition: str.h:52
#define IDIV_PERCENT(X, Y)
Definition: idiv.h:110