-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathrestrace.js
48 lines (45 loc) · 1.2 KB
/
restrace.js
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
// Process each JSON object of the input file as a seperate optimizer trace.
// Used to process the result files in the MYSQL opt_trace test suite.
// These files contains traces for multiple queries.
function findJSONobject(text)
{
var len = text.length;
var pos = 0;
var braces= 0;
while (pos < len)
{
switch (text[pos]) {
case '{':
++braces;
break;
case '}':
if (--braces == 0)
return pos;
break;
default:
break;
}
++pos;
}
return pos;
}
var fs = require('fs');
var script = require('./trace');
fs.readFile(process.argv[2], 'utf8', function(err, text) {
if (err) {
return console.log(err);
}
while (text.length > 0)
{
startPos = text.indexOf("\"steps\": [");
if (startPos < 0) break
start = "{\n" + text.substring(startPos);
endPos = findJSONobject(start);
trace = start.substring(0, endPos+1);
output = script.processTrace(trace);
console.log(output);
console.log("======================================================\n");
text = start.substr(endPos+1);
}
return;
});