Skip to content

Instantly share code, notes, and snippets.

@elhoyos
Forked from danypype/package.json
Last active August 29, 2015 14:07
Show Gist options
  • Save elhoyos/9b55e9263f6d3e40e84d to your computer and use it in GitHub Desktop.
Save elhoyos/9b55e9263f6d3e40e84d to your computer and use it in GitHub Desktop.
{
"dependencies": {
"heapdump": "^0.2.10"
}
}
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