Access the V8 profiler from node.js


Access the V8 profiler from node.js -

This module is effectively deprecated. Newer versions of V8 have removed much of the functionality that node-profiler depends on. As a result, it's become much less effective.

Consider using strong-agent if you want on-demand CPU profiling.

This module is for people who need fine-grained run-time control over the V8 profiler. You don't need it if all you want is wholesale profiling, simply start node with profiling enabled:

node --prof application.js

Read on, however, if you want to wield the arcane powers this module grants.

Easy as pie. To build from source:

node-gyp configure build install

Or, if you have npm installed:

npm install profiler

In most cases you will want to start your application with the profiler in suspended animation.

node --prof --prof_lazy --log application.js

And inside your application:

var profiler = require('profiler');
// <here be code you don't want to profile>
// <performance critical code here>

This results in a v8.log being written to the current directory that you can process with the bundled nprof tool. Run sh tools/build-nprof to build it.

You will sometimes want to run the garbage collector before profiling a performance critical section of code. Here is how you do it:

$ cat application.js
if (typeof gc === 'function') gc();
// ...
$ node --prof --prof_lazy --log --expose-gc application.js