Profilejs: V8 profiling for Express framework
I’ve started using Danny Coates’ node-inspector recently. It works very well as a graphical debugger (runs in a webkit browser), and it can also serve as a profiler in conjunction with v8-profiler.
I wanted a tool that would profile all requests for me, so I could browse and pick through the logs afterwards, but I couldn’t find one. So I decided to write a middleware for Express that would pipe all requests throug the v8-profiler. The result is Profilejs.
Currently at version 0.0.2, Profilejs is still immature and probably buggy, and most certainly underfeatured. But the good news is, it’s not meant to replace node-inspector, and it works very well with it (for now).
I won’t detail installation and usage here, as it’s documented on the Github page.
Installation is fairly simple:
npm install profilejs
It will pull in v8-profiler as dependency, though, so be aware of that.
Typical usage involves setting up the middleware, and starting the profiler:
var profilejs = require('profilejs');
app.use(profilejs.profiler);
profilejs.start();
You can start either in silent mode or without the silent mode. The difference is you get a lot less noise in standard output in silent mode. Default is to run in extremely loud mode.

Each request results in a single profile. However, profiles are all named by the request URL that resulted in a call to the profiled handler. If the same URL gets hit multiple times, it will add runs to the profile with the same name. So you’ll have 5 runs for the url ‘/foo’ if you make 5 requests to ‘/foo’. In node-inspector UI, you will see a single profile named ‘/foo’, and five subitems under it which show different data from each run.
Once your app is hooked up, you can sart it with the debug option:
node --debug app.js
Preferably, you will make a separate environment for your profiling needs, and run the app in that environment:
NODE_ENV=profiling node --debug app.js
Once your app is running, you can start the node-inspector:
node-inspector --profile
The --profile option enables profiling. Now, you can open your WebKit browser (I use Chromium), and direct it to 0.0.0.0:8080. Once there, you need to go over into the Profiles tab and enable them.
With profiles enabled, you can click the refresh icon in the bottom left corner, and your profiles will be loaded. There won’t be any profiles until you actually inteact with the application, though.

I hope this tool is useful to you. If you have any issues with this library, you can file a bug, or drop by the nodejs mailing list.




