@sematext/gc-stats
Version:
Exposes node v8 garbage collection stats
27 lines (21 loc) • 649 B
JavaScript
;
var gcEmitter,
binary = require('@mapbox/node-pre-gyp'),
path = require('path'),
binding_path = binary.find(path.resolve(path.join(__dirname,'./package.json'))),
gcstats = require(binding_path),
EventEmitter = require('events').EventEmitter;
function gcStats() {
if (this instanceof gcStats){
throw Error('gc-stats no longer exports a constructor. Call without the `new` keyword');
}
if(!gcEmitter) {
gcEmitter = new EventEmitter();
gcstats.afterGC(function(stats) {
gcEmitter.emit('data', stats);
gcEmitter.emit('stats', stats);
});
}
return gcEmitter;
}
module.exports = gcStats;