Setup:
npm i memwatch-next pino
Usage:
require('./memory-leak-profiler')
const Memwatch = require('memwatch-next') | |
const pino = require('pino') | |
let hd | |
Memwatch.on('leak', info => { | |
pino.warn(info, 'Memwatch::leak') | |
if (!hd) hd = new Memwatch.HeapDiff() | |
else { | |
const diff = hd.end() | |
pino.warn(diff, 'Memwatch::heapdiff') | |
hd = null | |
} | |
}) | |
Memwatch.on('stats', (stats) => { | |
pino.warn(stats, 'Memwatch::stats') | |
}) |