Skip to content

Instantly share code, notes, and snippets.

@leontastic
Last active December 18, 2017 00:53
Show Gist options
  • Save leontastic/855b13c7ce9d339115d66362e085f866 to your computer and use it in GitHub Desktop.
Save leontastic/855b13c7ce9d339115d66362e085f866 to your computer and use it in GitHub Desktop.
Memory leak profiler using `memwatch-next` and `pino`

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')
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment