2022-04-07 00:00:21 +09:00
|
|
|
import { whiteBright, red, green, gray } from 'colorette'
|
|
|
|
import prettyBytes from 'pretty-bytes'
|
|
|
|
import { table } from 'table'
|
2021-05-28 19:50:16 +09:00
|
|
|
|
2022-04-07 00:00:21 +09:00
|
|
|
export function displayMemoryUsageFromNode(initialMemoryUsage) {
|
2021-05-28 19:50:16 +09:00
|
|
|
const finalMemoryUsage = process.memoryUsage()
|
2022-01-24 12:33:51 +09:00
|
|
|
const titles = Object.keys(initialMemoryUsage).map((k) => whiteBright(k))
|
2021-05-28 19:50:16 +09:00
|
|
|
const tableData = [titles]
|
|
|
|
const diffColumn = []
|
|
|
|
for (const [key, value] of Object.entries(initialMemoryUsage)) {
|
|
|
|
const diff = finalMemoryUsage[key] - value
|
|
|
|
const prettyDiff = prettyBytes(diff, { signed: true })
|
|
|
|
if (diff > 0) {
|
2022-01-24 12:33:51 +09:00
|
|
|
diffColumn.push(red(prettyDiff))
|
2021-05-28 19:50:16 +09:00
|
|
|
} else if (diff < 0) {
|
2022-01-24 12:33:51 +09:00
|
|
|
diffColumn.push(green(prettyDiff))
|
2021-05-28 19:50:16 +09:00
|
|
|
} else {
|
2022-01-24 12:33:51 +09:00
|
|
|
diffColumn.push(gray(prettyDiff))
|
2021-05-28 19:50:16 +09:00
|
|
|
}
|
|
|
|
}
|
|
|
|
tableData.push(diffColumn)
|
|
|
|
console.info(table(tableData))
|
|
|
|
}
|