Skip to content

Instantly share code, notes, and snippets.

@ncarbon
Forked from doron2402/memwatch_detect.js
Created June 7, 2018 04:43
Show Gist options
  • Select an option

  • Save ncarbon/d71ed1e06373eeddc01623e94e30a295 to your computer and use it in GitHub Desktop.

Select an option

Save ncarbon/d71ed1e06373eeddc01623e94e30a295 to your computer and use it in GitHub Desktop.

Revisions

  1. @doron2402 doron2402 created this gist May 4, 2017.
    34 changes: 34 additions & 0 deletions memwatch_detect.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,34 @@
    'use strict';
    const Memwatch = require('memwatch-next');
    const Util = require('util');

    if (Config.env === 'production') {
    /**
    * Check for memory leaks
    */
    let hd = null;
    Memwatch.on('leak', (info) => {
    console.log('memwatch::leak');
    console.error(info);
    if (!hd) {
    hd = new Memwatch.HeapDiff();
    }
    else {
    const diff = hd.end();
    console.error(Util.inspect(diff, true, null));
    trace.report('memwatch::leak', {
    HeapDiff: hd
    });
    hd = null;
    }
    });

    Memwatch.on('stats', (stats) => {
    console.log('memwatch::stats');
    console.error(Util.inspect(stats, true, null));
    trace.report('memwatch::stats', {
    Stats: stats
    });
    });
    }