This repository was archived by the owner on Jun 18, 2021. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 36
Add command line to nodereport. #34
Closed
Closed
Changes from 1 commit
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
d5673b8
This patch adds the command line used to start the process to noderep…
hhellyer 412efb4
Correct white space. Shouldn't indent when starting a #ifdef.
hhellyer 1294c2a
Fix the spelling of separator
hhellyer dd20187
Add command line support on Windows
rnchamberlain 5872102
Fix code review and formatting nits
rnchamberlain File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -29,6 +29,8 @@ | |
| #include <dlfcn.h> | ||
| #ifndef _AIX | ||
| #include <execinfo.h> | ||
| #else | ||
| #include <sys/procfs.h> | ||
| #endif | ||
| #include <sys/utsname.h> | ||
| #endif | ||
|
|
@@ -41,6 +43,11 @@ | |
| #define UNKNOWN_NODEVERSION_STRING "Unable to determine Node.js version\n" | ||
| #endif | ||
|
|
||
| #ifdef __APPLE__ | ||
| // Include _NSGetArgv and _NSGetArgc for command line arguments. | ||
| #include <crt_externs.h> | ||
| #endif | ||
|
|
||
| #ifndef _WIN32 | ||
| extern char** environ; | ||
| #endif | ||
|
|
@@ -58,6 +65,7 @@ using v8::String; | |
| using v8::V8; | ||
|
|
||
| // Internal/static function declarations | ||
| static void PrintCommandLine(FILE* fp); | ||
| static void PrintVersionInformation(FILE* fp, Isolate* isolate); | ||
| static void PrintJavaScriptStack(FILE* fp, Isolate* isolate, DumpEvent event, const char* location); | ||
| static void PrintStackFromStackTrace(FILE* fp, Isolate* isolate, DumpEvent event); | ||
|
|
@@ -77,6 +85,7 @@ static bool report_active = false; // recursion protection | |
| static char report_filename[NR_MAXNAME + 1] = ""; | ||
| static char report_directory[NR_MAXPATH + 1] = ""; // defaults to current working directory | ||
| static std::string version_string = UNKNOWN_NODEVERSION_STRING; | ||
| static std::string commandline_string = ""; | ||
| #ifdef _WIN32 | ||
| static SYSTEMTIME loadtime_tm_struct; // module load time | ||
| #else // UNIX, OSX | ||
|
|
@@ -299,6 +308,65 @@ void SetLoadTime() { | |
| localtime_r(&time_val.tv_sec, &loadtime_tm_struct); | ||
| #endif | ||
| } | ||
|
|
||
| /******************************************************************************* | ||
| * Function to save the process command line | ||
| *******************************************************************************/ | ||
| void SetCommandLine() { | ||
| #ifdef __linux__ | ||
| // Read the command line from /proc/self/cmdline | ||
| char buf[64]; | ||
| FILE* cmdline_fd = fopen("/proc/self/cmdline", "r"); | ||
| if (cmdline_fd == nullptr) { | ||
| return; | ||
| } | ||
| commandline_string = ""; | ||
| int bytesread = fread(buf, 1, sizeof(buf), cmdline_fd); | ||
| while (bytesread > 0) { | ||
| for (int i = 0; i < bytesread; i++) { | ||
| // Arguments are null separated. | ||
| if (buf[i] == '\0') { | ||
| commandline_string += " "; | ||
| } else { | ||
| commandline_string += buf[i]; | ||
| } | ||
| } | ||
| bytesread = fread(buf, 1, sizeof(buf), cmdline_fd); | ||
| } | ||
| fclose(cmdline_fd); | ||
| #elif __APPLE__ | ||
| char **argv = *_NSGetArgv(); | ||
| int argc = *_NSGetArgc(); | ||
|
|
||
| commandline_string = ""; | ||
| std::string seperator = ""; | ||
| for (int i = 0; i < argc; i++) { | ||
| commandline_string += seperator + argv[i]; | ||
| seperator = " "; | ||
| } | ||
| #elif _AIX | ||
| // Read the command line from /proc/self/cmdline | ||
| char procbuf[64]; | ||
| snprintf(procbuf, sizeof(procbuf), "/proc/%d/psinfo", getpid()); | ||
| FILE* psinfo_fd = fopen(procbuf, "r"); | ||
| if (psinfo_fd == nullptr) { | ||
| return; | ||
| } | ||
| psinfo_t info; | ||
| int bytesread = fread(&info, 1, sizeof(psinfo_t), psinfo_fd); | ||
| fclose(psinfo_fd); | ||
| if (bytesread == sizeof(psinfo_t)) { | ||
| commandline_string = ""; | ||
| std::string seperator = ""; | ||
|
||
| char **argv = *((char ***) info.pr_argv); | ||
| for (uint32_t i = 0; i < info.pr_argc; i++) { | ||
| commandline_string += seperator + argv[i]; | ||
| seperator = " "; | ||
| } | ||
| } | ||
| #endif // _AIX | ||
| } | ||
|
|
||
| /******************************************************************************* | ||
| * Main API function to write a NodeReport to file. | ||
| * | ||
|
|
@@ -311,7 +379,7 @@ void SetLoadTime() { | |
| ******************************************************************************/ | ||
| void TriggerNodeReport(Isolate* isolate, DumpEvent event, const char* message, const char* location, char* name) { | ||
| // Recursion check for NodeReport in progress, bail out | ||
| if (report_active) return; | ||
| if (report_active) return; | ||
| report_active = true; | ||
|
|
||
| // Obtain the current time and the pid (platform dependent) | ||
|
|
@@ -414,6 +482,10 @@ void TriggerNodeReport(Isolate* isolate, DumpEvent event, const char* message, c | |
| fprintf(fp, "Process ID: %d\n", pid); | ||
| fflush(fp); | ||
|
|
||
| // Print out the command line. | ||
| PrintCommandLine(fp); | ||
| fflush(fp); | ||
|
|
||
| // Print Node.js and OS version information | ||
| PrintVersionInformation(fp, isolate); | ||
| fflush(fp); | ||
|
|
@@ -463,6 +535,16 @@ void TriggerNodeReport(Isolate* isolate, DumpEvent event, const char* message, c | |
| report_active = false; | ||
| } | ||
|
|
||
| /******************************************************************************* | ||
| * Function to print process command line. | ||
| * | ||
| ******************************************************************************/ | ||
| static void PrintCommandLine(FILE* fp) { | ||
| if (commandline_string != "") { | ||
| fprintf(fp, "Command line arguments: %s\n", commandline_string.c_str()); | ||
| } | ||
| } | ||
|
|
||
| /******************************************************************************* | ||
| * Function to print Node.js version, OS version and machine information | ||
| * | ||
|
|
@@ -688,7 +770,7 @@ void PrintNativeStack(FILE* fp) { | |
| SymInitialize(hProcess, nullptr, TRUE); | ||
|
|
||
| WORD numberOfFrames = CaptureStackBackTrace(2, 64, frames, nullptr); | ||
|
|
||
| // Walk the frames printing symbolic information if available | ||
| for (int i = 0; i < numberOfFrames; i++) { | ||
| DWORD64 dwOffset64 = 0; | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The indentation for this
#elifblock is different from the rest of this function, please can you make it consistent?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The rest of the function was wrong and didn't match the file. I'd indented when starting #ifdef sections. I've adjusted the rest of the function to be correct.