Skip to content

Instantly share code, notes, and snippets.

@rafaelmaeuer
Created December 14, 2022 09:38
Show Gist options
  • Save rafaelmaeuer/956bc08a87f0fed62e5bf4ca4b7c307c to your computer and use it in GitHub Desktop.
Save rafaelmaeuer/956bc08a87f0fed62e5bf4ca4b7c307c to your computer and use it in GitHub Desktop.
const formatMemoryUsage = (data) => `${Math.round(data / 1024 / 1024 * 100) / 100} MB`;
const memoryData = process.memoryUsage();
const memoryUsage = {
rss: `${formatMemoryUsage(memoryData.rss)} -> Resident Set Size - total memory allocated for the process execution`,
heapTotal: `${formatMemoryUsage(memoryData.heapTotal)} -> total size of the allocated heap`,
heapUsed: `${formatMemoryUsage(memoryData.heapUsed)} -> actual memory used during the execution`,
external: `${formatMemoryUsage(memoryData.external)} -> V8 external memory`,
};
console.log(memoryUsage);
/*
{
"rss": "177.54 MB -> Resident Set Size - total memory allocated for the process execution",
"heapTotal": "102.3 MB -> total size of the allocated heap",
"heapUsed": "94.3 MB -> actual memory used during the execution",
"external": "3.03 MB -> V8 external memory"
}
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment