Skip to content

Commit e3bae20

Browse files
richardlautargos
authored andcommitted
report: use DiagnosticFilename for default filename
PR-URL: #26647 Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
1 parent 925b645 commit e3bae20

File tree

3 files changed

+12
-31
lines changed

3 files changed

+12
-31
lines changed

doc/api/report.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ is provided below for reference.
2424
"header": {
2525
"event": "exception",
2626
"trigger": "Exception",
27-
"filename": "report.20181221.005011.8974.001.json",
27+
"filename": "report.20181221.005011.8974.0.001.json",
2828
"dumpEventTime": "2018-12-21T00:50:11Z",
2929
"dumpEventTimeStamp": "1545371411331",
3030
"processId": 8974,
@@ -471,7 +471,7 @@ triggered using the Node.js REPL:
471471
```raw
472472
$ node
473473
> process.report.writeReport();
474-
Writing Node.js report to file: report.20181126.091102.8480.001.json
474+
Writing Node.js report to file: report.20181126.091102.8480.0.001.json
475475
Node.js report completed
476476
>
477477
```

src/node_report.cc

+8-27
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ constexpr double SEC_PER_MICROS = 1e-6;
4343

4444
namespace report {
4545
using node::arraysize;
46+
using node::DiagnosticFilename;
4647
using node::Environment;
4748
using node::Mutex;
4849
using node::NativeSymbolDebuggingContext;
@@ -92,46 +93,26 @@ std::string TriggerNodeReport(Isolate* isolate,
9293
const char* trigger,
9394
const std::string& name,
9495
Local<String> stackstr) {
95-
std::ostringstream oss;
9696
std::string filename;
9797
std::shared_ptr<PerIsolateOptions> options;
9898
if (env != nullptr) options = env->isolate_data()->options();
9999

100-
// Obtain the current time and the pid (platform dependent)
100+
// Obtain the current time.
101101
TIME_TYPE tm_struct;
102102
LocalTime(&tm_struct);
103103
// Determine the required report filename. In order of priority:
104104
// 1) supplied on API 2) configured on startup 3) default generated
105105
if (!name.empty()) {
106-
// Filename was specified as API parameter, use that
107-
oss << name;
106+
// Filename was specified as API parameter.
107+
filename = name;
108108
} else if (env != nullptr && options->report_filename.length() > 0) {
109-
// File name was supplied via start-up option, use that
110-
oss << options->report_filename;
109+
// File name was supplied via start-up option.
110+
filename = options->report_filename;
111111
} else {
112-
// Construct the report filename, with timestamp, pid and sequence number
113-
oss << "report";
114-
#ifdef _WIN32
115-
oss << "." << std::setfill('0') << std::setw(4) << tm_struct.wYear;
116-
oss << std::setfill('0') << std::setw(2) << tm_struct.wMonth;
117-
oss << std::setfill('0') << std::setw(2) << tm_struct.wDay;
118-
oss << "." << std::setfill('0') << std::setw(2) << tm_struct.wHour;
119-
oss << std::setfill('0') << std::setw(2) << tm_struct.wMinute;
120-
oss << std::setfill('0') << std::setw(2) << tm_struct.wSecond;
121-
#else // UNIX, OSX
122-
oss << "." << std::setfill('0') << std::setw(4) << tm_struct.tm_year + 1900;
123-
oss << std::setfill('0') << std::setw(2) << tm_struct.tm_mon + 1;
124-
oss << std::setfill('0') << std::setw(2) << tm_struct.tm_mday;
125-
oss << "." << std::setfill('0') << std::setw(2) << tm_struct.tm_hour;
126-
oss << std::setfill('0') << std::setw(2) << tm_struct.tm_min;
127-
oss << std::setfill('0') << std::setw(2) << tm_struct.tm_sec;
128-
#endif
129-
oss << "." << uv_os_getpid();
130-
oss << "." << std::setfill('0') << std::setw(3) << ++seq;
131-
oss << ".json";
112+
filename = *DiagnosticFilename(env != nullptr ? env->thread_id() : 0,
113+
"report", "json", seq++);
132114
}
133115

134-
filename = oss.str();
135116
// Open the report file stream for writing. Supports stdout/err,
136117
// user-specified or (default) generated name
137118
std::ofstream outfile;

test/common/report.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ const path = require('path');
77

88
function findReports(pid, dir) {
99
// Default filenames are of the form
10-
// report.<date>.<time>.<pid>.<seq>.json
11-
const format = '^report\\.\\d+\\.\\d+\\.' + pid + '\\.\\d+\\.json$';
10+
// report.<date>.<time>.<pid>.<tid>.<seq>.json
11+
const format = '^report\\.\\d+\\.\\d+\\.' + pid + '\\.\\d+\\.\\d+\\.json$';
1212
const filePattern = new RegExp(format);
1313
const files = fs.readdirSync(dir);
1414
const results = [];

0 commit comments

Comments
 (0)