mirror of
https://github.com/nodejs/node.git
synced 2026-11-27 17:52:27 -05:00
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: https://github.com/nodejs/node/pull/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>
This commit is contained in:
1 parent
873cc72125
commit
f08b83bc1d
5 files changed
+42
No files matched your search
@@ -639,6 +639,7 @@ The value may be one of:
|
||||
|
||||
* `perf_hooks.constants.NODE_PERFORMANCE_GC_MAJOR`
|
||||
* `perf_hooks.constants.NODE_PERFORMANCE_GC_MINOR`
|
||||
* `perf_hooks.constants.NODE_PERFORMANCE_GC_MINOR_MARK_SWEEP`
|
||||
* `perf_hooks.constants.NODE_PERFORMANCE_GC_INCREMENTAL`
|
||||
* `perf_hooks.constants.NODE_PERFORMANCE_GC_WEAKCB`
|
||||
|
||||
@@ -650,6 +651,7 @@ When `performanceEntry.type` is equal to `'gc'`, the
|
||||
* `kind` {number} One of:
|
||||
* `perf_hooks.constants.NODE_PERFORMANCE_GC_MAJOR`
|
||||
* `perf_hooks.constants.NODE_PERFORMANCE_GC_MINOR`
|
||||
* `perf_hooks.constants.NODE_PERFORMANCE_GC_MINOR_MARK_SWEEP`
|
||||
* `perf_hooks.constants.NODE_PERFORMANCE_GC_INCREMENTAL`
|
||||
* `perf_hooks.constants.NODE_PERFORMANCE_GC_WEAKCB`
|
||||
* `flags` {number} One of:
|
||||
|
||||
@@ -365,6 +365,7 @@ void CreatePerContextProperties(Local<Object> target,
|
||||
|
||||
NODE_DEFINE_CONSTANT(constants, NODE_PERFORMANCE_GC_MAJOR);
|
||||
NODE_DEFINE_CONSTANT(constants, NODE_PERFORMANCE_GC_MINOR);
|
||||
NODE_DEFINE_CONSTANT(constants, NODE_PERFORMANCE_GC_MINOR_MARK_SWEEP);
|
||||
NODE_DEFINE_CONSTANT(constants, NODE_PERFORMANCE_GC_INCREMENTAL);
|
||||
NODE_DEFINE_CONSTANT(constants, NODE_PERFORMANCE_GC_WEAKCB);
|
||||
|
||||
|
||||
@@ -63,6 +63,7 @@ inline PerformanceEntryType ToPerformanceEntryTypeEnum(
|
||||
enum PerformanceGCKind {
|
||||
NODE_PERFORMANCE_GC_MAJOR = v8::GCType::kGCTypeMarkSweepCompact,
|
||||
NODE_PERFORMANCE_GC_MINOR = v8::GCType::kGCTypeScavenge,
|
||||
NODE_PERFORMANCE_GC_MINOR_MARK_SWEEP = v8::GCType::kGCTypeMinorMarkSweep,
|
||||
NODE_PERFORMANCE_GC_INCREMENTAL = v8::GCType::kGCTypeIncrementalMarking,
|
||||
NODE_PERFORMANCE_GC_WEAKCB = v8::GCType::kGCTypeProcessWeakCallbacks
|
||||
};
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
// Flags: --expose-gc --no-warnings --minor-ms
|
||||
'use strict';
|
||||
|
||||
// When V8's Minor Mark-Sweep collector is enabled (--minor-ms), minor garbage
|
||||
// collections are reported with kind NODE_PERFORMANCE_GC_MINOR_MARK_SWEEP
|
||||
// rather than NODE_PERFORMANCE_GC_MINOR.
|
||||
|
||||
const common = require('../common');
|
||||
const assert = require('assert');
|
||||
const { gcUntil } = require('../common/gc');
|
||||
const {
|
||||
PerformanceObserver,
|
||||
constants
|
||||
} = require('perf_hooks');
|
||||
|
||||
const {
|
||||
NODE_PERFORMANCE_GC_MINOR_MARK_SWEEP
|
||||
} = constants;
|
||||
|
||||
let observed = false;
|
||||
const obs = new PerformanceObserver(common.mustCallAtLeast((list) => {
|
||||
for (const entry of list.getEntries()) {
|
||||
// Other GC kinds (e.g. a scheduled or incremental GC) may be observed in
|
||||
// between; only the minor mark-sweep entry is relevant here.
|
||||
if (entry.detail.kind === NODE_PERFORMANCE_GC_MINOR_MARK_SWEEP) {
|
||||
assert.strictEqual(entry.name, 'gc');
|
||||
assert.strictEqual(entry.entryType, 'gc');
|
||||
observed = true;
|
||||
obs.disconnect();
|
||||
return;
|
||||
}
|
||||
}
|
||||
}));
|
||||
obs.observe({ entryTypes: ['gc'] });
|
||||
|
||||
gcUntil('minor gc event', () => observed, 10, { type: 'minor' });
|
||||
@@ -11,6 +11,7 @@ const {
|
||||
const {
|
||||
NODE_PERFORMANCE_GC_MAJOR,
|
||||
NODE_PERFORMANCE_GC_MINOR,
|
||||
NODE_PERFORMANCE_GC_MINOR_MARK_SWEEP,
|
||||
NODE_PERFORMANCE_GC_INCREMENTAL,
|
||||
NODE_PERFORMANCE_GC_WEAKCB,
|
||||
NODE_PERFORMANCE_GC_FLAGS_FORCED
|
||||
@@ -19,6 +20,7 @@ const {
|
||||
const kinds = [
|
||||
NODE_PERFORMANCE_GC_MAJOR,
|
||||
NODE_PERFORMANCE_GC_MINOR,
|
||||
NODE_PERFORMANCE_GC_MINOR_MARK_SWEEP,
|
||||
NODE_PERFORMANCE_GC_INCREMENTAL,
|
||||
NODE_PERFORMANCE_GC_WEAKCB,
|
||||
];
|
||||
|
||||
Reference in new issue
Block a user