From 6b713b52537f2509e79fcb4d4f9433db1aee2dd9 Mon Sep 17 00:00:00 2001 From: Ben Noordhuis Date: Fri, 18 Jan 2013 12:44:10 +0100 Subject: [PATCH] cluster: make --prof work for workers Profiling in clustered environments doesn't work out of the box. By default, V8 writes the profile data of all processes to a single v8.log. Running that log file through a tick processor produces bogus numbers because many events won't match up with the recorded memory mappings and you end up with graphs where 80+% of ticks is unaccounted for. Fixing the tick processor to deal with multi-process output is not very useful because the processes may be running wildly disparate workloads. That's why we fix up the command line arguments to include a "--logfile=v8-%p.log" argument (where %p is expanded to the PID) unless it already contains a --logfile argument. Fixes #4617. --- lib/cluster.js | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/lib/cluster.js b/lib/cluster.js index 4bece2d..b2e7625 100644 --- a/lib/cluster.js +++ b/lib/cluster.js @@ -105,10 +105,31 @@ cluster.setupMaster = function(options) { // Get filename and arguments options = options || {}; + // By default, V8 writes the profile data of all processes to a single + // v8.log. + // + // Running that log file through a tick processor produces bogus numbers + // because many events won't match up with the recorded memory mappings + // and you end up with graphs where 80+% of ticks is unaccounted for. + // + // Fixing the tick processor to deal with multi-process output is not very + // useful because the processes may be running wildly disparate workloads. + // + // That's why we fix up the command line arguments to include + // a "--logfile=v8-%p.log" argument (where %p is expanded to the PID) + // unless it already contains a --logfile argument. + var execArgv = options.execArgv || process.execArgv; + if (execArgv.some(function(s) { return /^--prof/.test(s); }) && + !execArgv.some(function(s) { return /^--logfile=/.test(s); })) + { + execArgv = execArgv.slice(); + execArgv.push('--logfile=v8-%p.log'); + } + // Set settings object settings = cluster.settings = { exec: options.exec || process.argv[1], - execArgv: options.execArgv || process.execArgv, + execArgv: execArgv, args: options.args || process.argv.slice(2), silent: options.silent || false }; -- 2.7.4