diff --git a/bin/pm2 b/bin/pm2 index d8f8db781..45a4734a1 100755 --- a/bin/pm2 +++ b/bin/pm2 @@ -86,6 +86,7 @@ commander.version(pkg.version) .option('--attach', 'attach logging after your start/restart/stop/reload') .option('--sort ', 'sort process according to field\'s name') .option('--v8', 'enable v8 data collecting') + .option('--event-loop-inspector', 'enable event-loop-inspector dump in pmx') .usage('[cmd] app'); commander.on('--help', function() { diff --git a/lib/API/Modules/Modularizer.js b/lib/API/Modules/Modularizer.js index d08585445..6d318e7fe 100644 --- a/lib/API/Modules/Modularizer.js +++ b/lib/API/Modules/Modularizer.js @@ -63,6 +63,19 @@ Modularizer.install = function(CLI, module_name, opts, cb) { return false; } + if (module_name === 'event-loop-inspector') { + installLangModule('event-loop-inspector', function(err) { + if (err) { + Common.printError(cst.PREFIX_MSG_MOD_ERR + chalk.bold.green('event-loop-inspector installation has FAILED (checkout previous logs)')); + return cb(err); + } + + Common.printOut(cst.PREFIX_MSG + chalk.bold.green('event-loop-inspector ENABLED')); + return cb(); + }); + return false; + } + if (module_name.indexOf('typescript') > -1) { // Special dependency install return installLangModule(module_name, function(e) { diff --git a/lib/API/schema.json b/lib/API/schema.json index 1f23eb02f..97495a153 100644 --- a/lib/API/schema.json +++ b/lib/API/schema.json @@ -197,6 +197,11 @@ "boolean" ] }, + "event-loop-inspector": { + "type": [ + "boolean" + ] + }, "increment_var": { "type": "string" }, diff --git a/lib/ProcessContainer.js b/lib/ProcessContainer.js index 573400cae..16b4a55c3 100644 --- a/lib/ProcessContainer.js +++ b/lib/ProcessContainer.js @@ -30,17 +30,18 @@ delete process.env.pm2_env; (function ProcessContainer() { var fs = require('fs'); - if (process.env.pmx !== 'false') + if (process.env.pmx !== 'false') { require('pmx').init({ - transactions: process.env.km_link == 'true' && process.env.trace == 'true' || false, - http: process.env.km_link == 'true' || false, - v8: process.env.v8 === 'true' || false + transactions: (process.env.km_link === 'true' && process.env.trace === 'true') || false, + http: process.env.km_link === 'true' || false, + v8: process.env.v8 === 'true' || false, + event_loop_dump: process.env['event-loop-inspector'] === 'true' || false }); + } var stdFile = pm2_env.pm_log_path; var outFile = pm2_env.pm_out_log_path; var errFile = pm2_env.pm_err_log_path; - var pmId = pm2_env.pm_id; var pidFile = pm2_env.pm_pid_path; var script = pm2_env.pm_exec_path; var cronRestart = pm2_env.cron_restart; diff --git a/lib/ProcessContainerFork.js b/lib/ProcessContainerFork.js index 989308b08..fb0291adb 100644 --- a/lib/ProcessContainerFork.js +++ b/lib/ProcessContainerFork.js @@ -4,11 +4,12 @@ * can be found in the LICENSE file. */ // Inject custom modules -if (process.env.pmx !== "false") { +if (process.env.pmx !== 'false') { require('pmx').init({ - transactions: process.env.km_link == 'true' && process.env.trace == 'true' || false, - http: process.env.km_link == 'true' || false, - v8: process.env.v8 === 'true' || false + transactions: (process.env.km_link === 'true' && process.env.trace === 'true') || false, + http: process.env.km_link === 'true' || false, + v8: process.env.v8 === 'true' || false, + event_loop_dump: process.env['event-loop-inspector'] === 'true' || false }); }