-
Notifications
You must be signed in to change notification settings - Fork 3
/
utils.js
74 lines (63 loc) · 2.12 KB
/
utils.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
import { readdirSync, readFileSync, writeFileSync, unlinkSync } from 'fs';
import path from 'path';
// Utils
export function mergeLogFiles(dirPath, outputFileName) {
let files = readdirSync(dirPath);
let mergedContent = '';
// Filter and sort files
files = files
.filter(file => file.startsWith('eth_'))
.sort((a, b) => {
const numberA = parseInt(a.split('.')[1]);
const numberB = parseInt(b.split('.')[1]);
return numberA - numberB;
});
files.forEach((file) => {
const filePath = path.join(dirPath, file);
const content = readFileSync(filePath, 'utf8');
mergedContent += content + '\n';
unlinkSync(filePath); // delete the file
});
writeFileSync(path.join(dirPath, outputFileName), mergedContent);
}
export function mergeMetaFiles(dirPath, outputFileName, logFileName) {
let files = readdirSync(dirPath);
let mergedContent = '';
// Filter and sort files
files = files
.filter(file => file.startsWith('metadata'))
.sort((a, b) => {
const numberA = parseInt(a.split('.')[1]);
const numberB = parseInt(b.split('.')[1]);
return numberA - numberB;
});
files.forEach((file) => {
const filePath = path.join(dirPath, file);
const content = readFileSync(filePath, 'utf8');
mergedContent += content + '\n';
unlinkSync(filePath); // delete the file
});
// Read the content of the log file
const logFilePath = path.join(dirPath, logFileName);
const logContent = readFileSync(logFilePath, 'utf8');
// Merge the metadata content with the log content
mergedContent += logContent;
// Write the merged content to the output file
writeFileSync(path.join(dirPath, outputFileName), mergedContent);
// Delete the benchmark_results file after merge
unlinkSync(logFilePath);
}
export function countdown(s) {
const d = Math.floor(s / (3600 * 24));
s -= d * 3600 * 24;
const h = Math.floor(s / 3600);
s -= h * 3600;
const m = Math.floor(s / 60);
s -= m * 60;
const tmp = [];
d && tmp.push(d + 'd');
(d || h) && tmp.push(h + 'h');
(d || h || m) && tmp.push(m + 'm');
tmp.push(parseInt(s) + 's');
return tmp.join(' ');
}