node package manager


Minimal profiling library.


Profiles is a simple way to profile different parts of your app.


npm install profiles


Note, These API's will change


var profiles = require('profiles')()
var end = profiles.beg('test1')
//do something that will take some time
end() //returns the time from beg to the time end was invoked


You can also create stats about certain parts of your app using the profiler.stat(name, value) API. If you want to stat how many request per second your server is handling, you can do the following (this ties in nicely with ProfilesStream):

var reqPerSec = 0
function serve(req, res) {
  reqPerSec +=1
  res.setHeader('content-type', 'text/plain')
  res.end('request per sec #' + reqPerSec)
setInterval(function() {
  profiler.stat('perSec', reqPerSec)
  reqPerSec = 0
}, 1000)


Profiles is also an instance of EventEmitter so you can listen to the profile event which takes a listener function:

 profiles.on('profile', function(profileName, value, profileType, uid) {})
  * profileName will be the name of the stat or time
  * value is the 'time' it took  before the end() function was invoked or the 'stat' value when you call stat()
  * profileType will be the type of profile you invoked, so: 'stat' or 'time'
  * uid is a unique ID, currently this is just


You can also wrap your profiler in a readable stream:

var profiles = require('profiles')
  , profiler = profiles()
  , pStream = new profiles.PS(profiler)
  // OR:  pStream = new profiles.ProfilesStream(profiler)


ProfilesStream just listens in on the "profile" event and emits \n delimited JSON string Buffer objects that have the following format:

{'name' : nameOfStatOrTime, 'val': itsValue, '__profileType' : 'time' OR 'stat', __uid : ID }
MIT License