Advertisement
Anatolyukropov

Memory Usage Control

May 3rd, 2023
152
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.56 KB | None | 0 0
  1. const memory: any[] = [];
  2. const showMemoryUsage = () => {
  3. // eslint-disable-next-line no-console
  4. console.clear();
  5. const bytesToMb = bytes => Math.round(bytes / 1000) / 1000;
  6. const usage = process.memoryUsage();
  7. const row = {
  8. rss: bytesToMb(usage.rss),
  9. heapTotal: bytesToMb(usage.heapTotal),
  10. heapUsed: bytesToMb(usage.heapUsed),
  11. external: bytesToMb(usage.external),
  12. stack: bytesToMb(usage.rss - usage.heapTotal - usage.external),
  13. };
  14.  
  15. memory.push(row);
  16. // eslint-disable-next-line no-console
  17. console.table(memory);
  18. };
Tags: node
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement