Skip to content

Commit

Permalink
perf_hooks: fix miscounted gc performance entry starttime (#43066)
Browse files Browse the repository at this point in the history
PR-URL: #43066
Fixes: #43062
Reviewed-By: Chengzhong Wu <[email protected]>
Reviewed-By: James M Snell <[email protected]>
  • Loading branch information
meixg authored and targos committed Jul 12, 2022
1 parent 752380a commit 02009b7
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/node_perf.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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<GCPerformanceEntry> entry =
std::make_unique<GCPerformanceEntry>(
Expand Down
1 change: 1 addition & 0 deletions test/parallel/test-performance-gc.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}));
Expand Down

0 comments on commit 02009b7

Please sign in to comment.