@@ -1788,23 +1788,92 @@ const profile = handle.stop();
17881788console .log (profile);
17891789` ` `
17901790
1791- ## ` v8 .startHeapProfile () `
1791+ ## ` v8 .heapProfilerConstants `
17921792
17931793<!-- YAML
17941794added: REPLACEME
17951795-->
17961796
1797+ * {Object}
1798+
1799+ A frozen object containing constants used with [` v8 .startHeapProfile ()` ][].
1800+
1801+ The following constants are available:
1802+
1803+ | Constant | Description |
1804+ | ------------------------------------------------ | --------------------------------------------------- |
1805+ | ` SAMPLING_NO_FLAGS ` | No flags. |
1806+ | ` SAMPLING_FORCE_GC ` | Force garbage collection before taking the profile. |
1807+ | ` SAMPLING_INCLUDE_OBJECTS_COLLECTED_BY_MAJOR_GC ` | Include objects collected by major GC. |
1808+ | ` SAMPLING_INCLUDE_OBJECTS_COLLECTED_BY_MINOR_GC ` | Include objects collected by minor GC. |
1809+
1810+ These constants can be combined using bitwise OR to pass as the ` flags`
1811+ parameter.
1812+
1813+ ## ` v8 .startHeapProfile ([sampleInterval[, stackDepth[, flags]]])`
1814+
1815+ <!-- YAML
1816+ added: REPLACEME
1817+ -->
1818+
1819+ * ` sampleInterval` {number} The average sampling interval in bytes.
1820+ **Default:** ` 524288 ` (512 KiB).
1821+ * ` stackDepth` {integer} The maximum stack depth for samples.
1822+ **Default:** ` 16 ` .
1823+ * ` flags` {integer} Flags to control sampling behavior. Use constants from
1824+ [` v8 .heapProfilerConstants ` ][]. Multiple flags can be combined with bitwise
1825+ OR. **Default:** ` v8 .heapProfilerConstants .SAMPLING_NO_FLAGS ` .
17971826* Returns: {SyncHeapProfileHandle}
17981827
17991828Starting a heap profile then return a ` SyncHeapProfileHandle` object.
18001829This API supports ` using` syntax.
18011830
18021831` ` ` cjs
1832+ const v8 = require (' node:v8' );
1833+
18031834const handle = v8 .startHeapProfile ();
18041835const profile = handle .stop ();
18051836console .log (profile);
18061837` ` `
18071838
1839+ ` ` ` mjs
1840+ import v8 from ' node:v8' ;
1841+
1842+ const handle = v8 .startHeapProfile ();
1843+ const profile = handle .stop ();
1844+ console .log (profile);
1845+ ` ` `
1846+
1847+ With custom parameters:
1848+
1849+ ` ` ` cjs
1850+ const v8 = require (' node:v8' );
1851+ const { heapProfilerConstants } = v8;
1852+
1853+ const handle = v8 .startHeapProfile (
1854+ 1024 ,
1855+ 8 ,
1856+ heapProfilerConstants .SAMPLING_FORCE_GC |
1857+ heapProfilerConstants .SAMPLING_INCLUDE_OBJECTS_COLLECTED_BY_MAJOR_GC ,
1858+ );
1859+ const profile = handle .stop ();
1860+ console .log (profile);
1861+ ` ` `
1862+
1863+ ` ` ` mjs
1864+ import v8 from ' node:v8' ;
1865+ const { heapProfilerConstants } = v8;
1866+
1867+ const handle = v8 .startHeapProfile (
1868+ 1024 ,
1869+ 8 ,
1870+ heapProfilerConstants .SAMPLING_FORCE_GC |
1871+ heapProfilerConstants .SAMPLING_INCLUDE_OBJECTS_COLLECTED_BY_MAJOR_GC ,
1872+ );
1873+ const profile = handle .stop ();
1874+ console .log (profile);
1875+ ` ` `
1876+
18081877[CppHeap]: https://v8docs.nodesource.com/node-22.4/d9/dc4/classv8_1_1_cpp_heap.html
18091878[HTML structured clone algorithm]: https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm
18101879[Hook Callbacks]: #hook-callbacks
@@ -1839,6 +1908,8 @@ console.log(profile);
18391908[` serializer .transferArrayBuffer ()` ]: #serializertransferarraybufferid-arraybuffer
18401909[` serializer .writeRawBytes ()` ]: #serializerwriterawbytesbuffer
18411910[` settled` callback]: #settledpromise
1911+ [` v8 .heapProfilerConstants ` ]: #v8heapprofilerconstants
1912+ [` v8 .startHeapProfile ()` ]: #v8startheapprofilesampleinterval-stackdepth-flags
18421913[` v8 .stopCoverage ()` ]: #v8stopcoverage
18431914[` v8 .takeCoverage ()` ]: #v8takecoverage
18441915[` vm .Script ` ]: vm.md#new-vmscriptcode-options
0 commit comments