Skip to content

Commit 5c41876

Browse files
richardlautargos
authored andcommitted
report: use LocalTime from DiagnosticFilename
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 e3bae20 commit 5c41876

File tree

1 file changed

+19
-36
lines changed

1 file changed

+19
-36
lines changed

src/node_report.cc

+19-36
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,7 @@ static void WriteNodeReport(Isolate* isolate,
6565
const char* trigger,
6666
const std::string& filename,
6767
std::ostream& out,
68-
Local<String> stackstr,
69-
TIME_TYPE* tm_struct);
68+
Local<String> stackstr);
7069
static void PrintVersionInformation(JSONWriter* writer);
7170
static void PrintJavaScriptStack(JSONWriter* writer,
7271
Isolate* isolate,
@@ -79,7 +78,6 @@ static void PrintSystemInformation(JSONWriter* writer);
7978
static void PrintLoadedLibraries(JSONWriter* writer);
8079
static void PrintComponentVersions(JSONWriter* writer);
8180
static void PrintRelease(JSONWriter* writer);
82-
static void LocalTime(TIME_TYPE* tm_struct);
8381

8482
// Global variables
8583
static std::atomic_int seq = {0}; // sequence number for report filenames
@@ -97,9 +95,6 @@ std::string TriggerNodeReport(Isolate* isolate,
9795
std::shared_ptr<PerIsolateOptions> options;
9896
if (env != nullptr) options = env->isolate_data()->options();
9997

100-
// Obtain the current time.
101-
TIME_TYPE tm_struct;
102-
LocalTime(&tm_struct);
10398
// Determine the required report filename. In order of priority:
10499
// 1) supplied on API 2) configured on startup 3) default generated
105100
if (!name.empty()) {
@@ -147,7 +142,7 @@ std::string TriggerNodeReport(Isolate* isolate,
147142
}
148143

149144
WriteNodeReport(isolate, env, message, trigger, filename, *outstream,
150-
stackstr, &tm_struct);
145+
stackstr);
151146

152147
// Do not close stdout/stderr, only close files we opened.
153148
if (outfile.is_open()) {
@@ -165,11 +160,7 @@ void GetNodeReport(Isolate* isolate,
165160
const char* trigger,
166161
Local<String> stackstr,
167162
std::ostream& out) {
168-
// Obtain the current time and the pid (platform dependent)
169-
TIME_TYPE tm_struct;
170-
LocalTime(&tm_struct);
171-
WriteNodeReport(
172-
isolate, env, message, trigger, "", out, stackstr, &tm_struct);
163+
WriteNodeReport(isolate, env, message, trigger, "", out, stackstr);
173164
}
174165

175166
// Internal function to coordinate and write the various
@@ -180,8 +171,10 @@ static void WriteNodeReport(Isolate* isolate,
180171
const char* trigger,
181172
const std::string& filename,
182173
std::ostream& out,
183-
Local<String> stackstr,
184-
TIME_TYPE* tm_struct) {
174+
Local<String> stackstr) {
175+
// Obtain the current time and the pid.
176+
TIME_TYPE tm_struct;
177+
DiagnosticFilename::LocalTime(&tm_struct);
185178
uv_pid_t pid = uv_os_getpid();
186179

187180
// Save formatting for output stream.
@@ -208,23 +201,23 @@ static void WriteNodeReport(Isolate* isolate,
208201
snprintf(timebuf,
209202
sizeof(timebuf),
210203
"%4d-%02d-%02dT%02d:%02d:%02dZ",
211-
tm_struct->wYear,
212-
tm_struct->wMonth,
213-
tm_struct->wDay,
214-
tm_struct->wHour,
215-
tm_struct->wMinute,
216-
tm_struct->wSecond);
204+
tm_struct.wYear,
205+
tm_struct.wMonth,
206+
tm_struct.wDay,
207+
tm_struct.wHour,
208+
tm_struct.wMinute,
209+
tm_struct.wSecond);
217210
writer.json_keyvalue("dumpEventTime", timebuf);
218211
#else // UNIX, OSX
219212
snprintf(timebuf,
220213
sizeof(timebuf),
221214
"%4d-%02d-%02dT%02d:%02d:%02dZ",
222-
tm_struct->tm_year + 1900,
223-
tm_struct->tm_mon + 1,
224-
tm_struct->tm_mday,
225-
tm_struct->tm_hour,
226-
tm_struct->tm_min,
227-
tm_struct->tm_sec);
215+
tm_struct.tm_year + 1900,
216+
tm_struct.tm_mon + 1,
217+
tm_struct.tm_mday,
218+
tm_struct.tm_hour,
219+
tm_struct.tm_min,
220+
tm_struct.tm_sec);
228221
writer.json_keyvalue("dumpEventTime", timebuf);
229222
struct timeval ts;
230223
gettimeofday(&ts, nullptr);
@@ -619,14 +612,4 @@ static void PrintRelease(JSONWriter* writer) {
619612
writer->json_objectend();
620613
}
621614

622-
static void LocalTime(TIME_TYPE* tm_struct) {
623-
#ifdef _WIN32
624-
GetLocalTime(tm_struct);
625-
#else // UNIX, OSX
626-
struct timeval time_val;
627-
gettimeofday(&time_val, nullptr);
628-
localtime_r(&time_val.tv_sec, tm_struct);
629-
#endif
630-
}
631-
632615
} // namespace report

0 commit comments

Comments
 (0)