process#resourceUsage TypeScript Examples

The following examples show how to use process#resourceUsage. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: resourceLogger.ts    From hoprnet with GNU General Public License v3.0 6 votes vote down vote up
function createResourceLog(log: LogType) {
  const resourcesUsed = resourceUsage()
  // reported as KiloBytes
  const maxUsedMemoryMB = resourcesUsed.maxRSS / 1024
  // reported in microseconds
  const usedCpuSec = resourcesUsed.userCPUTime / 1000 / 1000
  // reported as Bytes
  const usedMemoryMB = memoryUsage().rss / 1024 / 1024

  log(
    `Process stats: mem ${usedMemoryMB.toPrecision(1)} MB (max: ${maxUsedMemoryMB.toPrecision(1)} MB) ` +
      `cputime: ${usedCpuSec.toPrecision(1)} sec`
  )
}