| 1 | #include <iostream> | 
|---|
| 2 | #include <sstream> | 
|---|
| 3 |  | 
|---|
| 4 | #include <regex> | 
|---|
| 5 |  | 
|---|
| 6 | #include <string> | 
|---|
| 7 |  | 
|---|
| 8 | extern "C"{ | 
|---|
| 9 | #include <unistd.h> | 
|---|
| 10 | } | 
|---|
| 11 |  | 
|---|
| 12 | #include "log.hh" | 
|---|
| 13 | #include "schema.hh" | 
|---|
| 14 | #include "impedance.hh" | 
|---|
| 15 | #include "random.hh" | 
|---|
| 16 |  | 
|---|
| 17 | using namespace std; | 
|---|
| 18 |  | 
|---|
| 19 | struct stats_visitor : prod_visitor { | 
|---|
| 20 | int nodes = 0; | 
|---|
| 21 | int maxlevel = 0; | 
|---|
| 22 | long retries = 0; | 
|---|
| 23 | map<const char *, long> production_stats; | 
|---|
| 24 | virtual void visit(struct prod *p) { | 
|---|
| 25 | nodes++; | 
|---|
| 26 | if (p->level > maxlevel) | 
|---|
| 27 | maxlevel = p->level; | 
|---|
| 28 | production_stats[typeid(*p).name()]++; | 
|---|
| 29 | retries += p->retries; | 
|---|
| 30 | } | 
|---|
| 31 | void report() { | 
|---|
| 32 | cerr << "production statistics"<< endl; | 
|---|
| 33 | vector<pair<const char *, long>> report; | 
|---|
| 34 | for (auto p : production_stats) | 
|---|
| 35 | report.push_back(p); | 
|---|
| 36 | stable_sort( | 
|---|
| 37 | report.begin(), report.end(), | 
|---|
| 38 | [](const pair<std::string, long> &a, const pair<std::string, long> &b) { return a.second > b.second; }); | 
|---|
| 39 | for (auto p : report) { | 
|---|
| 40 | cerr << p.second << "\t"<< p.first << endl; | 
|---|
| 41 | } | 
|---|
| 42 | } | 
|---|
| 43 | }; | 
|---|
| 44 |  | 
|---|
| 45 | void stats_collecting_logger::generated(prod &query) { | 
|---|
| 46 | queries++; | 
|---|
| 47 |  | 
|---|
| 48 | stats_visitor v; | 
|---|
| 49 | query.accept(&v); | 
|---|
| 50 |  | 
|---|
| 51 | sum_nodes += v.nodes; | 
|---|
| 52 | sum_height += v.maxlevel; | 
|---|
| 53 | sum_retries += v.retries; | 
|---|
| 54 | } | 
|---|
| 55 |  | 
|---|
| 56 | void cerr_logger::report() { | 
|---|
| 57 | cerr << endl << "queries: "<< queries << endl; | 
|---|
| 58 | // 	 << " (" << 1000.0*query_count/gen_time.count() << " gen/s, " | 
|---|
| 59 | // 	 << 1000.0*query_count/query_time.count() << " exec/s)" << endl; | 
|---|
| 60 | cerr << "AST stats (avg): height = "<< sum_height / queries << " nodes = "<< sum_nodes / queries << endl; | 
|---|
| 61 |  | 
|---|
| 62 | vector<pair<std::string, long>> report; | 
|---|
| 63 | for (auto e : errors) { | 
|---|
| 64 | report.push_back(e); | 
|---|
| 65 | } | 
|---|
| 66 | stable_sort(report.begin(), report.end(), | 
|---|
| 67 | [](const pair<std::string, long> &a, const pair<std::string, long> &b) { return a.second > b.second; }); | 
|---|
| 68 | long err_count = 0; | 
|---|
| 69 | for (auto e : report) { | 
|---|
| 70 | err_count += e.second; | 
|---|
| 71 | cerr << e.second << "\t"<< e.first.substr(0, 80) << endl; | 
|---|
| 72 | } | 
|---|
| 73 | cerr << "error rate: "<< (float)err_count / (queries) << endl; | 
|---|
| 74 | impedance::report(); | 
|---|
| 75 | } | 
|---|
| 76 |  | 
|---|
| 77 | void cerr_logger::generated(prod &p) { | 
|---|
| 78 | stats_collecting_logger::generated(p); | 
|---|
| 79 | if ((10 * columns - 1) == queries % (10 * columns)) | 
|---|
| 80 | report(); | 
|---|
| 81 | } | 
|---|
| 82 |  | 
|---|
| 83 | void cerr_logger::executed(prod &query) { | 
|---|
| 84 | (void)query; | 
|---|
| 85 | if (columns - 1 == (queries % columns)) { | 
|---|
| 86 | cerr << endl; | 
|---|
| 87 | } | 
|---|
| 88 | cerr << "."; | 
|---|
| 89 | } | 
|---|
| 90 |  | 
|---|
| 91 | void cerr_logger::error(prod &query, const dut::failure &e) { | 
|---|
| 92 | (void)query; | 
|---|
| 93 | istringstream err(e.what()); | 
|---|
| 94 | string line; | 
|---|
| 95 |  | 
|---|
| 96 | if (columns - 1 == (queries % columns)) { | 
|---|
| 97 | cerr << endl; | 
|---|
| 98 | } | 
|---|
| 99 | getline(err, line); | 
|---|
| 100 | errors[line]++; | 
|---|
| 101 | if (dynamic_cast<const dut::timeout *>(&e)) | 
|---|
| 102 | cerr << "t"; | 
|---|
| 103 | else if (dynamic_cast<const dut::syntax *>(&e)) | 
|---|
| 104 | cerr << "S"; | 
|---|
| 105 | else if (dynamic_cast<const dut::broken *>(&e)) | 
|---|
| 106 | cerr << "C"; | 
|---|
| 107 | else | 
|---|
| 108 | cerr << "e"; | 
|---|
| 109 | } | 
|---|
| 110 |  | 
|---|