0.1.1 • Published 7 years ago
memory-leak-heapdump v0.1.1
memory-leak-heapdump
memory-leak-heapdump
is based on memwatch-next
and heapdump
. It can dump heapsnapshot if memory leak.
Install
npm install memory-leak-heapdump --save
Usage
snapshot
- js
var heapdump = require('memory-leak-heapdump').Heapdump;
heapdump.snapshot('/tmp/test.heapsnapshot')
.then(function (filepath) {
console.log('snapshot file path: ', filepath);
})
.catch(function (err) {
console.error(err);
});
- ts
import { Heapdump } from "memory-leak-heapdump";
Heapdump.snapshot("/tmp/test.heapsnapshot")
.then((filepath) => {
console.log("snapshot file path: ", filepath);
})
.catch((err) => {
console.error(err);
});
Watch leak and snapshot
- ts
import { Watcher, WatcherConfig } from "memory-leak-heapdump";
const watcherConfig = new WatcherConfig();
watcherConfig.appName = "targetAppName";
watcherConfig.snapshotDir = "/tmp";
watcherConfig.snapshotMinInterval = 18000; // 3 min interval(avoid cpu usage issue).
const handleSnapshot = (err: Error, filepath: string): void => {
if (util.isNullOrUndefined(err)) {
console.info("snapshot file path: ", filepath);
} else {
console.error("handleSnapshot: ", err);
}
};
watcher.snapshotIfLeak(handleSnapshot);