6 #ifndef HAVE_BOOST_REGEX
9 #include <boost/regex.hpp>
12 using boost::regex_match;
34 map<const char*, long> production_stats;
35 virtual void visit(
struct prod *p) {
37 if (p->
level > maxlevel)
39 production_stats[
typeid(*p).name()]++;
43 cerr <<
"production statistics" << endl;
44 vector<pair<const char *, long> > report;
45 for (
auto p : production_stats)
47 stable_sort(report.begin(), report.end(),
48 [](
const pair<std::string, long> &a,
49 const pair<std::string, long> &b)
50 { return a.second > b.second; });
51 for (
auto p : report) {
52 cerr << p.second <<
"\t" << p.first << endl;
57 void stats_collecting_logger::generated(
prod &query)
65 sum_height += v.maxlevel;
66 sum_retries += v.retries;
69 void cerr_logger::report()
71 cerr << endl <<
"queries: " << queries << endl;
74 cerr <<
"AST stats (avg): height = " << sum_height/queries
75 <<
" nodes = " << sum_nodes/queries << endl;
77 vector<pair<std::string, long> > report;
78 for (
auto e : errors) {
81 stable_sort(report.begin(), report.end(),
82 [](
const pair<std::string, long> &a,
83 const pair<std::string, long> &b)
84 { return a.second > b.second; });
86 for (
auto e : report) {
87 err_count += e.second;
88 cerr << e.second <<
"\t" << e.first.substr(0,80) << endl;
90 cerr <<
"error rate: " << (float)err_count/(queries) << endl;
95 void cerr_logger::generated(
prod &p)
97 stats_collecting_logger::generated(p);
98 if ((10*columns-1) == queries%(10*columns))
102 void cerr_logger::executed(
prod &query)
105 if (columns-1 == (queries%columns)) {
114 istringstream err(e.what());
117 if (columns-1 == (queries%columns)) {
132 pqxx_logger::pqxx_logger(std::string target, std::string conninfo,
struct schema &s)
134 c = make_shared<pqxx::connection>(conninfo);
137 w.exec(
"set application_name to '" PACKAGE
"::log';");
139 c->prepare(
"instance",
140 "insert into instance (rev, target, hostname, version, seed) "
141 "values ($1, $2, $3, $4, $5) returning id");
144 gethostname(hostname,
sizeof(hostname));
149 result r = w.prepared(
"instance")(GITREV)(target)(hostname)(s.version)(seed.str()).exec();
151 id = r[0][0].as<
long>(id);
154 "insert into error (id, msg, query, sqlstate) "
155 "values (" + to_string(
id) +
", $1, $2, $3)");
157 w.exec(
"insert into stat (id) values (" + to_string(
id) +
")");
159 "update stat set generated=$1, level=$2, nodes=$3, updated=now() "
160 ", retries = $4, impedance = $5 "
161 "where id = " + to_string(
id));
172 w.prepared(
"error")(e.what())(s.str())(e.sqlstate).exec();
176 void pqxx_logger::generated(
prod &query)
178 stats_collecting_logger::generated(query);
179 if (999 == (queries%1000)) {
182 impedance::report(s);
183 w.prepared(
"stat")(queries)(sum_height/queries)(sum_nodes/queries)(sum_retries/queries)(s.str()).exec();
feedback to the grammar about failed productions
Base class providing schema information to grammar.
Base class for walking the AST.
Base class for AST nodes.
int level
Level of this production in the AST. 0 for root node.
long retries
Number of retries in this production.
virtual void accept(prod_visitor *v)
Visitor pattern for walking the AST.