-
-
Save elhoyos/9b55e9263f6d3e40e84d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"dependencies": { | |
"heapdump": "^0.2.10" | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var net = require("net") | |
, heapdump = require("heapdump") | |
, server; | |
function onConnection (client) { | |
client.on("data", function (data) { | |
client.end(); | |
}); | |
}; | |
function onListen () { | |
var socket = net.connect({host: "127.0.0.1", port: 3000}); | |
socket.bigBuffer = new Buffer(50000000); //50MB Buffer | |
heapdump.writeSnapshot(__dirname + "/initial.heapsnapshot", function writeInitialSnapshot () { | |
console.log("Wrote initial heap snapshot"); | |
socket.write("data"); | |
}); | |
socket.on("close", writeEndSnapshot); | |
}; | |
function writeEndSnapshot (had_error) { | |
if (had_error) console.log("Got a transmission error"); | |
server.close(function () { | |
process.nextTick(function onNextTick () { | |
console.log("Running GC"); | |
gc(); | |
heapdump.writeSnapshot(__dirname + "/final.heapsnapshot", function writeFinalSnapshot () { | |
console.log("Wrote final heap snapshot"); | |
}); | |
}); | |
}); | |
}; | |
server = net.createServer(onConnection).listen(3000, onListen); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment