Skip to content

Commit 02009b7

Browse files
meixgtargos
authored andcommitted
perf_hooks: fix miscounted gc performance entry starttime (#43066)
PR-URL: #43066 Fixes: #43062 Reviewed-By: Chengzhong Wu <[email protected]> Reviewed-By: James M Snell <[email protected]>
1 parent 752380a commit 02009b7

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

src/node_perf.cc

+4-2
Original file line numberDiff line numberDiff line change
@@ -159,8 +159,10 @@ void MarkGarbageCollectionEnd(
159159
if (LIKELY(!state->observers[NODE_PERFORMANCE_ENTRY_TYPE_GC]))
160160
return;
161161

162-
double start_time = state->performance_last_gc_start_mark / 1e6;
163-
double duration = (PERFORMANCE_NOW() / 1e6) - start_time;
162+
double start_time =
163+
(state->performance_last_gc_start_mark - timeOrigin) / 1e6;
164+
double duration =
165+
(PERFORMANCE_NOW() / 1e6) - (state->performance_last_gc_start_mark / 1e6);
164166

165167
std::unique_ptr<GCPerformanceEntry> entry =
166168
std::make_unique<GCPerformanceEntry>(

test/parallel/test-performance-gc.js

+1
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ const kinds = [
3535
assert.strictEqual(entry.flags, NODE_PERFORMANCE_GC_FLAGS_FORCED);
3636
assert.strictEqual(entry.detail.flags, NODE_PERFORMANCE_GC_FLAGS_FORCED);
3737
assert.strictEqual(typeof entry.startTime, 'number');
38+
assert(entry.startTime < 1e4, 'startTime should be relative to performance.timeOrigin.');
3839
assert.strictEqual(typeof entry.duration, 'number');
3940
obs.disconnect();
4041
}));

0 commit comments

Comments
 (0)