5.2.0 • Published 1 month ago

@datadog/pprof v5.2.0

Weekly downloads
-
License
Apache-2.0
Repository
github
Last release
1 month ago

pprof support for Node.js

NPM Version Build Status Known Vulnerabilities

pprof support for Node.js.

Prerequisites

  1. Your application will need to be using Node.js 14 or greater.

  2. 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. For Linux: pprof has prebuilt binaries available for Linux arm64/x64, Alpine Linux x64, macOS arm64/x64, windows x64 for Node 14/16/18/20. 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.

  3. 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:

  1. Update code to collect and save a profile:

    const profile = await pprof.time.profile({
      durationMillis: 10000,    // time in milliseconds for which to 
                                // collect profile.
    });
    const buf = await pprof.encode(profile);
    fs.writeFile('wall.pb.gz', buf, (err) => {
      if (err) throw err;
    });
  2. View the profile with command line pprof:

    pprof -http=: wall.pb.gz

Requiring from the command line

  1. Start program from the command line:

    node --require @datadog/pprof app.js
  2. A wall time profile for the job will be saved in pprof-profile-${process.pid}.pb.gz. View the profile with command line pprof:

    ```bash
    pprof -http=: pprof-profile-${process.pid}.pb.gz
    ```

Collect a Heap Profile

  1. Enable heap profiling at the start of the application:

    // The average number of bytes between samples.
    const intervalBytes = 512 * 1024;
    
    // The maximum stack depth for samples collected.
    const stackDepth = 64;
    
    heap.start(intervalBytes, stackDepth); 
  2. Collect heap profiles:

    • Collecting and saving a profile in profile.proto format:

      const profile = await pprof.heap.profile();
      const buf = await pprof.encode(profile);
      fs.writeFile('heap.pb.gz', buf, (err) => {
        if (err) throw err;
      })
    • View the profile with command line pprof.

      pprof -http=: heap.pb.gz
    • Collecting a heap profile with V8 allocation profile format:

        const profile = await pprof.heap.v8Profile();
5.2.0

1 month ago

5.1.0

2 months ago

6.0.0-pre-2dd149e

2 months ago

6.0.0-pre-391b56d

3 months ago

6.0.0-pre-7d7500a

4 months ago

6.0.0-pre-3ad27c6

4 months ago

5.0.0

4 months ago

5.0.0-pre-d624748

4 months ago

5.0.0-pre-56cf286

5 months ago

4.1.0

5 months ago

4.0.0-pre-b439913

10 months ago

4.0.0-pre-ff50bca

9 months ago

5.0.0-pre-236fbc9

6 months ago

3.2.0

9 months ago

4.0.0-pre-2f3b78c

7 months ago

3.0.0

10 months ago

4.0.0-pre-d444c12

9 months ago

4.0.1

7 months ago

4.0.0

8 months ago

5.0.0-pre-39c03d4

6 months ago

4.0.0-pre-68b0b7b

10 months ago

4.0.0-pre-05c5dd4

8 months ago

3.1.0

10 months ago

4.0.0-pre-70d3943

7 months ago

2.2.3

11 months ago

3.0.0-pre-19d5e87

11 months ago

3.0.0-pre-a35f774

11 months ago

3.0.0-pre-8a3ca6b

11 months ago

2.2.1

1 year ago

2.2.0

1 year ago

2.2.2

11 months ago

3.0.0-pre-60585ba

11 months ago

3.0.0-pre-10eb724

11 months ago

3.0.0-pre-b1bc08a

11 months ago

2.1.0

1 year ago

2.0.0-pre

1 year ago

2.0.0

1 year ago

1.1.1

2 years ago

1.1.0

2 years ago

1.0.3

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago

0.5.0

2 years ago

0.5.1

2 years ago

0.4.0

2 years ago

0.3.0

3 years ago

0.2.1

3 years ago

0.2.0

3 years ago

0.1.3

3 years ago

0.1.2

3 years ago

0.1.1

3 years ago

0.1.0

3 years ago