Daniel Lockyer

Daniel Lockyer

I help teams fix high CPU, memory leaks, slow APIs, and rising cloud bills - without rewriting everything.

Contact me

How to capture a CPU profile in Node.js

# 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 debugproduction.com (my service):
curl -F 'file=@node.cpuprofile' https://debugproduction.com/collect