-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.cpp
240 lines (216 loc) · 8.53 KB
/
main.cpp
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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
#include <iostream>
#include <sstream>
#include <fstream>
#include <string>
#include <cstdio>
#include <vector>
#include <map>
#include <unordered_map>
#include "Event.hpp"
#include "Log.hpp"
#include "globals.hpp"
std::string chooseRandom(int init, const std::vector<bool> &cond){ // L1
std::stringstream log; log << std::boolalpha;
int val = init; // L2
log << "L2 " << "val=" << val << " "; // L2 instrument: val
int loop = cond.size(); // number of loops
for(int i=0; i<loop; i++){ // L3: loop condition
log << "L3 " << (i<loop) << " "; // L3 instrument: loop condition
log << "L4 " << cond[i] << " "; // L4 instrument: if condition
if(cond[i]){ // L4: if condition
val--; // L5
log << "L5 " << "val=" << val << " "; // L5 instrument: val change
}
}
log << "L6 " << (val > 0) << " "; // L6 instrument: if condition
if(val > 0){ // L6: if condition
log << "L7 " << "fail "; // L7 instrument: throw Exception
}
return log.str();
}
std::pair<Log*, std::vector<Event>> logCompare(Log* failed, std::vector<Log*> succeeds){
std::vector<Event> prefix; // longest common prefix
if(succeeds.size()==0) {return std::make_pair(nullptr, prefix);}
int max_length = 0; // longest prefix length
int max_total = 0;
int max_idx = 0;
std::pair<Log*, std::vector<Event>> out;
for(int i=0; i<succeeds.size(); i++){
// int length = compare_one_log(failed, succeeds[i]);
// std::cout << "comapring " << i << std::endl;
// auto result = compare_log_contexts(failed, succeeds[i]);
auto result = compare_log_maploops(failed, succeeds[i]);
int length = result.first;
if(length > max_length || (length == max_length && succeeds[i]->parsed.size() > max_total) ){
out.first = succeeds[i];
out.second = result.second;
max_length = length; // update max length
max_idx = i; // the run index in vector woth longest common prefix
max_total = succeeds[i]->parsed.size();
}
}
// int i = 0; Log lon(succeed_str[max_idx]);
// while(i<lon.current || !lon.parsedAll()){
// Event* es = lon.getEvent(i);
// if(es == nullptr){
// break;
// }else{
// longest.push_back(*es);
// }
// i++;
// }
return out; //std::make_pair(max_length, succeeds[max_idx]);
}
int main (int argc, char *argv[]){
std::string filename = "step2.log";
std::ifstream file1("logs/"+filename);
if (!file1.is_open()) {
std::cout << "Failed to open logs." << std::endl;
}
std::string newLogIndicator = "Method Entry";
std::string failureIndicator = "BlockManager$ReplicationMonitor";
std::string line;
// std::unordered_map<int, int> loopStarts; //= {{4, 0}, {1, 0}};
std::unordered_map <int, int> loopIds = {{4, 1},{3, 1},{2, 1},{1, 2}, {0, 2}};
std::unordered_map <int, int> loopStartIds = {{4, 1},{1, 2}};
std::vector<Log*> logs; //
std::unordered_map<int, Log*> threads;
int num_fails = 0;
int num_threads = 0; bool fail_encountered = false;
while(std::getline(file1, line)){
bool newLog = false; int thread = -1; bool fail = false;
std::string::size_type temp_id = line.find("IPC Server handler ");
if(temp_id != std::string::npos){ // deal with thread
std::stringstream ss (line.substr(temp_id+19));
ss >> thread; // thread number
}
else if(line.find(failureIndicator) != std::string::npos){ // failed run
if(!fail_encountered){ // fail log did not appear before
newLog = true; fail_encountered = true;
}
fail = true;
thread = -2;
}
if(threads.find(thread) == threads.end()){ // new thread
// threads[thread] = num_threads; num_threads++;
newLog = true;
}
temp_id = line.find(newLogIndicator);
if(temp_id != std::string::npos){ // new Log
newLog = true;
if(thread==-2) {num_fails++;}
}
Log* log = nullptr;
if(newLog){
// std::cout << "new log! " << "fail: " << fail << std::endl;
log = new Log();
log->loopIds = loopIds;
log->loopStartIds = loopStartIds; log->loopIds_count = loopStartIds.size() + 1;
// log->init_contexts(loopStarts);
logs.push_back(log);
threads[thread] = log; // new current log for that thread
num_threads++;
}else{
log = threads[thread];
}
log->to_parse.push_back(line);
log->fail = fail;
// std::cout << line << ": thread # " << thread << " fail: " << fail << std::endl;
}
std::cout << "# logs " << logs.size() << std::endl;
std::vector<Log*> succeeds; std::vector<Log*> fails;
for(Log* l : logs){
if(l==nullptr){
std::cout << "null" << std::endl;
}
else if(l->fail){
l->parseAll();
fails.push_back(l);
}else{
l->parseAll();
succeeds.push_back(l);
}
}
if(fails.size()==0){
std::cout << "no failed log found " << std::endl;
return 1;
}
int k = 0;
std::cout << "failed run: " << std::endl;
fails[k]->printAll();
// fails[k]->printLoops();
auto result = logCompare(fails[k], succeeds);
for(int i=0; i<result.second.size(); i++){
std::cout << result.second[i].idx << ":ID=" << result.second[i].lineNum << " ";
}std::cout << std::endl;
// auto result = logCompare(fails[k], succeeds);
// //std::cout << max_idx ; // << " L" << fails[2]->getEvent(max_idx)->lineNum << std::endl;
int length = result.second.size();
std::cout << "length: " << (length) << ". ";
// result.second->printAll();
result.first->printAll();
std::cout << std::endl;
fails[k]->printAll();
if( length==fails[k]->parsed.size() && length==result.first->parsed.size() ){
std::cout << "no divergence" << std::endl;
}else{
std::cout << "div at: " ;
if(length==0){ // div at the beginning
if(fails[k]->parsed.size()>1 && fails[k]->getEvent(0)->lineNum==-1){
std::cout << "HERE" << std::endl;
fails[k]->getEvent(1)->print();
}else{
fails[k]->getEvent(0)->print();
}
}else if(length==1){
if(fails[k]->parsed.size()>1 && result.second.back().lineNum==-1){ // the first one is entry
fails[k]->getEvent(1)->print(); // print the first one after the entry
}else{
result.second.back().print();
}
}else {
result.second.back().print();
}
std::cout << std::endl;
}
//
// if(false){
// std::cout << "failed contexts: " << std::endl;
// fails[k]->printContexts();
// std::cout << "succeeds[0] contexts: " << std::endl;
// succeeds[2]->printContexts();
// std::cout << "/////////// " << std::endl;
// for(int i=0; i<fails[k]->parsed.size(); i++){
// std::cout << fails[k]->getEvent(i)->idx << ": " << fails[k]->getEvent(i)->lineNum << " ";
// } std::cout << std::endl;
// for(Event* c : fails[k]->parsed){
// std::cout << c->idx << ": L" << c->lineNum ;
// if(c->context != nullptr){std::cout << ": " << c->context->idx << ":L" << c->context->lineNum;}
// std::cout << std::endl;
// for(Event* e : fails[k]->contextMap[c->idx]){
// std::cout << e->idx<< " ";
// }std::cout << std::endl;
// } std::cout << std::endl;
// }
// return 0;
}
/* // current output:
Failed Run:
L2 val=3 L3 true L4 false L3 true L4 false L3 true L4 false L6 true L7 fail
Successful Runs:
Run 0: L2 val=3 L3 true L4 true L5 val=2 L3 true L4 true L5 val=1 L3 true L4 true L5 val=0 L6 false
Run 1: L2 val=3 L3 true L4 true L5 val=2 L3 true L4 false L3 true L4 false L3 true L4 true L5 val=1 L3 true L4 true L5 val=0 L6 false
Run 2: L2 val=4 L3 true L4 false L3 true L4 true L5 val=3 L3 true L4 true L5 val=2 L3 true L4 true L5 val=1 L3 true L4 true L5 val=0 L6 false
//// if we consider CE with different value (True / False) as different log:
Prefix:
L2 L3 L4 L3
Longest:
L2 L3 L4 L3 L4 L5 L3 L4 L5 L3 L4 L5 L3 L4 L5 L6
// diverge at L3
//// otherwise:
Prefix:
L2 L3 L4 L3 L4
Longest:
L2 L3 L4 L3 L4 L5 L3 L4 L5 L3 L4 L5 L3 L4 L5 L6
// diverge at L4
*/