Skip to content

Instantly share code, notes, and snippets.

@poying
Created May 3, 2017 04:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save poying/b9bace072ea030e941ddaca55797f721 to your computer and use it in GitHub Desktop.
Save poying/b9bace072ea030e941ddaca55797f721 to your computer and use it in GitHub Desktop.
const path = require('path');
const memwatch = require('memwatch-next');
const heapdump = require('heapdump');
const logger = require('./logger');
const settings = require('./config/settings');
memwatch.on('leak', info => {
const filepath = path.resolve(settings.HEAP_SNAPSHOT_DIR, Date.now() + '.heapsnapshot');
logger.fatal({ leak: info }, 'Memory leak');
heapdump.writeSnapshot(filepath, err => {
if (err) {
logger.error({ err }, 'Failed to take heap snapshot');
}
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment