Skip to content

Commit

Permalink
#250 - Add another way to measure used memory
Browse files Browse the repository at this point in the history
  • Loading branch information
Elanis committed Apr 25, 2023
1 parent afb0901 commit f23fef2
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion runner/runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,11 @@ export function killAll(pid, signal='SIGTERM'){
async function getMemoryUsageHistoryOfProcess(processPath, processExe, timeout=DEFAULT_TIMEOUT) {
return new Promise((resolve, reject) => {
let memUsageHistory = [];
let sysMemUsageHistory = [];
let startTime = '?';
let done = false;
let time = 0;
let originalFreeMemory = os.freemem();

// Spawn process
const startTimestamp = performance.now();
Expand All @@ -133,6 +135,7 @@ async function getMemoryUsageHistoryOfProcess(processPath, processExe, timeout=D
if(time < 0) { // Unlock cargo/rust
time = 0;
memUsageHistory = [];
sysMemUsageHistory = [];
}
}
});
Expand Down Expand Up @@ -165,14 +168,15 @@ async function getMemoryUsageHistoryOfProcess(processPath, processExe, timeout=D
trimmedCleanData.includes('Building application for development...') ||
trimmedCleanData.includes('Compiling application: ')
) {
console.log(`[WARNING] Cargo/Rust action detected. Delaying timer ...`);
console.log(`[WARNING] Cargo/Rust/Wails/Go action detected. Delaying timer ...`);
time = -1;

for(let i = 0; i <= resetTimeoutId; i++) { clearTimeout(i); }
resetTimeoutId = setTimeout(() => {
if(time < 0) { // Unlock cargo/rust
time = 0;
memUsageHistory = [];
sysMemUsageHistory = [];
}
}, 120*1000); // Unlock if going for more than 2 minutes
}
Expand All @@ -185,6 +189,7 @@ async function getMemoryUsageHistoryOfProcess(processPath, processExe, timeout=D
if(time < 0) { // Unlock cargo/rust/wails
time = 0;
memUsageHistory = [];
sysMemUsageHistory = [];
}
}
});
Expand Down Expand Up @@ -212,6 +217,7 @@ async function getMemoryUsageHistoryOfProcess(processPath, processExe, timeout=D
}
}
});
sysMemUsageHistory.push(os.freemem() - originalFreeMemory);
} catch(e) {

}
Expand All @@ -226,6 +232,7 @@ async function getMemoryUsageHistoryOfProcess(processPath, processExe, timeout=D
if(time++ === timeout || childProcess.exitCode !== null || done) {
resolve({
memoryUsage: memUsageHistory,
systemMeasuredMemory: sysMemUsageHistory,
startTime
});
clearInterval(interval);
Expand Down

0 comments on commit f23fef2

Please sign in to comment.