From af35d4044fd32922ce784afa6da98520ffbbf872 Mon Sep 17 00:00:00 2001 From: cjihrig Date: Sun, 31 Mar 2019 10:33:23 -0400 Subject: [PATCH 1/2] report: use uv_gettimeofday for dumpEventTimeStamp dumpEventTimeStamp was not implemented on Windows, and did not include any error checking. This commit adds Windows support and error checking. PR-URL: https://github.com/nodejs/node/pull/27029 Reviewed-By: Refael Ackermann --- src/node_report.cc | 11 +++++++---- src/node_report.h | 5 +---- test/common/report.js | 6 +----- 3 files changed, 9 insertions(+), 13 deletions(-) diff --git a/src/node_report.cc b/src/node_report.cc index 74391cd4c1bcc9..8a257b0c9c6ef4 100644 --- a/src/node_report.cc +++ b/src/node_report.cc @@ -209,11 +209,14 @@ static void WriteNodeReport(Isolate* isolate, tm_struct.tm_min, tm_struct.tm_sec); writer.json_keyvalue("dumpEventTime", timebuf); - struct timeval ts; - gettimeofday(&ts, nullptr); - writer.json_keyvalue("dumpEventTimeStamp", - std::to_string(ts.tv_sec * 1000 + ts.tv_usec / 1000)); #endif + + uv_timeval64_t ts; + if (uv_gettimeofday(&ts) == 0) { + writer.json_keyvalue("dumpEventTimeStamp", + std::to_string(ts.tv_sec * 1000 + ts.tv_usec / 1000)); + } + // Report native process ID writer.json_keyvalue("processId", pid); diff --git a/src/node_report.h b/src/node_report.h index 5ae041b9fe9267..27ace3c8efedf9 100644 --- a/src/node_report.h +++ b/src/node_report.h @@ -5,10 +5,7 @@ #include "uv.h" #include "v8.h" -#ifdef _WIN32 -#include -#else -#include +#ifndef _WIN32 #include #include #endif diff --git a/test/common/report.js b/test/common/report.js index f3942c5d298abf..f97cf10669cada 100644 --- a/test/common/report.js +++ b/test/common/report.js @@ -70,11 +70,7 @@ function _validateContent(data) { assert(typeof header.filename === 'string' || header.filename === null); assert.notStrictEqual(new Date(header.dumpEventTime).toString(), 'Invalid Date'); - if (isWindows) - assert.strictEqual(header.dumpEventTimeStamp, undefined); - else - assert(String(+header.dumpEventTimeStamp), header.dumpEventTimeStamp); - + assert(String(+header.dumpEventTimeStamp), header.dumpEventTimeStamp); assert(Number.isSafeInteger(header.processId)); assert.strictEqual(typeof header.cwd, 'string'); assert(Array.isArray(header.commandLine)); From 8e1e9946a9f251fd943de1777fd9b598979e5a23 Mon Sep 17 00:00:00 2001 From: cjihrig Date: Mon, 15 Apr 2019 12:37:27 -0400 Subject: [PATCH 2/2] src: use uv_gettimeofday() to get microseconds Use uv_gettimeofday() in GetCurrentTimeInMicroseconds() to remove the need for #ifdef logic. PR-URL: https://github.com/nodejs/node/pull/27029 Reviewed-By: Refael Ackermann --- src/util.cc | 21 ++++----------------- 1 file changed, 4 insertions(+), 17 deletions(-) diff --git a/src/util.cc b/src/util.cc index 4091fffb6b894d..78ac680f39cea3 100644 --- a/src/util.cc +++ b/src/util.cc @@ -50,9 +50,6 @@ static std::atomic_int seq = {0}; // Sequence number for diagnostic filenames. namespace node { -// Microseconds in a second, as a float. -#define MICROS_PER_SEC 1e6 - using v8::ArrayBufferView; using v8::Isolate; using v8::Local; @@ -166,20 +163,10 @@ void ThrowErrStringTooLong(Isolate* isolate) { } double GetCurrentTimeInMicroseconds() { -#ifdef _WIN32 -// The difference between the Unix Epoch and the Windows Epoch in 100-ns ticks. -#define TICKS_TO_UNIX_EPOCH 116444736000000000LL - FILETIME ft; - GetSystemTimeAsFileTime(&ft); - uint64_t filetime_int = - static_cast(ft.dwHighDateTime) << 32 | ft.dwLowDateTime; - // FILETIME is measured in terms of 100 ns. Convert that to 1 us (1000 ns). - return (filetime_int - TICKS_TO_UNIX_EPOCH) / 10.; -#else - struct timeval tp; - gettimeofday(&tp, nullptr); - return MICROS_PER_SEC * tp.tv_sec + tp.tv_usec; -#endif + constexpr double kMicrosecondsPerSecond = 1e6; + uv_timeval64_t tv; + CHECK_EQ(0, uv_gettimeofday(&tv)); + return kMicrosecondsPerSecond * tv.tv_sec + tv.tv_usec; } int WriteFileSync(const char* path, uv_buf_t buf) {