-
Notifications
You must be signed in to change notification settings - Fork 0
/
analyze.js
executable file
·78 lines (63 loc) · 1.71 KB
/
analyze.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
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
#!/usr/bin/env node
const { readFile, readdir } = require('fs/promises');
const entries = {};
const getFiles = async (directory) => {
const entries = await readdir(directory);
const files = entries.filter((e) => e.match(/.+\.out$/));
return files;
};
const entryForFile = (filename) => {
const fileparts = filename.match(/.+\/(.+)\.out$/);
if (!fileparts) {
return;
}
const parts = fileparts[1].match(/(.+)\.sql/);
if (!parts) {
return fileparts[1];
}
return parts[1];
};
const processFile = async (filename) => {
const entry = entryForFile(filename);
if (!entry) {
console.log(`Unable to parse file ${filename}`);
return;
}
const data = await readFile(filename, 'utf-8');
const lines = data.split('\n');
for (let line of lines) {
const parts = line.match(/Time: (\d+\.\d+)/);
if (parts) {
const time = Number(parts[1]);
if (entries[entry]) {
entries[entry].count++;
entries[entry].value += time;
} else {
entries[entry] = {
count: 1,
value: time
};
}
}
}
};
const run = async () => {
const files = await getFiles(process.argv[2]);
for (let file of files) {
await processFile(`${process.argv[2]}/${file}`);
}
const results = {};
results['total'] = results['queries'] = 0;
for (const key in entries) {
const entry = entries[key];
// compute average for numeric keys, otherwise use total value
const result = Number.isNaN(Number(key)) ? entry.value : entry.value / entry.count;
results[key] = result;
results['total'] += result;
if (!Number.isNaN(Number(key))) {
results['queries'] += result;
}
}
console.log(JSON.stringify(results));
};
run();