Skip to content

Commit

Permalink
add setGC
Browse files Browse the repository at this point in the history
  • Loading branch information
cenfun committed Oct 6, 2024
1 parent d1e66e9 commit e562723
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 3 deletions.
4 changes: 4 additions & 0 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,10 @@ class CoverageReport {
return results;
}

setGC(value) {
Util.setGC(value);
}

// add coverage from dir
async addFromDir(dir) {
const time_start = Date.now();
Expand Down
24 changes: 21 additions & 3 deletions lib/utils/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -869,18 +869,36 @@ const Util = {
console.log(`[MCR] ${message} before ${lengthBefore} => after ${lengthAfter}`);
},

setGC: (value) => {
if (!Util.isNum(value)) {
value = 1024;
}
Util.gcValue = value;
},

getMemory: () => {
const { heapUsed } = process.memoryUsage();
const memory = parseFloat((heapUsed / 1024 ** 2).toFixed(1));
return memory;
},

// time is debug level, fix the log info, for checking snapshot
logTime: (message, time_start) => {

// memory gc
let memory = Util.getMemory();
if (Util.gcValue && Util.gcValue < memory) {
Util.forceGC();
}

if (Util.loggingLevel < Util.loggingLevels.debug && !process.env.MCR_LOG_TIME) {
return;
}
const duration = Date.now() - time_start;
const durationH = Util.TF(duration);
const ls = [`[MCR] ${message}`];

// memory
const { heapUsed } = process.memoryUsage();
const memory = parseFloat((heapUsed / 1024 ** 2).toFixed(1));
memory = Util.getMemory();
ls.push(` (memory: ${memory}MB)`);

// time
Expand Down

0 comments on commit e562723

Please sign in to comment.