-
Notifications
You must be signed in to change notification settings - Fork 243
Importing from Node.js
There are two ways to import profiles from Node.js: using the Chrome inspector, and using node --prof
. The Chrome inspector strategy can also be used to import heap snapshots.
Node now has built-in support to be inspected using Chrome. This article by Paul Irish has more details.
Run your program with --inspect
. For example, this is how you'd profile a build of parcel
node --inspect node_modules/.bin/parcel assets/index.html
Now visit chrome://inspect
, and you should see something like this:
Click the "inspect" link. This should open a developer tools window.
Click the start button to start recording a profile.
Now force the node behavior you're trying to profile (e.g. by loading the webpage it serves). When you're done, click the stop button.
Click on "save" to save the recorded profile. Save it with the default .cpuprofile
file extension.
You should be able to open that file in https://www.speedscope.app/.
To view it offline, you'll need to install speedscope via npm
:
npm install -g speedscope
Then you should be able to open it like so:
speedscope /path/to/profile.json
Like the CPU Profiling, you can use the Chrome Inspector to record a heap allocation profile. First, launch your process with the --inspect
flag. Next, go the Memory
section and select the "Allocation sampling" option.
Click the start button to start recording a profile.
Now, use the application for a while, then click the Stop
button.
Click "save" to save the recorded profile. Save it with the default .heapprofile
file extension.
You should be able to open that file in https://www.speedscope.app/.
To view it offline, you'll need to install speedscope via npm
:
npm install -g speedscope
Then you should be able to open it like so:
speedscope /path/to/profile.heapprofile
If you record profiling information like so:
node --prof /path/to/my/script.js
Then this will generate one or more isolate*.log
files. You can
convert these files into a file that can be imported into speedscope
like so:
node --prof-process --preprocess -j isolate*.log > profile.v8log.json
You should be able to open that file in https://www.speedscope.app/.
To view it offline, you'll need to install speedscope via npm
:
npm install -g speedscope
Then you should be able to open it like so:
speedscope /path/to/profile.v8log.json
You can also pipe the output of node --prof-process
directly to speedscope with a trailing -
like so:
node --prof-process --preprocess -j isolate*.log | speedscope -