Reputation: 1555
I'm familiar with Node's build in CPU profiler:
NODE_ENV=production node --prof server.js
... but can the profiler be attached to a running process.
The problem I need to solve is that there is a lot of heavy lifting during start up on our IoT Gateway and I want to profile the CPU only AFTER the heavy lifting during steady state, so I want to attach it to the running process rather than monitor from start up as it will totally mis-represent my steady-state.
I am aware you can do this with the debugger, but I need to do it for the profiler.
Upvotes: 3
Views: 1693
Reputation: 8008
You can use remote inspector
NODE_ENV=production node --inspect-brk server.js
Now, go in chrome to chrome://inspect
and launch NodeJS Inspector and resume the application
Profiler
tab. console.profile()
and console.profileEnd()
If you want to inspect remote server:
NODE_ENV=production node --inspect=0.0.0.0:9229 server.js
chrome://inspect
click Configure
new Discover network targets
and add the IP address and 9229
port of your server. Refersh the page, and then you will see your remote server to inspect.Make sure to open the 9229
port on remote server firewall. If you can access only 22
(ssh) then try to open ssh-tunel: ssh -L 9229:127.0.0.1:9229 some@myserver -N
. Then you can start the server only with --inspect
flag, without ip-binding.
Upvotes: 4