Skip to content

Commit 5075bb4

Browse files
authored
perf_hooks: add NODE_PERFORMANCE_GC_MINOR_MARK_SWEEP constant
V8's Minor Mark-Sweep collector, enabled with the --minor-ms flag (available since Node.js 22), reports garbage collection performance entries with kind kGCTypeMinorMarkSweep (value 2). perf_hooks exposed constants for every other GC kind (major, minor, incremental, weakcb) but not this one, so consumers inspecting performanceEntry.detail.kind had no constant to compare against and saw an unmapped value. Expose it as perf_hooks.constants.NODE_PERFORMANCE_GC_MINOR_MARK_SWEEP, mirroring the existing v8::GCType mappings, and document it alongside the other GC kinds. Signed-off-by: Attila Szegedi <attila.szegedi@datadoghq.com> PR-URL: #63877 Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com> Reviewed-By: Ilyas Shabi <ilyasshabi94@gmail.com> Reviewed-By: Chengzhong Wu <legendecas@gmail.com>
1 parent ccc2d7c commit 5075bb4

5 files changed

Lines changed: 42 additions & 0 deletions

File tree

doc/api/perf_hooks.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -643,6 +643,7 @@ The value may be one of:
643643

644644
* `perf_hooks.constants.NODE_PERFORMANCE_GC_MAJOR`
645645
* `perf_hooks.constants.NODE_PERFORMANCE_GC_MINOR`
646+
* `perf_hooks.constants.NODE_PERFORMANCE_GC_MINOR_MARK_SWEEP`
646647
* `perf_hooks.constants.NODE_PERFORMANCE_GC_INCREMENTAL`
647648
* `perf_hooks.constants.NODE_PERFORMANCE_GC_WEAKCB`
648649

@@ -654,6 +655,7 @@ When `performanceEntry.type` is equal to `'gc'`, the
654655
* `kind` {number} One of:
655656
* `perf_hooks.constants.NODE_PERFORMANCE_GC_MAJOR`
656657
* `perf_hooks.constants.NODE_PERFORMANCE_GC_MINOR`
658+
* `perf_hooks.constants.NODE_PERFORMANCE_GC_MINOR_MARK_SWEEP`
657659
* `perf_hooks.constants.NODE_PERFORMANCE_GC_INCREMENTAL`
658660
* `perf_hooks.constants.NODE_PERFORMANCE_GC_WEAKCB`
659661
* `flags` {number} One of:

src/node_perf.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -365,6 +365,7 @@ void CreatePerContextProperties(Local<Object> target,
365365

366366
NODE_DEFINE_CONSTANT(constants, NODE_PERFORMANCE_GC_MAJOR);
367367
NODE_DEFINE_CONSTANT(constants, NODE_PERFORMANCE_GC_MINOR);
368+
NODE_DEFINE_CONSTANT(constants, NODE_PERFORMANCE_GC_MINOR_MARK_SWEEP);
368369
NODE_DEFINE_CONSTANT(constants, NODE_PERFORMANCE_GC_INCREMENTAL);
369370
NODE_DEFINE_CONSTANT(constants, NODE_PERFORMANCE_GC_WEAKCB);
370371

src/node_perf.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ inline PerformanceEntryType ToPerformanceEntryTypeEnum(
6363
enum PerformanceGCKind {
6464
NODE_PERFORMANCE_GC_MAJOR = v8::GCType::kGCTypeMarkSweepCompact,
6565
NODE_PERFORMANCE_GC_MINOR = v8::GCType::kGCTypeScavenge,
66+
NODE_PERFORMANCE_GC_MINOR_MARK_SWEEP = v8::GCType::kGCTypeMinorMarkSweep,
6667
NODE_PERFORMANCE_GC_INCREMENTAL = v8::GCType::kGCTypeIncrementalMarking,
6768
NODE_PERFORMANCE_GC_WEAKCB = v8::GCType::kGCTypeProcessWeakCallbacks
6869
};
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
// Flags: --expose-gc --no-warnings --minor-ms
2+
'use strict';
3+
4+
// When V8's Minor Mark-Sweep collector is enabled (--minor-ms), minor garbage
5+
// collections are reported with kind NODE_PERFORMANCE_GC_MINOR_MARK_SWEEP
6+
// rather than NODE_PERFORMANCE_GC_MINOR.
7+
8+
const common = require('../common');
9+
const assert = require('assert');
10+
const { gcUntil } = require('../common/gc');
11+
const {
12+
PerformanceObserver,
13+
constants
14+
} = require('perf_hooks');
15+
16+
const {
17+
NODE_PERFORMANCE_GC_MINOR_MARK_SWEEP
18+
} = constants;
19+
20+
let observed = false;
21+
const obs = new PerformanceObserver(common.mustCallAtLeast((list) => {
22+
for (const entry of list.getEntries()) {
23+
// Other GC kinds (e.g. a scheduled or incremental GC) may be observed in
24+
// between; only the minor mark-sweep entry is relevant here.
25+
if (entry.detail.kind === NODE_PERFORMANCE_GC_MINOR_MARK_SWEEP) {
26+
assert.strictEqual(entry.name, 'gc');
27+
assert.strictEqual(entry.entryType, 'gc');
28+
observed = true;
29+
obs.disconnect();
30+
return;
31+
}
32+
}
33+
}));
34+
obs.observe({ entryTypes: ['gc'] });
35+
36+
gcUntil('minor gc event', () => observed, 10, { type: 'minor' });

test/parallel/test-performance-gc.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ const {
1111
const {
1212
NODE_PERFORMANCE_GC_MAJOR,
1313
NODE_PERFORMANCE_GC_MINOR,
14+
NODE_PERFORMANCE_GC_MINOR_MARK_SWEEP,
1415
NODE_PERFORMANCE_GC_INCREMENTAL,
1516
NODE_PERFORMANCE_GC_WEAKCB,
1617
NODE_PERFORMANCE_GC_FLAGS_FORCED
@@ -19,6 +20,7 @@ const {
1920
const kinds = [
2021
NODE_PERFORMANCE_GC_MAJOR,
2122
NODE_PERFORMANCE_GC_MINOR,
23+
NODE_PERFORMANCE_GC_MINOR_MARK_SWEEP,
2224
NODE_PERFORMANCE_GC_INCREMENTAL,
2325
NODE_PERFORMANCE_GC_WEAKCB,
2426
];

0 commit comments

Comments
 (0)