Fork me on GitHub

Puncher

Build Status

Library to collect timing data for your node.js application. Simplifies bottlenecks search.

  1. Easy interface.
  2. Nesting support with coverage info.

See API documentation and example.

Usage overview

// require Puncher library
var Puncher = require('puncher');


// start profiler
var p = new Puncher();


p.start('Total');
setTimeout(function () {

  p.start('Block 1');
  setTimeout(function () {
    p.stop(); // Stop Block 1

    p.start('Block 2');
    setTimeout(function () {
      p.stop(); // Stop Block 2

      p.stop(); // Stop Total
      console.log(require('util').inspect(p.result, false, 10, true));
    }, 300);
  }, 200);
}, 100);

Example above will show you something like this:

[ { message: 'Total',
    start: 1342643670524,
    stop: 1342643671130,
    elapsed: { total: 606, missed: 105 },
    meta: {},
    childs: 
     [ { message: 'Block 1',
         start: 1342643670629,
         stop: 1342643670829,
         elapsed: { total: 200, missed: 0 },
         meta: {},
         childs: [] },
       { message: 'Block 2',
         start: 1342643670829,
         stop: 1342643671130,
         elapsed: { total: 301, missed: 0 },
         meta: {},
         childs: [] } ] } ]
class

Puncher

Description

Provides easy way to profile complex workflows.

Constructor

Instance methods

Instance properties

constructor

Puncher.new

    • new Puncher()

Creates new instance of the Puncher

instance method

Puncher#start

    • Puncher#start(message[, meta = {}])
    • message
      • String
    • Scope description

    • meta
      • Object
    • Additional information. You can put any info here.

Starts new scope of timestamps.

Example
puncher.start('Iterate values', {count: arr.length});
arr.forEach(function (el) {
  puncher.start('Store element in database', {el: el});
  db.save(el, function (err) {
    puncher.stop();

    // ...
  });
});
puncher.stop();
instance method

Puncher#stop

    • Puncher#stop([all = false][, meta = {}])
    • all
      • Boolean
    • Stop all started scopes if true.

    • meta
      • Object
    • Add more additional information.

Closes previously started scope.

See Also:
instance property

Puncher#result

    • Puncher#result
      • Array

Returns profiling result, with following structure:

[
  {
    "message":  "Foo",
    "start":    1342641419901,
    "stop":     1342641420102,
    "elapsed":  {"total": 201, "missed": 100},
    "meta":     {},
    "childs":   [
      {
        "message":  "Bar",
        "start":    1342641420001,
        // ...
      },
      // ...
    ]
  },
  // ...
]
instance property

Puncher#stopped

    • Puncher#stopped
      • Boolean

Tells if all started scopes were stopped.