node package manager
Stop writing boring code. Discover, share, and reuse within your team. Create a free org ยป



Access the V8 profiler from node.js -

A word of advice

This module is for people who need run-time control over V8's profiler. If all you want is wholesale profiling, you don't need it. 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-waf 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 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 V8 profiling tools.

See for more information.

Advanced usage

By default, everything that can be profiled, is: heap and CPU usage, and JS object construction. This can be customized by passing a bitwise OR of the following flags to resume() and pause():



profiler.resume(profiler.CPU | profiler.JS_CONSTRUCTORS);
// <performance critical code here>
profiler.pause(profiler.CPU | profiler.JS_CONSTRUCTORS);

You can optionally pass a tag to uniquely mark a section in the v8.log:

profiler.resume(profiler.CPU, 42);
// <performance critical code here>
profiler.pause(profiler.CPU, 42);

You will sometimes want to run the garbage collector before profiling a performance critical section of code. No problem, we got your back!

profiler.resume(profiler.CPU | profiler.HEAP_STATS);