For instance, when I run the C++ executable, I call this function 20-30 times consecutively. Everything works fine, but I’m having trouble determining the memory usage of this command. The process.memoryUsage()
function returns an inaccurate value, and since the process ID disappears once it finishes, I’m unable to track it by PID.
What would be the best way to accurately measure the memory usage?
return new Promise(async (resolve, reject) => {
try {
let init_memory = process.memoryUsage();
console.log(process.memoryUsage());
exec(`./main < ${msg.test_path}/input_${num}.txt > ./output.txt`, { timeout: msg.time_limit, maxBuffer: 64 * 1024 * 1024, cwd: msg.code_path }, async (error, stdout, stderr) => {
let end_memory = process.memoryUsage();
console.log(error, process.memoryUsage(), (init_memory.external - end_memory.external) / 1024 / 1024);
if (error || !fnCheck(`${msg.code_path}/output.txt`, `${msg.test_path}/output_${num}.txt`)) {
return reject({ error, stdout, stderr });
}
return resolve({ error, stdout, stderr });
});
} catch (error) {
reject(false);
}
});
};
Please ask if something is unclear, Thanks!