From 35c4b8e36319a9d40b7b483f11293cfbeb0fefab Mon Sep 17 00:00:00 2001 From: meixg Date: Thu, 12 May 2022 13:16:14 +0800 Subject: [PATCH 1/2] perf_hooks: fix miscounted gc performance entry starttime fixes: https://github.com/nodejs/node/issues/43062 --- src/node_perf.cc | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/node_perf.cc b/src/node_perf.cc index 910e1e47efa0a5..253f72157e8a7b 100644 --- a/src/node_perf.cc +++ b/src/node_perf.cc @@ -159,8 +159,10 @@ void MarkGarbageCollectionEnd( if (LIKELY(!state->observers[NODE_PERFORMANCE_ENTRY_TYPE_GC])) return; - double start_time = state->performance_last_gc_start_mark / 1e6; - double duration = (PERFORMANCE_NOW() / 1e6) - start_time; + double start_time = + (state->performance_last_gc_start_mark - timeOrigin) / 1e6; + double duration = + (PERFORMANCE_NOW() / 1e6) - (state->performance_last_gc_start_mark / 1e6); std::unique_ptr entry = std::make_unique( From f2530a9308cd520c90e7300c68a2f46d08f4a6e5 Mon Sep 17 00:00:00 2001 From: meixg Date: Thu, 12 May 2022 14:12:59 +0800 Subject: [PATCH 2/2] perf_hooks: fix miscounted gc performance entry starttime add test case --- test/parallel/test-performance-gc.js | 1 + 1 file changed, 1 insertion(+) diff --git a/test/parallel/test-performance-gc.js b/test/parallel/test-performance-gc.js index 1561bc5fb78572..9c4a3a850a22dd 100644 --- a/test/parallel/test-performance-gc.js +++ b/test/parallel/test-performance-gc.js @@ -35,6 +35,7 @@ const kinds = [ assert.strictEqual(entry.flags, NODE_PERFORMANCE_GC_FLAGS_FORCED); assert.strictEqual(entry.detail.flags, NODE_PERFORMANCE_GC_FLAGS_FORCED); assert.strictEqual(typeof entry.startTime, 'number'); + assert(entry.startTime < 1e4, 'startTime should be relative to performance.timeOrigin.'); assert.strictEqual(typeof entry.duration, 'number'); obs.disconnect(); }));