Skip to content
This repository has been archived by the owner on Oct 15, 2020. It is now read-only.

Commit

Permalink
lib,src: enable TTD record with env variable
Browse files Browse the repository at this point in the history
* 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: #285
Reviewed-By: Hitesh Kanwathirtha <[email protected]>
  • Loading branch information
kfarnung committed Jun 13, 2017
1 parent b0681ba commit 5868614
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
3 changes: 3 additions & 0 deletions lib/trace_mgr.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
14 changes: 14 additions & 0 deletions src/node.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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");

Expand Down Expand Up @@ -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


Expand Down

0 comments on commit 5868614

Please sign in to comment.