-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlogging.cjs
56 lines (51 loc) · 1.92 KB
/
logging.cjs
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
const eventTimes = {};
function getTimeSince(event) {
return ((performance.now() - eventTimes[event]) / 1000).toFixed(4) + "s";
}
function percentComplete(...args) {
return (((args[0] + (args[2] / args[3])) / args[1]) * 100).toFixed(2) + "%"
}
let throttler = 0;
const throttlerThreshold = 1000;
async function eventListener(event, ...args) {
switch (event) {
case "tuning-written":
// fallthrough
case "simdata-written":
throttler++;
throttler %= throttlerThreshold;
if ((throttler % throttlerThreshold === 0) || args[2] === args[3])
process.stdout.write(`\r\x1b[K | Progress: ${percentComplete(...args)}`);
return;
case "index-stbl-start":
eventTimes[event] = performance.now();
return console.log("Indexing STBLs...");
case "index-stbl-end":
return console.log("STBLs indexed in ", getTimeSince("index-stbl-start"));
case "index-sim-start":
eventTimes[event] = performance.now();
return console.log("Indexing simulation files...");
case "index-sim-end":
return console.log("Simulation files indexed in ", getTimeSince("index-sim-start"));
case "mapping-start":
eventTimes[event] = performance.now();
return console.log("Mapping comments...");
case "mapping-end":
return console.log("Comments mapped in ", getTimeSince("mapping-start"));
case "extract-tuning-start":
throttler = 0;
eventTimes[event] = performance.now();
return console.log("Extracting tuning...");
case "extract-tuning-end":
return console.log("\nTuning extracted in ", getTimeSince("extract-tuning-start"));
case "extract-simdata-start":
throttler = 0;
eventTimes[event] = performance.now();
return console.log("Extracting SimData...");
case "extract-simdata-end":
return console.log("\nSimData extracted in ", getTimeSince("extract-simdata-start"));
}
}
module.exports = {
eventListener
};