BAM
Abstract Machine for Bottom-Up Evaluation with the Push Method
out.h
Go to the documentation of this file.
1 // ============================================================================
2 // Project: Deductive Database
3 // Filename: out.h
4 // Purpose: Class for Output of Tests/Benchmarks
5 // Last Change: 04.08.2017
6 // Language: C++
7 // EMail: brass@informatik.uni-halle.de
8 // WWW: http://www.informatik.uni-halle.de/~brass/
9 // Address: Feldschloesschen 15, D-06120 Halle (Saale), GERMANY
10 // Copyright: (c) 2016-2017 by Stefan Brass
11 // License: See file "LICENSE" for copying conditions.
12 // Note: There is no warranty at all - this code may contain bugs.
13 // ============================================================================
14 
15 
22 //=============================================================================
23 // Include File Frame:
24 //=============================================================================
25 
26 #ifndef OUT_INCLUDED
27 #define OUT_INCLUDED
28 
29 //=============================================================================
30 // Used Types and Macros:
31 //=============================================================================
32 
33 #ifndef VER_INCLUDED
34 #include "../base/ver.h"
35 #endif
36 
37 #ifndef STR_INCLUDED
38 #include "../base/str.h"
39 #endif
40 
41 #ifndef CHECK_INCLUDED
42 #include "../base/check.h"
43 #endif
44 
45 #ifndef IDIV_INCLUDED
46 #include "../base/idiv.h"
47 #endif
48 
49 #ifndef PAGE_INCLUDED
50 #include "../mem/page.h"
51 #endif
52 
53 #ifndef STRTAB_INCLUDED
54 #include "../dom/strtab.h"
55 #endif
56 
57 #ifndef ATOMTAB_INCLUDED
58 #include "../dom/atomtab.h"
59 #endif
60 
61 #ifndef REL_INCLUDED
62 #include "../rel/rel.h"
63 #endif
64 
65 
66 //=============================================================================
67 // Module for Output of Tests/Benchmarks (Class with only static members):
68 //=============================================================================
69 
70 class out_c {
71  public:
72 
73 
74 //-----------------------------------------------------------------------------
75 // Static Methods for Output Selection:
76 //-----------------------------------------------------------------------------
77 
78  // set_verbose: Set verbose mode with output while test runs.
79  static void set_verbose(bool verbose) {
80  Verbose = verbose;
81  }
82 
83  // set_answer_limit: Set maximal number of answers to print.
84  static void set_answer_limit(long max_answers) {
85  if(max_answers <= 1) {
86  AnswerOutput = false;
87  AnswerLimit = 0;
88  }
89  else {
90  AnswerOutput = true;
91  AnswerLimit = max_answers + 1;
92  // If the answer number is equal to limit,
93  // a message is printed that there are more answers.
94  // The answer itself is not printed.
95  // Therefore the limit must be one larger than
96  // the maximum number of answers to print.
97  }
98  }
99 
100  // set_debug: Set debug mode with additional output while test runs.
101  static void set_debug(bool debug) {
102 
103  // Set debug mode:
104  Debug = debug;
105  }
106 
107  // set_summary: Set flag for printing summary line.
108  static void set_summary(bool summary, bool newline) {
109  Summary = summary;
110  Summary_NewLine = newline;
111  }
112 
113  // set_rel: Set flag for printing relation statistics.
114  static void set_rel(bool rel) {
115  Rel = rel;
116  }
117 
118  // set_mem_pools: Set flag for printing memory pool list.
119  static void set_mem_pools(bool mem_pools) {
120  MemPools = mem_pools;
121  }
122 
123  // set_dump: Set flag for printing data structure dump.
124  static void set_dump(bool dump) {
125  Dump = dump;
126  }
127 
128 
129 //-----------------------------------------------------------------------------
130 // Static Methods for Querying Output Selection:
131 //-----------------------------------------------------------------------------
132 
133  // show_rel: Should the relation statistics be shown?
134  static bool show_rel() {
135  return Rel;
136  }
137 
138  // show_dump: Should the data structure dump be shown?
139  static bool show_dump() {
140  return Dump;
141 
142  // Note: The dump is currently written via methods
143  // of err_c, because it is also used if check constraints fail.
144  // Therefore, it is written to cerr and the alert file
145  // (as selected by methods of err_c).
146  // It would be possible to print a note or headline here.
147  }
148 
149 //-----------------------------------------------------------------------------
150 // Static Methods for Verbose Output:
151 //-----------------------------------------------------------------------------
152 
153  // verbose_msg: Print string only in verbose mode.
154  static inline void verbose_msg(str_t msg) {
155  if(Verbose)
156  print_str(msg);
157  }
158 
159  // verbose_int: Print integer value only in verbose mode.
160  static inline void verbose_int(int i) {
161  if(Verbose)
162  print_int(i);
163  }
164 
165  // verbose_long: Print long value only in verbose mode.
166  static inline void verbose_long(long n) {
167  if(Verbose)
168  print_long(n);
169  }
170 
171  // verbose_fact_1: Print fact with predicate and one integer argument.
172  static inline void verbose_fact_1(str_t pred, int arg1) {
173  if(Verbose)
174  print_fact_1(pred, arg1);
175  }
176 
177  // verbose_fact_22: Print fact with predicate and two integer arguments.
178  static inline void verbose_fact_2(str_t pred, int arg1, int arg2) {
179  if(Verbose)
180  print_fact_2(pred, arg1, arg2);
181  }
182 
183  // verbose_nl: Print newline.
184  static inline void verbose_nl() {
185  if(Verbose) {
186  print_nl();
187  }
188  }
189 
190  // verbose_hrule: Print "horizontal rule" - separating line.
191  static inline void verbose_hrule() {
192  if(Verbose) {
193  print_str("----------------------------------------");
194  print_str("---------------------------------------\n");
195  }
196  }
197 
198  // verbose_test_head: Print test headline.
199  static inline void verbose_headline(str_t test_id) {
200  if(Verbose) {
201  print_str("----------------------------------------");
202  print_str("---------------------------------------\n");
203  print_str("--- TEST \"");
204  print_str(test_id);
205  print_str("\"\n");
206  print_str("----------------------------------------");
207  print_str("---------------------------------------\n");
208  }
209  }
210 
211  // verbose_time: Print time measurements.
212  static inline void verbose_time(str_t name, long realtime, long cpu) {
213  if(Verbose) {
214  print_str(name);
215  print_long(realtime);
216  print_str(" ms ");
217  print_str("(CPU: ");
218  print_long(cpu);
219  print_str(" ms)\n");
220  }
221  }
222 
223  // verbose_success: Print success message for test.
224  static inline void verbose_success(str_t test_id) {
225  if(Verbose) {
226  print_str("Test '");
227  print_str(test_id);
228  print_str("' successfully finished.\n");
229  }
230  }
231 
232  // verbose_bad_ok: Test function reported ok, but error detected.
233  static inline void verbose_bad_ok(str_t test_id) {
234  if(Verbose) {
235  print_str("Test '");
236  print_str(test_id);
237  print_str("' returned ok status,");
238  print_str("but an error was detected.\n");
239  }
240  }
241 
242  // verbose_failure: Print failure message for test.
243  static inline void verbose_failure(str_t test_id) {
244  if(Verbose) {
245  print_str("*** TEST '");
246  print_str(test_id);
247  print_str(" FAILED! ***\n");
248  }
249  }
250 
251  // verbose_benchmark: Print benchmark name.
252  static inline void verbose_benchmark(str_t bench_name) {
253  if(Verbose) {
254  print_str("Benchmark: '");
255  print_str(bench_name);
256  print_str("'\n");
257  }
258  }
259 
260  // verbose_input: Print input file name.
261  static inline void verbose_input(str_t file_name) {
262  if(Verbose) {
263  print_str("Input File: '");
264  print_str(file_name);
265  print_str("'\n");
266  }
267  }
268 
269  // verbose_result: Print number of result rows.
270  static inline void verbose_result(long eval_result) {
271  if(Verbose) {
272  print_str("Number of result rows: ");
273  print_long(eval_result);
274  print_nl();
275  }
276  }
277 
278  // verbose_cannot_check: Cannot check result, data missing.
279  static inline void verbose_cannot_check() {
280  if(Verbose) {
281  print_str("Result cannot be checked, ");
282  print_str("expected result unknown.\n");
283  }
284  }
285 
286  // verbose_bench_ok: Benchmark was successfully executed (result ok).
287  static inline void verbose_bench_ok() {
288  if(Verbose) {
289  print_str("Benchmark was successfully executed.\n");
290  }
291  }
292 
293  // verbose_real_gt_cpu: Realtime was much bigger than cpu time.
294  static inline void verbose_real_gt_cpu(long realtime, long cputime) {
295  if(Verbose) {
296  print_str("Warning: Wallclock time (");
297  print_long(realtime);
298  print_str(" ms) much more than CPU time (");
299  print_long(cputime);
300  print_str(" ms)\n");
301  }
302  }
303 
304  // verbose_cpu_gt_real: CPU time was significantly more than cpu time.
305  static inline void verbose_cpu_gt_real(long realtime, long cputime) {
306  if(Verbose) {
307  print_str("Warning: CPU time (");
308  print_long(cputime);
309  print_str(" ms) is more than Wallclock time (");
310  print_long(realtime);
311  print_str(" ms)\n");
312  }
313  }
314 
315  // verbose_test_failed: Function call returned false.
316  static inline void verbose_test_failed(str_t msg) {
317  if(Verbose) {
318  print_str("*** TEST FAILED: ");
319  print_str(msg);
320  print_str(" ***\n");
321  }
322  }
323 
324  // verbose_wrong_result: Function call returned unexpected value.
325  static inline void verbose_wrong_result(str_t fun, long result,
326  long expected_result) {
327  if(Verbose) {
328  print_str("*** TEST FAILED: ");
329  print_str("Function ");
330  print_str(fun);
331  print_str(" returned ");
332  print_long(result);
333  print_str(" (expected: ");
334  print_long(expected_result);
335  print_str(") ***\n");
336  }
337  }
338 
339  // verbose_error_row: Relation data structure test failed at this row.
340  static inline void verbose_error_row(int row_num, str_t row_text) {
341  if(Verbose) {
342  print_str("*** TEST FAILED AT ROW ");
343  print_int(row_num);
344  print_str(": ");
345  print_str(row_text);
346  print_str(". ***\n");
347  }
348  }
349 
350  // verbose_num_rows: Print relation size (number of rows).
351  static inline void verbose_num_rows(int num_rows) {
352  if(Verbose) {
353  print_str("Number of rows: ");
354  print_int(num_rows);
355  print_nl();
356  }
357  }
358 
359  // verbose_num_cols: Print number of columns (with bound, free args).
360  static inline void verbose_num_cols(int bound_args, int free_args) {
361  if(Verbose) {
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);
368  print_str(")");
369  print_nl();
370  }
371  }
372 
373  // verbose_implementation: Print implementation (data structure) name.
374  static inline void verbose_implementation(str_t impl_name) {
375  if(Verbose) {
376  print_str("Implementation: ");
377  print_str(impl_name);
378  print_nl();
379  }
380  }
381 
382  // verbose_hashtab_size: Print hash table size.
383  static inline void verbose_hashtab_size(int hash_size) {
384  if(Verbose) {
385  print_str("Hash table size: ");
386  print_int(hash_size);
387  print_nl();
388  }
389  }
390 
391  // verbose_hashtab_usage: Print hash table usage.
392  static inline void verbose_hashtab_usage(int hash_size,
393  int entries_used){
394  if(Verbose) {
395  print_str("Used entries: ");
396  print_int(entries_used);
397  print_str(" (");
398  print_int(IDIV_PERCENT(entries_used, hash_size));
399  print_str("%)");
400  print_nl();
401  }
402  }
403 
404  // verbose_hashtab_chain: Print average hash table chain length.
405  static inline void verbose_hashtab_chain(int num_rows,
406  int entries_used) {
407  if(Verbose) {
408  print_str("Avg. chain length: ");
409  if(entries_used == 0)
410  print_int(0);
411  else {
412  print_int(IDIV_WHOLE(num_rows, entries_used));
413  print_str(".");
414  print_int(IDIV_TENTH(num_rows, entries_used));
415  }
416  print_nl();
417 
418  }
419  }
420 
421  // verbose_bucket_size: Print bucket size.
422  static inline void verbose_bucket_size(int num_entries, int bytes) {
423  if(Verbose) {
424  print_str("Bucket size: ");
425  print_int(num_entries);
426  if(bytes >= 0) {
427  print_str(" (");
428  print_int(bytes);
429  print_str(" Bytes)");
430  }
431  print_nl();
432  }
433  }
434 
435  // verbose_total_buckets: Print total number of buckets.
436  static inline void verbose_total_buckets(int total_buckets) {
437  if(Verbose) {
438  print_str("Total buckets: ");
439  print_int(total_buckets);
440  print_nl();
441  }
442  }
443 
444  // verbose_overflow_buckets: Print number of overflow buckets.
445  static inline void verbose_overflow_buckets(int overflow_buckets) {
446  if(Verbose) {
447  print_str("Overflow buckets: ");
448  print_int(overflow_buckets);
449  print_nl();
450  }
451  }
452 
453  // verbose_rows_per_bucket: Print average entries per bucket.
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));
459  print_str(".");
460  print_int(IDIV_TENTH(num_rows, total_buckets));
461  if(bucket_size > 0) {
462  int rows_per_bucket =
463  IDIV_WHOLE(num_rows, total_buckets)*10+
464  IDIV_TENTH(num_rows, total_buckets);
465  print_str(" (");
466  print_int(IDIV_PERCENT(rows_per_bucket,
467  bucket_size * 10));
468  print_str("%)");
469  }
470  print_nl();
471  }
472  }
473 
474 
475  // verbose_mem_pages: Print memory usage.
476  static inline void verbose_mem_pages(int num_pages) {
477  if(Verbose) {
478  print_str("Used memory pages: ");
479  print_int(num_pages);
480  print_str(" (");
481  print_int(PAGE_KB(num_pages));
482  print_str(" KB)");
483  print_nl();
484  }
485  }
486 
487  // verbose_obj_size: Print size of the data structure object.
488  static inline void verbose_obj_size(int obj_size) {
489  if(Verbose) {
490  print_str("Object size: ");
491  print_int(obj_size);
492  print_str(" Bytes");
493  print_nl();
494  }
495  }
496 
497  // verbose_bytes_per_row: Print memory usage per row.
498  static inline void verbose_bytes_per_row(int num_pages, int obj_size,
499  int num_rows) {
500  if(Verbose && num_rows > 0) {
501  int bytes = PAGE_KB(num_pages) * 1024 + obj_size;
502  print_str("Bytes per row: ");
503  print_int(IDIV_WHOLE(bytes, num_rows));
504  print_str(".");
505  print_int(IDIV_TENTH(bytes, num_rows));
506  print_str(" Bytes");
507  print_nl();
508  }
509  }
510 
511 //-----------------------------------------------------------------------------
512 // Static Methods for Output of Answers:
513 //-----------------------------------------------------------------------------
514 
515  // answer_1: Print answer with one integer argument.
516  static inline void answer_1(long no, int arg1) {
517  if(AnswerOutput && no <= AnswerLimit) {
518  if(no < AnswerLimit) {
519  print_answer_no(no);
520  print_fact_1("answer", arg1);
521  }
522  else if( AnswerLimit > 1) {
523  print_answer_limit();
524  }
525  }
526  }
527 
528  // answer_2: Print answer with 2 integer arguments.
529  static inline void answer_2(long no, int arg1, int arg2) {
530  if(AnswerOutput && no <= AnswerLimit) {
531  if(no < AnswerLimit) {
532  print_answer_no(no);
533  print_fact_2("answer", arg1, arg2);
534  }
535  else if( AnswerLimit > 1) {
536  print_answer_limit();
537  }
538  }
539  }
540 
541  // answer_s: Print answer with one string argument.
542  static inline void answer_s(long no, str_t arg1) {
543  if(AnswerOutput && no <= AnswerLimit) {
544  if(no < AnswerLimit) {
545  print_answer_no(no);
546  print_fact_s("answer", arg1);
547  }
548  else if( AnswerLimit > 1) {
549  print_answer_limit();
550  }
551  }
552  }
553 
554  // answer_5s: Print answer with five string arguments.
555  static inline void answer_5s(long no, str_t arg1, str_t arg2,
556  str_t arg3, str_t arg4, str_t arg5) {
557  if(AnswerOutput && no <= AnswerLimit) {
558  if(no < AnswerLimit) {
559  print_answer_no(no);
560  print_fact_5s("answer", arg1, arg2, arg3,
561  arg4, arg5);
562  }
563  else if( AnswerLimit > 1) {
564  print_answer_limit();
565  }
566  }
567  }
568 
569 //-----------------------------------------------------------------------------
570 // Static Methods for Output of Relation Statistics:
571 //-----------------------------------------------------------------------------
572 
573  // rel_size_headline: Print headline for relation list.
574  static inline void rel_size_headline() {
575  if(Rel) {
576  print_nl();
577  print_str("Relations and Domains:\n");
578  print_str("--------------------- \n");
579  }
580  }
581 
582  // rel_size: Show number of rows and pages of relation:
583  static inline void rel_size(rel_t rel) {
584  if(Rel) {
585  print_rel_size(rel->name(), rel->num_rows(),
586  rel->num_pages());
587  }
588  }
589 
590  // rel_size_nonstd: Version for non-standard implementations.
591  static inline void rel_size_nonstd(str_t name, long num_rows,
592  long num_pages){
593  if(Rel) {
594  print_rel_size(name, num_rows, num_pages);
595  }
596  }
597 
598  // rel_size_strtab: Print size of a string table.
599  static inline void rel_size_strtab(strtab_t tab) {
600  if(Rel) {
601  print_rel_size_strtab(tab);
602  }
603  }
604 
605  // rel_size_atomtab: Print size of an atom table.
606  static inline void rel_size_atomtab(atomtab_t tab) {
607  if(Rel) {
608  print_rel_size_atomtab(tab);
609  }
610  }
611 
612  // rel_size_done: Called at the end of the relation/domain table.
613  static inline void rel_size_done() {
614  if(Rel) {
615  print_nl();
616  }
617  }
618 
619 //-----------------------------------------------------------------------------
620 // Static Method for Output of Memory Pools:
621 //-----------------------------------------------------------------------------
622 
623  // mem_pools_tab: Show table of memory pools.
624  static inline void mem_pools_tab(str_t headline = STR_NULL) {
625  if(MemPools) {
626  print_mem_pools_tab(headline);
627  }
628  }
629 
630 //-----------------------------------------------------------------------------
631 // Static Method for Benchmark Summary Line:
632 //-----------------------------------------------------------------------------
633 
634  // summary: Print summary line.
635  static inline void summary(str_t bench_id, long load_time,
636  long eval_time, long total_time, str_t result) {
637  if(Summary)
638  print_summary(bench_id, load_time, eval_time,
639  total_time, result);
640  }
641 
642 //-----------------------------------------------------------------------------
643 // Static Methods for Debug Output:
644 //-----------------------------------------------------------------------------
645 
646  // debug_msg: Print string only in debug mode.
647  static inline void debug_msg(str_t msg) {
648  if(Debug)
649  print_str(msg);
650  }
651 
652  // debug_int: Print integer value only in debug mode.
653  static inline void debug_int(int i) {
654  if(Debug)
655  print_int(i);
656  }
657 
658  // debug_long: Print long value only in debug mode.
659  static inline void debug_long(long n) {
660  if(Debug)
661  print_long(n);
662  }
663 
664  // debug_nl: Print newline only in debug mode.
665  static inline void debug_nl() {
666  if(Debug)
667  print_nl();
668  }
669 
670  // debug_fact_1: Print fact with predicate and one integer argument.
671  static inline void debug_fact_1(str_t pred, int arg1) {
672  if(Debug)
673  print_fact_1(pred, arg1);
674  }
675 
676  // debug_fact_2: Print fact with predicate and two integer arguments.
677  static inline void debug_fact_2(str_t pred, int arg1, int arg2) {
678  if(Debug)
679  print_fact_2(pred, arg1, arg2);
680  }
681 
682  // debug_ival: Print attribute-value pair (int val) in debug mode.
683  static inline void debug_ival(str_t attr, int i) {
684  if(Debug) {
685  print_str(attr);
686  print_int(i);
687  print_nl();
688  }
689  }
690 
691  // debug_lval: Print attribute-value pair (long val) in debug mode.
692  static inline void debug_lval(str_t attr, long n) {
693  if(Debug) {
694  print_str(attr);
695  print_int(n);
696  print_nl();
697  }
698  }
699 
700  // debug_sval: Print attribute-value pair (string val) in debug mode.
701  static inline void debug_sval(str_t attr, str_t s) {
702  if(Debug) {
703  print_str(attr);
704  print_str("'");
705  print_str(s);
706  print_str("'");
707  print_nl();
708  }
709  }
710 
711  // debug_mempages: Print number of memory pages in debug mode.
712  static inline void debug_mempages(str_t attr, int num_pages) {
713  if(Debug) {
714  print_str(attr);
715  print_int(num_pages);
716  print_str(" [");
717  print_int(PAGE_KB(num_pages));
718  print_str(" KB]");
719  print_nl();
720  }
721  }
722 
723  // debug_hashusage: Print number of used entries in a hash table.
724  static inline void debug_hashusage(str_t attr, int entries_used,
725  int hash_size) {
726  if(Debug) {
727  print_str(attr);
728  print_int(entries_used);
729  print_str(" [");
730  print_int(IDIV_PERCENT(entries_used, hash_size));
731  print_str("%]");
732  print_nl();
733  }
734  }
735 
736  // debug_hashchain: Print average chain length for a hash table.
737  static inline void debug_hashchain(str_t attr, int entries_used,
738  int num_rows) {
739  if(Debug) {
740  print_str(attr);
741  print_int(entries_used);
742  print_int(IDIV_WHOLE(num_rows, entries_used));
743  print_str(".");
744  print_int(IDIV_TENTH(num_rows, entries_used));
745  print_nl();
746  }
747  }
748 
749 
750 //-----------------------------------------------------------------------------
751 // Methods and Macros for printing trace information in debug mode:
752 //-----------------------------------------------------------------------------
753 
754  // debug_trace_iteration: Print trace information for main loop.
755  static void debug_trace_iteration(int stacksize)
756  {
757  if(Debug) {
758  print_str("NEXT ITERATION [Stacksize: ");
759  print_int(stacksize);
760  print_str("]");
761  print_nl();
762  }
763  }
764 
765  // debug_trace_label: Print trace information for label reached.
766  static void debug_trace_label(str_t type, int label,
767  str_t rule, str_t fact_type)
768  {
769  if(Debug) {
770  static const int LABEL_WIDTH = 3;
771  print_str(" ");
772  print_str(type);
773  print_str("[");
774  print_int(label);
775  print_str("] ");
776  print_str(str_fill(label, LABEL_WIDTH));
777  print_str(rule);
778  print_str(" <= ");
779  print_str(fact_type);
780  print_nl();
781  }
782  }
783 
784  // debug_trace_assign: Print trace information for variable assigned.
785  static void debug_trace_assign(str_t var, int value)
786  {
787  if(Debug) {
788  print_str(" ");
789  print_str(var);
790  print_str(" = ");
791  print_int(value);
792  print_nl();
793  }
794  }
795 
796  // debug_trace_pop_var: Print trace information for variable restored.
797  static void debug_trace_pop_var(str_t var, int value)
798  {
799  if(Debug) {
800  print_str(" ");
801  print_str(var);
802  print_str(" = ");
803  print_int(value);
804  print_str(" [Restored from Stack]");
805  print_nl();
806  }
807  }
808 
809  static void debug_trace_rule_app(int call_depth, str_t rule,
810  str_t pred, int num_args,
811  int arg1, int arg2)
812  {
813  if(Debug) {
814  while(call_depth-- > 0)
815  print_str(" ");
816  print_str("RULE ");
817  print_str(rule);
818  print_str(" <= ");
819  print_str(pred);
820  print_str("(");
821  if(num_args > 0)
822  print_int(arg1);
823  if(num_args > 1) {
824  print_str(", ");
825  print_int(arg2);
826  }
827  print_str(")");
828  print_nl();
829  }
830  }
831 
832  static void debug_trace_call(int call_depth, str_t pred, int num_args,
833  int arg1, int arg2)
834  {
835  if(Debug) {
836  while(call_depth-- > 0)
837  print_str(" ");
838  print_str("CALL: ");
839  print_str(pred);
840  print_str("(");
841  if(num_args > 0)
842  print_int(arg1);
843  if(num_args > 1) {
844  print_str(", ");
845  print_int(arg2);
846  }
847  print_str(")");
848  print_nl();
849  }
850  }
851 
852 #if VER_DEBUG_OUT_ENABLED
853 
854 // Trace-Output for Standard Algorithm (with Switch):
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)))
871 
872 // Trace-Output for Function Call Version:
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)
879 
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)))
889 
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, \
893  (PRED), 0, 0, 0))
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)))
902 
903 // If debug output is not enabled, trace output is not compiled in:
904 #else
905 
906 #define OUT_TRACE_ITERATION(STACKSIZE) \
907  ((void)0)
908 #define OUT_TRACE_START(LABEL, RULE, FACT_TYPE) \
909  ((void)0)
910 #define OUT_TRACE_START_REC(LABEL, RULE, FACT_TYPE) \
911  ((void)0)
912 #define OUT_TRACE_CONT(LABEL, RULE, FACT_TYPE) \
913  ((void)0)
914 #define OUT_TRACE_ANSWER(LABEL, RULE, FACT_TYPE) \
915  ((void)0)
916 #define OUT_TRACE_RESTORE(LABEL, RULE, FACT_TYPE) \
917  ((void)0)
918 #define OUT_TRACE_ASSIGN(VAR, VALUE) \
919  ((void)0)
920 #define OUT_TRACE_POP_VAR(VAR, VALUE) \
921  ((void)0)
922 
923 #define OUT_TRACE_DEPTH_DECL \
924  void out_depth_not_used()
925  // If we simply leave it empty, gcc -pedantic gives a warning
926  // that there two semicolons one after the other.
927 #define OUT_TRACE_DEPTH_INIT \
928  ((void)0)
929 #define OUT_TRACE_DEPTH \
930  ((void)0)
931 
932 #define OUT_TRACE_RULE_APP_0(RULE, PRED) \
933  ((void)0)
934 #define OUT_TRACE_RULE_APP_1(RULE, PRED, ARG1) \
935  ((void)0)
936 #define OUT_TRACE_RULE_APP_2(RULE, PRED, ARG1, ARG2) \
937  ((void)0)
938 
939 #define OUT_TRACE_CALL_0(PRED) \
940  ((void)0)
941 #define OUT_TRACE_CALL_1(PRED, ARG1) \
942  ((void)0)
943 #define OUT_TRACE_CALL_2(PRED, ARG1, ARG2) \
944  ((void)0)
945 
946 // End of conditional compilation of debug output:
947 #endif
948 
949 //-----------------------------------------------------------------------------
950 // Static Methods for Printing Help:
951 //-----------------------------------------------------------------------------
952 
953  // help_line: One line of the -h help output:
954  static inline void help_line(str_t line) {
955  print_str(line);
956  print_nl();
957  }
958 
959  // : One line of the -h help output:
960  static inline void help_test(str_t id, str_t name) {
961  static const int ID_WIDTH = 15;
962  print_str(id);
963  print_str(": ");
964  print_str(str_indent(ID_WIDTH - str_len(id)));
965  print_str(name);
966  print_nl();
967  }
968 
969 //-----------------------------------------------------------------------------
970 // Auxiliary Static Methods for Output:
971 //-----------------------------------------------------------------------------
972 
973  private:
974 
975  // print_str: Print string.
976  static void print_str(str_t msg);
977 
978  // print_int: Print integer.
979  static void print_int(int i);
980 
981  // print_long: Print long value.
982  static void print_long(long n);
983 
984  // print_nl: Print newline.
985  static void print_nl();
986 
987  // print_fact_1: Print fact with predicate and one integer argument.
988  static void print_fact_1(str_t pred, int arg1);
989 
990  // print_fact_2: Print fact with predicate and two integer arguments.
991  static void print_fact_2(str_t pred, int arg1, int arg2);
992 
993  // print_fact_s: Print fact with predicate and one string argument.
994  static void print_fact_s(str_t pred, str_t arg1);
995 
996  // print_fact_5s: Print fact with predicate and five string arguments.
997  static void print_fact_5s(str_t pred, str_t arg1, str_t arg2,
998  str_t arg3, str_t arg4, str_t arg5);
999 
1000  // print_answer_limit: Print information that there are more answers.
1001  static void print_answer_limit();
1002 
1003  // print_answer_no: Print prefix of line showing a computed answer.
1004  static void print_answer_no(long no);
1005 
1006  // print_summary: Print benchmark summary line.
1007  static void print_summary(str_t bench_id, long load_time,
1008  long eval_time, long total_time, str_t result);
1009 
1010  // print_rel_size: Print some data about a relation.
1011  static void print_rel_size(str_t name, long num_rows, long num_pages);
1012 
1013  // print_rel_size_strtab: Print some data about a string table.
1014  static void print_rel_size_strtab(strtab_t tab);
1015 
1016  // print_rel_size_atomtab: Print some data about an atom table.
1017  static void print_rel_size_atomtab(atomtab_t tab);
1018 
1019  // print_mem_pools_tab: Print table of memory pools.
1020  static void print_mem_pools_tab(str_t headline);
1021 
1022 //-----------------------------------------------------------------------------
1023 // There are no objects of this class, therefore no constructor is available:
1024 //-----------------------------------------------------------------------------
1025 
1026  private:
1027 
1028  // Constructor:
1029  out_c(); // Not implemented
1030 
1031  // Destructor:
1032  ~out_c(); // Not implemented
1033 
1034  // Copy-Constructor:
1035  out_c(const out_c& obj); // Not implemented
1036 
1037  // Assignment operator:
1038  out_c& operator=(const out_c& obj); // Not implemented
1039 
1040 //-----------------------------------------------------------------------------
1041 // Private Class Variables:
1042 //-----------------------------------------------------------------------------
1043 
1044  private:
1045 
1046  // Verbose mode:
1047  static bool Verbose;
1048 
1049  // AnswerOutput: Is output of answers switched on?
1050  static bool AnswerOutput;
1051 
1052  // AnswerLimit: One more than the maximal number of answers to print.
1053  static long AnswerLimit;
1054 
1055  // Debug mode:
1056  static bool Debug;
1057 
1058  // Flag for printing summary line:
1059  static bool Summary;
1060 
1061  // Flag for printing newline at end of summary line (else only a tab):
1062  static bool Summary_NewLine;
1063  // If there is no newline, the output can be easily combined
1064  // with the output of the time command in one line.
1065 
1066  // Flag for showing relation statistics:
1067  static bool Rel;
1068 
1069  // Flag for showing memory pool data:
1070  static bool MemPools;
1071 
1072  // Flag for showing data structure dump:
1073  static bool Dump;
1074 
1075 
1076 //=============================================================================
1077 // End of Class:
1078 //=============================================================================
1079 
1080 };
1081 
1082 
1083 //=============================================================================
1084 // End of Include File:
1085 //=============================================================================
1086 
1087 #endif
1088 
str_t str_indent(int n)
Definition: str.cpp:150
Definition: strtab.h:106
Definition: out.h:70
#define IDIV_TENTH(X, Y)
Definition: idiv.h:98
Definition: atomtab.h:78
int str_len(register str_t str)
Definition: str.cpp:34
Definition: rel.h:72
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