-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
util.mjs
23 lines (22 loc) · 790 Bytes
/
util.mjs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import chalk from 'chalk'
import prettyBytes from 'pretty-bytes'
import { table } from 'table'
export function displayMemoryUsageFromNode(initialMemoryUsage) {
const finalMemoryUsage = process.memoryUsage()
const titles = Object.keys(initialMemoryUsage).map((k) => chalk.whiteBright(k))
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) {
diffColumn.push(chalk.red(prettyDiff))
} else if (diff < 0) {
diffColumn.push(chalk.green(prettyDiff))
} else {
diffColumn.push(chalk.grey(prettyDiff))
}
}
tableData.push(diffColumn)
console.info(table(tableData))
}