Skip to content
This repository has been archived by the owner on Jun 18, 2021. It is now read-only.

Add command line to nodereport. #34

Closed
wants to merge 5 commits into from
Closed

Conversation

hhellyer
Copy link
Contributor

@hhellyer hhellyer commented Dec 16, 2016

This patch adds the command line used to start the process to nodereport.
It's based off https://github.com/rnchamberlain/nodereport/tree/clang_warning so it could be built and tested on Mac. It should merge cleanly once that has been landed.

One line is added to the NodeReport file. Sample output from a test script that generates a report:

> node --no-warnings my_application.js -a an_argument file.txt

First part of the generated NodeReport file:

================================================================================
==== NodeReport ================================================================

Event: JavaScript API, location: "TriggerReport"
Filename: NodeReport.20161216.145623.6353.001.txt
Dump event time:  2016/12/16 14:56:23
Module load time: 2016/12/16 14:56:23
Process ID: 6353
Command line arguments: node --no-warnings my_application.js -a an_argument file.txt

Node.js version: v6.5.0

@Fishrock123
Copy link
Contributor

@hhellyer could you document how this is supposed to be used? :D

@hhellyer
Copy link
Contributor Author

I've added some sample output.

@cjihrig
Copy link

cjihrig commented Dec 16, 2016

@hhellyer it looks like there are conflicts in src/node_report.cc that need to be resolved.

@richardlau
Copy link
Member

Is it possible to get the equivalent information on AIX and Windows?

@richardlau
Copy link
Member

Also needs tests.

@hhellyer
Copy link
Contributor Author

@richardlau
Not sure about AIX, it doesn't have /proc/self/cmdline so I'll need to find something else.

It looked like Windows had globals (__argv, __argc) which you could use, though I've not tested them as I don't have a windows box easily accessible. See: https://msdn.microsoft.com/en-us/library/dn727674.aspx for details, there may be a better way - I only had a quick look.

@richardlau
Copy link
Member

Windows: GetCommandLine()

AIX: getargs(). I actually used this to fix libuv/libuv#464 (although in that case we were only interested in the first argument of the command line).

Copy link
Member

@richardlau richardlau left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would like tests for this to be added and coverage extended to Windows and AIX.

@rnchamberlain
Copy link
Contributor

rnchamberlain commented Dec 19, 2016

Looks good

  1. Suggest just Command line: rather than Command line arguments:
  2. Windows and AIX support would be great - if not too much work
  3. Not sure we'll want tests for every output line in NodeReport, but as this is using some significant OS platform calls then yes maybe a test would be good.
  4. I've landed the Mac build fix, so probably best to rebase this now
  5. It would be handy if the command line could be saved (maybe at start-up as we do for load time and the version strings) because we need to know whether the user specified the --abort-on-uncaught-exception option

…ort on

Linux, Mac and AIX.
On Linux it reads /proc/self/cmdline.
On Mac is uses _NSGetArgv and _NSGetArgc.
On AIX it reads /proc/PID/psinfo.

The command line is read and stored at startup so files aren't opened
when a crash is occuring.
@hhellyer
Copy link
Contributor Author

hhellyer commented Jan 4, 2017

I've added AIX support. Note that on AIX we get the wrong command but that's because of nodejs/node#10607 and we give the same result as the ps command.

I've squashed the commits down, it looks like github shows the changes on the branch and not a diff against the merge destination which is confusing if you pull in changes from there, which I had done. At least I think that's what was happening... :-)

@gibfahn
Copy link
Member

gibfahn commented Jan 4, 2017

@hhellyer AFAIK the Files is just a diff against the merge destination, and if you want to see individual commit diffs you look at Commits. However Github does weird things sometimes.

commandline_string += seperator + argv[i];
seperator = " ";
}
#elif _AIX
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The indentation for this #elif block is different from the rest of this function, please can you make it consistent?

Copy link
Contributor Author

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.

Copy link
Member

@mhdawson mhdawson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about additional tests to validate we get he command line section ?

int argc = *_NSGetArgc();

commandline_string = "";
std::string seperator = "";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: seperator -> separator

fclose(psinfo_fd);
if (bytesread == sizeof(psinfo_t)) {
commandline_string = "";
std::string seperator = "";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: seperator -> separator

Add a check for the command line to common.js.
Add expected command line to all the test cases that pass an expected pid.
@hhellyer
Copy link
Contributor Author

hhellyer commented Jan 6, 2017

I've added the testcases or extended the existing ones.
(I've also fixed the spelling mistake.)

This change adds the command line to NodeReport on Windows. It
uses the Windows GetCommandLine() API to obtain the command line.

Also includes a minor change to print "Command line:" rather than
"Command line arguments:" in the report as prefix, plus updates to
the testcases.
@rnchamberlain
Copy link
Contributor

Added commit dd20187 for support on Windows. I think this PR has all we need now.

@@ -36,18 +36,18 @@ exports.validate = (t, report, options) => {
const expectedVersions = options ?
options.expectedVersions || nodeComponents :
nodeComponents;
const plan = REPORT_SECTIONS.length + nodeComponents.length + 2;
var plan = REPORT_SECTIONS.length + nodeComponents.length + 2;
if( options.commandline ) plan++;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Spaces -> if (options.commandline) plan++;

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

const nodeReportSection = getSection(reportContents, 'NodeReport');
t.match(nodeReportSection, new RegExp('Process ID: ' + pid),
t.contains(nodeReportSection, new RegExp('Process ID: ' + pid),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why was this changed?

Copy link
Contributor

@rnchamberlain rnchamberlain Jan 10, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@hhellyer said it fixed a test failure, but http://www.node-tap.org/asserts/ indicates that .contains is simply a synonym for .match, so I have reverted it. The tests pass ok for me on Linux, Windows and Mac.

// On Windows we need to strip out double quotes from the command line in the
// report, and escape the backslashes in the regex comparison string.
t.match(nodeReportSection.replace(/"/g,''),
new RegExp('Command line: ' + (options.commandline).replace(/\\/g,'\\\\')),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this line is > 80 chars.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

Copy link
Member

@mhdawson mhdawson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM subject to fixing the minor comments from Richard L

Currect spacing on if test, revert use of t.contains to t.match,
reduce line lengths to 80 or less.
if (options && options.commandline) {
if (this.isWindows()) {
// On Windows we need to strip double quotes from the command line in
// the report, and escape backslashes in the regex comparison string.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

n.b. I'm not seeing any double quotes in the reported command line in the reports generated from the tests on Windows.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It might depend on the shell or the executable path. This is what I am seeing on Windows:

==== NodeReport ================================================================

Event: JavaScript API, location: "TriggerReport"
Filename: NodeReport.20170110.113318.2184.001.txt
Dump event time:  2017/01/10 11:33:18
Module load time: 2017/01/10 11:33:18
Process ID: 2184
Command line: "C:\Program Files\nodejs6\node.exe" C:\tmp\nodereport\test\test-api-bad-processobj.js child

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah I think it might be spaces in the paths -- I get the same if I use Node.js installed under C:\Program Files

rnchamberlain pushed a commit that referenced this pull request Jan 11, 2017
On Linux it reads /proc/self/cmdline. On Mac is uses _NSGetArgv and
_NSGetArgc. On AIX it reads /proc/PID/psinfo. On Windows it uses the
GetCommandLine() API.

The command line is read and stored at startup so files aren't opened
when a crash is occuring.

PR-URL: #34
Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com>
Reviewed-By: Richard Lau <riclau@uk.ibm.com>
@rnchamberlain
Copy link
Contributor

Landed as c6db073

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants