Skip to content

Instantly share code, notes, and snippets.

@sgrodzicki
Created September 22, 2025 06:36
Show Gist options
  • Select an option

  • Save sgrodzicki/f51992ed99218a20f3c9793099cc0a75 to your computer and use it in GitHub Desktop.

Select an option

Save sgrodzicki/f51992ed99218a20f3c9793099cc0a75 to your computer and use it in GitHub Desktop.
How to capture a CPU profile in Node.js
# Copy of https://daniellockyer.com/how-to-capture-a-cpu-profile-in-nodejs/
# Find the process ID of the Node program
ps -H aux
# Enter the Node inspector
node inspect -p <pid>
# Start profiling:
profile
# Wait until you've captured enough of a timeframe
# Stop profiling:
profileEnd
# Save the profile:
profiles[0].save(filepath = 'node.cpuprofile')
# Exit the Node inspector:
Ctrl-d
# curl the file to flamegraphs.com (my service):
curl -F 'file=@node.cpuprofile' https://flamegraphs.com/collect
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment