description and source-codefunction dump() {
console.log('[WTF Node?] open handles:');
// sort the active handles into different types for logging
var sockets = [ ], fds = [ ], servers = [ ], _timers = [ ], processes = [ ], clusterWorkers = [ ], other = [ ];
process._getActiveHandles().forEach(function (h) {
if (h instanceof Socket) {
// stdin, stdout, etc. are now instances of socket and get listed in open handles
// todo: a more specific/better way to identify them than the 'fd' property
if ((h.fd != null)) { fds.push(h); }
else { sockets.push(h); }
}
else if (h instanceof Server) { servers.push(h); }
else if (h instanceof dgramSocket) { servers.push(h); }
else if (h instanceof Timer) { _timers.push(h); }
else if (h instanceof ChildProcess) { processes.push(h); }
else if (h.hasOwnProperty('__worker')) { clusterWorkers.push(h); }
// catchall
else { other.push(h); }
});
if (fds.length) {
console.log('- File descriptors: (note: stdio always exists)');
fds.forEach(function (s) {
var str = ' - fd '+s.fd;
if (s.isTTY) { str += ' (tty)'; }
if (s._isStdio) { str += ' (stdio)'; }
if (s.destroyed) { str += ' (destroyed)'; }
console.log(str);
// this event will source the origin of a readline instance, kind of indirectly
var keypressListeners = s.listeners('keypress');
if (keypressListeners && keypressListeners.length) {
console.log(' - Listeners:');
keypressListeners.forEach(function (fn) {
var callSite = getCallsite(fn);
console.log(' - %s: %s @ %s:%d', 'keypress', fn.name || '(anonymous)', callSite.file, callSite.line);
});
}
});
}
// remove cluster workers from child process list
clusterWorkers.forEach(function (p) {
if (!p.__worker || !p.__worker.process) { return; }
var cw = p.__worker.process,
idx = processes.indexOf(cw);
if (idx > -1) { processes.splice(idx, 1); }
});
if (processes.length) {
console.log('- Child processes');
processes.forEach(function (cp) {
var fds = [ ];
console.log(' - PID %s', cp.pid);
if (!DONT_INSTRUMENT['ChildProcess']) {
var callSite = getCallsite(cp);
console.log(' - Entry point: %s:%d', callSite.file, callSite.line);
}
if (cp.stdio && cp.stdio.length) {
cp.stdio.forEach(function (s) {
if (s && s._handle && (s._handle.fd != null)) { fds.push(s._handle.fd); }
var idx = sockets.indexOf(s);
if (idx > -1) {
sockets.splice(idx, 1);
}
});
if (fds && fds.length) {
console.log(' - STDIO file descriptors:', fds.join(', '));
}
}
});
}
if (clusterWorkers.length) {
console.log('- Cluster workers');
clusterWorkers.forEach(function (cw) {
var fds = [ ], cp = cw.__worker.process;
console.log(' - PID %s', cp.pid);
var callSite = getCallsite(cw);
console.log(' - Entry point: %s:%d', callSite.file, callSite.line);
});
}
if (sockets.length) {
console.log('- Sockets:');
sockets.forEach(function (s) {
if (s.destroyed) {
console.log(' - (?:?) -> %s:? (destroyed)', s._host);
} else if (s.localAddress) {
console.log(' - %s:%s -> %s:%s', s.localAddress, s.localPort, s.remoteAddress, s.remotePort);
} else if (s._handle && (s._handle.fd != null)) {
console.log(' - fd %s', s._handle.fd);
} else {
console.log(' - unknown socket');
}
var connectListeners = s.list ...