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>
This commit is contained in:
parent
1aadfa8700
commit
1dc22bf3e5
@ -111,7 +111,6 @@ std::string TriggerNodeReport(Isolate* isolate,
|
|||||||
// Obtain the current time and the pid (platform dependent)
|
// Obtain the current time and the pid (platform dependent)
|
||||||
TIME_TYPE tm_struct;
|
TIME_TYPE tm_struct;
|
||||||
LocalTime(&tm_struct);
|
LocalTime(&tm_struct);
|
||||||
uv_pid_t pid = uv_os_getpid();
|
|
||||||
// Determine the required report filename. In order of priority:
|
// Determine the required report filename. In order of priority:
|
||||||
// 1) supplied on API 2) configured on startup 3) default generated
|
// 1) supplied on API 2) configured on startup 3) default generated
|
||||||
if (!name.empty()) {
|
if (!name.empty()) {
|
||||||
@ -123,7 +122,6 @@ std::string TriggerNodeReport(Isolate* isolate,
|
|||||||
} else {
|
} else {
|
||||||
// Construct the report filename, with timestamp, pid and sequence number
|
// Construct the report filename, with timestamp, pid and sequence number
|
||||||
oss << "report";
|
oss << "report";
|
||||||
seq++;
|
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
oss << "." << std::setfill('0') << std::setw(4) << tm_struct.wYear;
|
oss << "." << std::setfill('0') << std::setw(4) << tm_struct.wYear;
|
||||||
oss << std::setfill('0') << std::setw(2) << tm_struct.wMonth;
|
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.wHour;
|
||||||
oss << std::setfill('0') << std::setw(2) << tm_struct.wMinute;
|
oss << std::setfill('0') << std::setw(2) << tm_struct.wMinute;
|
||||||
oss << std::setfill('0') << std::setw(2) << tm_struct.wSecond;
|
oss << std::setfill('0') << std::setw(2) << tm_struct.wSecond;
|
||||||
oss << "." << pid;
|
|
||||||
oss << "." << std::setfill('0') << std::setw(3) << seq.load();
|
|
||||||
#else // UNIX, OSX
|
#else // UNIX, OSX
|
||||||
oss << "." << std::setfill('0') << std::setw(4) << tm_struct.tm_year + 1900;
|
oss << "." << std::setfill('0') << std::setw(4) << tm_struct.tm_year + 1900;
|
||||||
oss << std::setfill('0') << std::setw(2) << tm_struct.tm_mon + 1;
|
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_hour;
|
||||||
oss << std::setfill('0') << std::setw(2) << tm_struct.tm_min;
|
oss << std::setfill('0') << std::setw(2) << tm_struct.tm_min;
|
||||||
oss << std::setfill('0') << std::setw(2) << tm_struct.tm_sec;
|
oss << std::setfill('0') << std::setw(2) << tm_struct.tm_sec;
|
||||||
oss << "." << pid;
|
|
||||||
oss << "." << std::setfill('0') << std::setw(3) << seq.load();
|
|
||||||
#endif
|
#endif
|
||||||
|
oss << "." << uv_os_getpid();
|
||||||
|
oss << "." << std::setfill('0') << std::setw(3) << ++seq;
|
||||||
oss << ".json";
|
oss << ".json";
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -150,7 +146,7 @@ std::string TriggerNodeReport(Isolate* isolate,
|
|||||||
// Open the report file stream for writing. Supports stdout/err,
|
// Open the report file stream for writing. Supports stdout/err,
|
||||||
// user-specified or (default) generated name
|
// user-specified or (default) generated name
|
||||||
std::ofstream outfile;
|
std::ofstream outfile;
|
||||||
std::ostream* outstream = &std::cout;
|
std::ostream* outstream;
|
||||||
if (filename == "stdout") {
|
if (filename == "stdout") {
|
||||||
outstream = &std::cout;
|
outstream = &std::cout;
|
||||||
} else if (filename == "stderr") {
|
} else if (filename == "stderr") {
|
||||||
@ -167,21 +163,18 @@ std::string TriggerNodeReport(Isolate* isolate,
|
|||||||
}
|
}
|
||||||
// Check for errors on the file open
|
// Check for errors on the file open
|
||||||
if (!outfile.is_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
|
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.
|
// 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;
|
std::cerr << "Node.js report completed" << std::endl;
|
||||||
if (name.empty()) return filename;
|
return filename;
|
||||||
return name;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// External function to trigger a report, writing to a supplied stream.
|
// External function to trigger a report, writing to a supplied stream.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user