From e3bae209416ef98e6c11f0595999217130b4affb Mon Sep 17 00:00:00 2001 From: Richard Lau Date: Wed, 13 Mar 2019 20:39:51 -0400 Subject: [PATCH] report: use DiagnosticFilename for default filename PR-URL: https://github.com/nodejs/node/pull/26647 Reviewed-By: Colin Ihrig Reviewed-By: Ruben Bridgewater Reviewed-By: James M Snell Reviewed-By: Joyee Cheung --- doc/api/report.md | 4 ++-- src/node_report.cc | 35 ++++++++--------------------------- test/common/report.js | 4 ++-- 3 files changed, 12 insertions(+), 31 deletions(-) diff --git a/doc/api/report.md b/doc/api/report.md index 7cb349395314e2..a7715751d5761f 100644 --- a/doc/api/report.md +++ b/doc/api/report.md @@ -24,7 +24,7 @@ is provided below for reference. "header": { "event": "exception", "trigger": "Exception", - "filename": "report.20181221.005011.8974.001.json", + "filename": "report.20181221.005011.8974.0.001.json", "dumpEventTime": "2018-12-21T00:50:11Z", "dumpEventTimeStamp": "1545371411331", "processId": 8974, @@ -471,7 +471,7 @@ triggered using the Node.js REPL: ```raw $ node > process.report.writeReport(); -Writing Node.js report to file: report.20181126.091102.8480.001.json +Writing Node.js report to file: report.20181126.091102.8480.0.001.json Node.js report completed > ``` diff --git a/src/node_report.cc b/src/node_report.cc index a319f51fdb1a9e..2c2616d7947581 100644 --- a/src/node_report.cc +++ b/src/node_report.cc @@ -43,6 +43,7 @@ constexpr double SEC_PER_MICROS = 1e-6; namespace report { using node::arraysize; +using node::DiagnosticFilename; using node::Environment; using node::Mutex; using node::NativeSymbolDebuggingContext; @@ -92,46 +93,26 @@ std::string TriggerNodeReport(Isolate* isolate, const char* trigger, const std::string& name, Local stackstr) { - std::ostringstream oss; std::string filename; std::shared_ptr options; if (env != nullptr) options = env->isolate_data()->options(); - // Obtain the current time and the pid (platform dependent) + // Obtain the current time. TIME_TYPE tm_struct; LocalTime(&tm_struct); // Determine the required report filename. In order of priority: // 1) supplied on API 2) configured on startup 3) default generated if (!name.empty()) { - // Filename was specified as API parameter, use that - oss << name; + // Filename was specified as API parameter. + filename = name; } else if (env != nullptr && options->report_filename.length() > 0) { - // File name was supplied via start-up option, use that - oss << options->report_filename; + // File name was supplied via start-up option. + filename = options->report_filename; } else { - // Construct the report filename, with timestamp, pid and sequence number - oss << "report"; -#ifdef _WIN32 - 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.wDay; - 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; -#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; - oss << std::setfill('0') << std::setw(2) << tm_struct.tm_mday; - 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; -#endif - oss << "." << uv_os_getpid(); - oss << "." << std::setfill('0') << std::setw(3) << ++seq; - oss << ".json"; + filename = *DiagnosticFilename(env != nullptr ? env->thread_id() : 0, + "report", "json", seq++); } - filename = oss.str(); // Open the report file stream for writing. Supports stdout/err, // user-specified or (default) generated name std::ofstream outfile; diff --git a/test/common/report.js b/test/common/report.js index 22a905957e1122..a9c1d038d22bd5 100644 --- a/test/common/report.js +++ b/test/common/report.js @@ -7,8 +7,8 @@ const path = require('path'); function findReports(pid, dir) { // Default filenames are of the form - // report..