diff options
author | cjihrig <cjihrig@gmail.com> | 2019-02-18 00:46:32 +0300 |
---|---|---|
committer | cjihrig <cjihrig@gmail.com> | 2019-02-20 16:43:59 +0300 |
commit | 1dc22bf3e55d5a7e1580f382231ee7af36de05aa (patch) | |
tree | e6eac6803bd141a3bf4196044350db20d4db06ff /src/node_report.cc | |
parent | 1aadfa87000849330cb3baa2061966f4511446ed (diff) |
report: simplify TriggerNodeReport()
PR-URL: https://github.com/nodejs/node/pull/26174
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Richard Lau <riclau@uk.ibm.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Diffstat (limited to 'src/node_report.cc')
-rw-r--r-- | src/node_report.cc | 36 |
1 files changed, 14 insertions, 22 deletions
diff --git a/src/node_report.cc b/src/node_report.cc index d4f59de84d8..59aa0657a97 100644 --- a/src/node_report.cc +++ b/src/node_report.cc @@ -111,7 +111,6 @@ std::string TriggerNodeReport(Isolate* isolate, // Obtain the current time and the pid (platform dependent) TIME_TYPE tm_struct; LocalTime(&tm_struct); - uv_pid_t pid = uv_os_getpid(); // Determine the required report filename. In order of priority: // 1) supplied on API 2) configured on startup 3) default generated if (!name.empty()) { @@ -123,7 +122,6 @@ std::string TriggerNodeReport(Isolate* isolate, } else { // Construct the report filename, with timestamp, pid and sequence number oss << "report"; - seq++; #ifdef _WIN32 oss << "." << std::setfill('0') << std::setw(4) << tm_struct.wYear; oss << std::setfill('0') << std::setw(2) << tm_struct.wMonth; @@ -131,8 +129,6 @@ std::string TriggerNodeReport(Isolate* isolate, oss << "." << std::setfill('0') << std::setw(2) << tm_struct.wHour; oss << std::setfill('0') << std::setw(2) << tm_struct.wMinute; oss << std::setfill('0') << std::setw(2) << tm_struct.wSecond; - oss << "." << pid; - oss << "." << std::setfill('0') << std::setw(3) << seq.load(); #else // UNIX, OSX oss << "." << std::setfill('0') << std::setw(4) << tm_struct.tm_year + 1900; oss << std::setfill('0') << std::setw(2) << tm_struct.tm_mon + 1; @@ -140,9 +136,9 @@ std::string TriggerNodeReport(Isolate* isolate, oss << "." << std::setfill('0') << std::setw(2) << tm_struct.tm_hour; oss << std::setfill('0') << std::setw(2) << tm_struct.tm_min; oss << std::setfill('0') << std::setw(2) << tm_struct.tm_sec; - oss << "." << pid; - oss << "." << std::setfill('0') << std::setw(3) << seq.load(); #endif + oss << "." << uv_os_getpid(); + oss << "." << std::setfill('0') << std::setw(3) << ++seq; oss << ".json"; } @@ -150,7 +146,7 @@ std::string TriggerNodeReport(Isolate* isolate, // Open the report file stream for writing. Supports stdout/err, // user-specified or (default) generated name std::ofstream outfile; - std::ostream* outstream = &std::cout; + std::ostream* outstream; if (filename == "stdout") { outstream = &std::cout; } else if (filename == "stderr") { @@ -167,21 +163,18 @@ std::string TriggerNodeReport(Isolate* isolate, } // Check for errors on the file open if (!outfile.is_open()) { - if (env != nullptr && options->report_directory.length() > 0) { - std::cerr << std::endl - << "Failed to open Node.js report file: " << filename - << " directory: " << options->report_directory - << " (errno: " << errno << ")" << std::endl; - } else { - std::cerr << std::endl - << "Failed to open Node.js report file: " << filename - << " (errno: " << errno << ")" << std::endl; - } - return ""; - } else { std::cerr << std::endl - << "Writing Node.js report to file: " << filename << std::endl; + << "Failed to open Node.js report file: " << filename; + + if (env != nullptr && options->report_directory.length() > 0) + std::cerr << " directory: " << options->report_directory; + + std::cerr << " (errno: " << errno << ")" << std::endl; + return ""; } + + std::cerr << std::endl + << "Writing Node.js report to file: " << filename << std::endl; } // Pass our stream about by reference, not by copying it. @@ -196,8 +189,7 @@ std::string TriggerNodeReport(Isolate* isolate, } std::cerr << "Node.js report completed" << std::endl; - if (name.empty()) return filename; - return name; + return filename; } // External function to trigger a report, writing to a supplied stream. |