21

I am looking for a method to do precise Node.JS profiling of script execution times on Linux.

There are interesting projects like the NodeTime.com Performance Profiler, but this profiles the timing of I/O httprequests and such, not execution time of lines of code.

I am looking for a way to figure out exactly where I can optimize my Javascript, where most of the time is spent, etc.


One interesting method I've seen is trying to create a FlameGraph using DTrace to profile Node.JS.

However, dtrace is very Solaris-specific.

  • For Linux (Debian/Ubuntu), dtrace can be found in the sytemtap-sdt-dev package. However, stap dtrace is not the same, and lacks all relevant hooks/probes.
  • Paul Fox made a port from the Unix version. It's more feature complete but somehow the hooks/probes don't work in userspace as the Solaris one, and also cannot be used to profile node.
    ftp://crisp.dyndns-server.com/pub/release/website/dtrace/ (It's pretty easy to build, see README.)
  • There's also an Oracle port, but noone would recommend it. Apparently, it only has about 0,1 percent of the probes the Paul Fox port. (Which is ironic, because Oracle was formerly Sun, original authors of dtrace for Solaris)

How, in Linux, using the terminal or using Eclipse, can I profile the code of my Node.JS scripts? I'm looking for something specific like the Zend Profiler shows execution times of each command in code of PHP scripts.

Redsandro
  • 11,060
  • 13
  • 76
  • 106

3 Answers3

8

"look" is a very good tool made by Vadim for profiling NodeJS app.

Take a look here:

https://github.com/baryshev/look

Bogdan Le
  • 2,216
  • 1
  • 20
  • 21
  • It appears "[look](https://github.com/baryshev/look)" is a _fork_ of [nodetime](http://nodetime.com/) negating the need to have it communicate profiling information to a 3rd party website. I haven't tried it yet, but this is potentially pretty cool. – Redsandro Jun 21 '13 at 17:03
  • 4
    I tried this but couldn't understand how to use it. It shows me "0.02% - channel.onread" (don't know what it is) and "99.98% - (program)", with no way to go into the "program" and see the time of specific routines. – Erel Segal-Halevi Mar 12 '14 at 19:00
7

If you're not against using nodetime, it actually does have CPU profiling:

See: http://nodetime.com/blog/cpu-profiling-with-nodetime

enter image description here

brianreavis
  • 11,562
  • 3
  • 43
  • 50
  • Nice, I missed that before. I prefer a flame graph style profiler, but I will try this until someone has a better idea. – Redsandro Oct 30 '12 at 20:30
1

https://www.npmjs.org/package/node.profiler Exactly what you need... It runs your project in monitor mode and it generates a chart after you are done with details on functions, each how many times it was called and the time it spent there.

Ralph
  • 1,480
  • 11
  • 16