Created
June 6, 2023 07:43
-
-
Save crazyoptimist/86f45fb8535d9331dcf93096ec02a5aa to your computer and use it in GitHub Desktop.
Monitor Memory Usage in NodeJS
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function formatMemoryUsage(data: number) { | |
return `${Math.round((data / 1024 / 1024) * 100) / 100} MB`; | |
} | |
function getCurrentMemoryUsage(): Object { | |
const memoryData = process.memoryUsage(); | |
return { | |
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`, | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment