You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Your application will need to be using Node.js 18 or greater.
The pprof module has a native component that is used to collect profiles
with v8's CPU and Heap profilers. You may need to install additional
dependencies to build this module.
pprof has prebuilt binaries available for Linux arm64/x64,
Alpine Linux x64, macOS arm64/x64, and Windows x64 for Node 18/20/22/24.
No additional dependencies are required.
For other environments: on environments that pprof does not have
prebuilt binaries for, the module
node-gyp will be used to
build binaries. See node-gyp's
documentation
for information on dependencies required to build binaries with node-gyp.
The pprof CLI can be used to view profiles collected with
this module. Instructions for installing the pprof CLI can be found
here.
Basic Set-up
Install pprof with npm or add to your package.json.
# Install through npm while saving to the local 'package.json'
npm install --save @datadog/pprof
Using the Profiler
Collect a Wall Time Profile
In code:
Update code to collect and save a profile:
constprofile=awaitpprof.time.profile({durationMillis: 10000,// time in milliseconds for which to// collect profile.});constbuf=awaitpprof.encode(profile);fs.writeFile('wall.pb.gz',buf,(err)=>{if(err)throwerr;});
A wall time profile for the job will be saved in
pprof-profile-${process.pid}.pb.gz. View the profile with command line
pprof:
pprof -http=: pprof-profile-${process.pid}.pb.gz
Collect a Heap Profile
Enable heap profiling at the start of the application:
// The average number of bytes between samples.constintervalBytes=512*1024;// The maximum stack depth for samples collected.conststackDepth=64;heap.start(intervalBytes,stackDepth);
Collect heap profiles:
Collecting and saving a profile in profile.proto format: