GitHub - jakebailey/pprof-it: A handy pprof wrapper for Node.js (original) (raw)

pprof-it

pprof-it is a convenient wrapper to pprof that makes it easy to capture CPU and memory profiles of node programs.

(Technically, pprof-it usesDataDog's fork of pprof-node, as it supports newer versions of node and includes prebuilds for many more platforms.)

Usage

To use pprof-it, use pprof-it in place of node:

$ npx pprof-it path/to/script.js

Or, ensure node is run with --require=pprof-it:

Directly running with node

$ node --require pprof-it path/to/script.js

Executables via npm/npx (v7+)

$ npx --node-option="--require pprof-it" $ npm exec --node-option="--require pprof-it"

Executables via npm/npx (v6)

$ npx --node-arg="--require pprof-it"

Executables via yarn (usually)

$ node --require pprof-it $(yarn bin )

The NODE_OPTIONS environment variable may be used to pass --require, but is not recommended as more than one process may emit profiles.

By default, pprof-it will produce both heap and time profiles and write them to the current directory.

To view the profiles, you can use SpeedScope for a quick and easy view, or use thepprof utility for more info, like:

CLI interface

$ go run github.com/google/pprof@latest pprof-time-10503.pb.gz

Browser interface

$ go run github.com/google/pprof@latest -http=: pprof-time-10503.pb.gz

Options

pprof-it's behavior can be configured via the following environment variables.

On Windows, where setting environment variables temporarily is less convenient, it's simplest to just use cross-env to handle this:

$ npx cross-env PPROF_OUT=C:\foo\bar node --require pprof-it path\to\script.js