-
Notifications
You must be signed in to change notification settings - Fork 0
/
impedance.cc
102 lines (85 loc) · 2.23 KB
/
impedance.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
#include "impedance.hh"
#include "log.hh"
#include <iostream>
using namespace std;
static map<const char*, long> occurances_in_failed_query;
static map<const char*, long> occurances_in_ok_query;
static map<const char*, long> retries;
static map<const char*, long> limited;
static map<const char*, long> failed;
impedance_visitor::impedance_visitor(map<const char*, long> &occured)
: _occured(occured)
{ }
void impedance_visitor::visit(struct prod *p)
{
found[typeid(*p).name()] = true;
}
impedance_visitor::~impedance_visitor()
{
for(auto pair : found)
_occured[pair.first]++;
}
void impedance_feedback::executed(prod &query)
{
impedance_visitor v(occurances_in_ok_query);
query.accept(&v);
}
void impedance_feedback::error(prod &query, const dut::failure &e)
{
(void)e;
impedance_visitor v(occurances_in_failed_query);
query.accept(&v);
}
namespace impedance {
bool matched(const char *name)
{
if (100 > occurances_in_failed_query[name])
return true;
double error_rate = (double)occurances_in_failed_query[name]
/ (occurances_in_failed_query[name] + occurances_in_ok_query[name]);
if (error_rate > 0.99)
return false;
return true;
}
void report()
{
cerr << "impedance report: " << endl;
for (auto pair : occurances_in_failed_query) {
cerr << " " << pretty_type(pair.first) << ": " <<
pair.second << "/" << occurances_in_ok_query[pair.first]
<< " (bad/ok)";
if (!matched(pair.first))
cerr << " -> BLACKLISTED";
cerr << endl;
}
}
void report(std::ostream &out)
{
out << "{\"impedance\": [ " << endl;
for (auto pair = occurances_in_failed_query.begin();
pair != occurances_in_failed_query.end();
++pair) {
out << "{\"prod\": \"" << pretty_type(pair->first) << "\","
<< "\"bad\": " << pair->second << ", "
<< "\"ok\": " << occurances_in_ok_query[pair->first] << ", "
<< "\"limited\": " << limited[pair->first] << ", "
<< "\"failed\": " << failed[pair->first] << ", "
<< "\"retries\": " << retries[pair->first] << "} ";
if (next(pair) != occurances_in_failed_query.end())
out << "," << endl;
}
out << "]}" << endl;
}
void retry(const char *p)
{
retries[p]++;
}
void limit(const char *p)
{
limited[p]++;
}
void fail(const char *p)
{
failed[p]++;
}
}