@@ -40,8 +40,8 @@ const {
4040const { Buffer } = require ( 'buffer' ) ;
4141const {
4242 validateString,
43- validateUint32,
4443 validateOneOf,
44+ validateUint32,
4545} = require ( 'internal/validators' ) ;
4646const {
4747 Serializer,
@@ -50,6 +50,9 @@ const {
5050const {
5151 namespace : startupSnapshot ,
5252} = require ( 'internal/v8/startup_snapshot' ) ;
53+ const {
54+ normalizeHeapProfileOptions,
55+ } = require ( 'internal/v8/heap_profile' ) ;
5356
5457let profiler = { } ;
5558if ( internalBinding ( 'config' ) . hasInspector ) {
@@ -115,6 +118,8 @@ const {
115118 setFlagsFromString : _setFlagsFromString ,
116119 startCpuProfile : _startCpuProfile ,
117120 stopCpuProfile : _stopCpuProfile ,
121+ startHeapProfile : _startHeapProfile ,
122+ stopHeapProfile : _stopHeapProfile ,
118123 isStringOneByteRepresentation : _isStringOneByteRepresentation ,
119124 updateHeapStatisticsBuffer,
120125 updateHeapSpaceStatisticsBuffer,
@@ -191,6 +196,22 @@ class SyncCPUProfileHandle {
191196 }
192197}
193198
199+ class SyncHeapProfileHandle {
200+ #stopped = false ;
201+
202+ stop ( ) {
203+ if ( this . #stopped) {
204+ return ;
205+ }
206+ this . #stopped = true ;
207+ return _stopHeapProfile ( ) ;
208+ } ;
209+
210+ [ SymbolDispose ] ( ) {
211+ this . stop ( ) ;
212+ }
213+ }
214+
194215/**
195216 * Starting CPU Profile.
196217 * @returns {SyncCPUProfileHandle }
@@ -200,6 +221,23 @@ function startCpuProfile() {
200221 return new SyncCPUProfileHandle ( id ) ;
201222}
202223
224+ /**
225+ * Starting Heap Profile.
226+ * @param {object } [options]
227+ * @param {number } [options.sampleInterval]
228+ * @param {number } [options.stackDepth]
229+ * @param {boolean } [options.forceGC]
230+ * @param {boolean } [options.includeObjectsCollectedByMajorGC]
231+ * @param {boolean } [options.includeObjectsCollectedByMinorGC]
232+ * @returns {SyncHeapProfileHandle }
233+ */
234+ function startHeapProfile ( options ) {
235+ const { sampleInterval, stackDepth, flags } =
236+ normalizeHeapProfileOptions ( options ) ;
237+ _startHeapProfile ( sampleInterval , stackDepth , flags ) ;
238+ return new SyncHeapProfileHandle ( ) ;
239+ }
240+
203241/**
204242 * Return whether this string uses one byte as underlying representation or not.
205243 * @param {string } content
@@ -518,4 +556,5 @@ module.exports = {
518556 GCProfiler,
519557 isStringOneByteRepresentation,
520558 startCpuProfile,
559+ startHeapProfile,
521560} ;
0 commit comments