From 5868614ec16a2a6faaad48413d5e7d1d8961a15c Mon Sep 17 00:00:00 2001 From: Kyle Farnung Date: Thu, 1 Jun 2017 10:23:06 -0700 Subject: [PATCH] lib,src: enable TTD record with env variable * Added support for the `DO_TTD_RECORD` environment variable to start recording * Added code to write the environment variable if `--record` is passed to the node command line for child processes to consume * Added the pid to the trace filename to prevent collisions Fixes #273 PR-URL: https://github.com/nodejs/node-chakracore/pull/285 Reviewed-By: Hitesh Kanwathirtha --- lib/trace_mgr.js | 3 +++ src/node.cc | 14 ++++++++++++++ 2 files changed, 17 insertions(+) diff --git a/lib/trace_mgr.js b/lib/trace_mgr.js index 7572e77f3cd..047ccd88d82 100644 --- a/lib/trace_mgr.js +++ b/lib/trace_mgr.js @@ -157,6 +157,9 @@ function createTraceLogTarget(tracename) { var traceRootDir = emitOptions.localTraceDirectory || path.dirname(process.mainModule.filename); + // Add the PID to the trace name + tracename = `${tracename}_pid${process.pid}`; + var resolvedTracePath = path.resolve(traceRootDir, '_diagnosticTraces', tracename); diff --git a/src/node.cc b/src/node.cc index 9921ba921be..cae0e695c8c 100644 --- a/src/node.cc +++ b/src/node.cc @@ -4981,6 +4981,15 @@ int Start(int argc, char** argv) { #if ENABLE_TTD_NODE bool chk_debug_enabled = debug_options.inspector_enabled(); + std::string envDoRecordVar; + bool envDoRecord = SafeGetenv("DO_TTD_RECORD", &envDoRecordVar) && + envDoRecordVar[0] == '1'; + + if (!s_doTTRecord && !s_doTTReplay) { + // Apply the value from the environment variable + s_doTTRecord = envDoRecord; + } + TTDFlagWarning_Cond(!s_doTTRecord || !s_doTTReplay, "Cannot enable record & replay at same time.\n"); @@ -5010,6 +5019,11 @@ int Start(int argc, char** argv) { TTDFlagWarning_Cond(s_ttoptReplayUri != nullptr, "Must set replay source info when replaying.\n"); } + + if (s_doTTRecord) { + // Apply the environment variable to be inherited by child processes. + putenv("DO_TTD_RECORD=1"); + } #endif