2019-04-12 17:19:46 +00:00
|
|
|
import chalk from 'chalk'
|
|
|
|
import consola from 'consola'
|
|
|
|
import prettyBytes from 'pretty-bytes'
|
|
|
|
|
2019-07-10 10:45:49 +00:00
|
|
|
export function getMemoryUsage () {
|
2019-04-12 17:19:46 +00:00
|
|
|
// https://nodejs.org/api/process.html#process_process_memoryusage
|
|
|
|
const { heapUsed, rss } = process.memoryUsage()
|
|
|
|
return { heap: heapUsed, rss }
|
|
|
|
}
|
|
|
|
|
2019-07-10 10:45:49 +00:00
|
|
|
export function getFormattedMemoryUsage () {
|
2019-04-12 17:19:46 +00:00
|
|
|
const { heap, rss } = getMemoryUsage()
|
|
|
|
return `Memory usage: ${chalk.bold(prettyBytes(heap))} (RSS: ${prettyBytes(rss)})`
|
|
|
|
}
|
|
|
|
|
2019-07-10 10:45:49 +00:00
|
|
|
export function showMemoryUsage () {
|
2019-04-12 17:19:46 +00:00
|
|
|
consola.info(getFormattedMemoryUsage())
|
|
|
|
}
|