On this page

    M

    v8.startHeapProfile

    History
    v8.startHeapProfile(options?): SyncHeapProfileHandle
    Attributes
    options:Object
    sampleInterval?:number
    The average sampling interval in bytes. Default: 524288 (512 KiB).
    stackDepth?:integer
    The maximum stack depth for samples. Default: 16.
    forceGC?:boolean
    Force garbage collection before taking the profile. Default: false.
    includeObjectsCollectedByMajorGC?:boolean
    Include objects collected by major GC. Default: false.
    includeObjectsCollectedByMinorGC?:boolean
    Include objects collected by minor GC. Default: false.

    Starting a heap profile then return a SyncHeapProfileHandle object. This API supports using syntax.

    const v8 = require('node:v8');
    
    const handle = v8.startHeapProfile();
    const profile = handle.stop();
    console.log(profile);
    import v8 from 'node:v8';
    
    const handle = v8.startHeapProfile();
    const profile = handle.stop();
    console.log(profile);

    With custom parameters:

    const v8 = require('node:v8');
    
    const handle = v8.startHeapProfile({
      sampleInterval: 1024,
      stackDepth: 8,
      forceGC: true,
      includeObjectsCollectedByMajorGC: true,
    });
    const profile = handle.stop();
    console.log(profile);
    import v8 from 'node:v8';
    
    const handle = v8.startHeapProfile({
      sampleInterval: 1024,
      stackDepth: 8,
      forceGC: true,
      includeObjectsCollectedByMajorGC: true,
    });
    const profile = handle.stop();
    console.log(profile);