Skip to content
Go to file

Latest commit


Git stats


Failed to load latest commit information.
Latest commit message
Commit time

A fork of Istanbul for performance analysis.

This fork aims to give a command that will output how many milliseconds each of your functions are called, and how many times.

It outputs data in JSON format.

Your code needs to be preprocessed by a tool (much like what babel does when converting es6 to es5).

Here's an example of how to use it in a script

# Compile each js file found in the js folder
find ./js -name '*.js' | while IFS='' read -r filename || [[ -n "$filename" ]]; do
	echo "$filename"
	echo "${filename/js/prof}"
	mkdir -p "$(dirname "${filename/js/prof}")"
	profi-stanbul profile --output "${filename/js/prof}" "${filename}"

# run the tests using the prof/tests/docxtemplater.js instead of the
mocha prof/tests/docxtemplater.js

# The file p.json is created, which you can open with your favorite editor

# You can also use the following script (which uses jq) to give you the functions called most of the time

jqq='. | to_entries | sort_by( | .[].value | .filename + "@" + .name + ":" + (.calls|tostring) + ":" + (.ms|tostring) + "ms"'

jq <p.json --raw-output "$jqq" |
sed "s:$(pwd)/prof/::g"

It only profiles correctly synchronous code, since it only looks at the time between the call and the function and the time when the function returns.

A profiling sample can be seeen in :

Below is the original readme of istanbul

Istanbul - a JS code coverage tool written in JS

Build Status Dependency Status



  • All-javascript instrumentation library that tracks statement, branch, and function coverage and reverse-engineers line coverage with 100% fidelity.
  • Module loader hooks to instrument code on the fly
  • Command line tools to run node unit tests "with coverage turned on" and no cooperation whatsoever from the test runner
  • HTML and LCOV reporting.
  • Ability to use as middleware when serving JS files that need to be tested on the browser.
  • Can be used on the command line as well as a library
  • Based on the awesome esprima parser and the equally awesome escodegen code generator
  • Well-tested on node 0.4.x, 0.6.x, 0.8.x and the browser (instrumentation library only)
  • profile option to instrument the code with profiling code that gives function level statistics


$ npm install -g istanbul

Getting started

The best way to see it in action is to run node unit tests. Say you have a test script test.js that runs all tests for your node project without coverage.


$ cd /path/to/your/source/root
$ istanbul cover test.js

and this should produce a coverage.json, and lcov-report/*html under ./coverage

Sample of code coverage reports produced by this tool (for this tool!):

Use cases

Supports the following use cases and more

  • transparent coverage of nodejs unit tests
  • ability to use in an npm test script for conditional coverage
  • instrumentation of files in batch mode for browser tests (using yeti for example)
  • Server side code coverage for nodejs by embedding it as custom middleware

Ignoring code for coverage

  • Skip an if or else path with /* istanbul ignore if */ or /* istanbul ignore else */ respectively.
  • For all other cases, skip the next 'thing' in the source with: /* istanbul ignore next */

See for the spec.

The command line

$ istanbul help

gives you detailed help on all commands.

Usage: istanbul help

Available commands are:

          checks overall coverage against thresholds from coverage JSON
          files. Exits 1 if thresholds are not met, 0 otherwise

  cover   transparently adds coverage information to a node command. Saves
          coverage.json and reports at the end of execution

  help    shows help

          instruments a file or a directory tree and writes the
          instrumented code to the desired output location

          instruments for profiling a file or a directory tree and writes
          the instrumented code to the desired output location

  report  writes reports for coverage JSON objects produced in a previous

  test    cover a node command only when npm_config_coverage is set. Use in
          an `npm test` script for conditional coverage

Command names can be abbreviated as long as the abbreviation is unambiguous

The cover command

$ istanbul cover my-test-script.js -- my test args
# note the -- between the command name and the arguments to be passed

The cover command can be used to get a coverage object and reports for any arbitrary node script. By default, coverage information is written under ./coverage - this can be changed using command-line options.

The test command

The test command has almost the same behavior as the cover command, except that it skips coverage unless the npm_config_coverage environment variable is set.

This helps you set up conditional coverage for tests. In this case you would have a package.json that looks as follows.

    "name": "my-awesome-lib",
    "version": "1.0",
    "script": {
        "test": "istanbul test my-test-file.js"


$ npm test # will run tests without coverage


$ npm test --coverage # will run tests with coverage

Note: This needs node 0.6 or better to work. npm for node 0.4.x does not support the --coverage flag.

The instrument command

Instruments a single JS file or an entire directory tree and produces an output directory tree with instrumented code. This should not be required for running node unit tests but is useful for tests to be run on the browser (using yeti for example).

The profile command

Instruments for profiling a single JS file or an entire directory tree and produces an output directory tree with instrumented code. The produced code can be run to do profiling The produced code needs to have in case of node.js a file called profile.js on the root of the project The produced code needs to have in case of browser, an object profile already defined The profile object needs two functions, profile.start and profile.end, the parameters are: functionName,filename,arguments

The report command

Writes reports using coverage*.json files as the source of coverage information. Reports are available in the following formats:

  • html - produces a bunch of HTML files with annotated source code
  • lcovonly - produces an file
  • lcov - produces html + lcov files. This is the default format
  • cobertura - produces a cobertura-coverage.xml file for easy Hudson integration
  • text-summary - produces a compact text summary of coverage, typically to console
  • text - produces a detailed text table with coverage for all files
  • teamcity - produces service messages to report code coverage to TeamCity

Additional report formats may be plugged in at the library level.

Library usage

All the features of istanbul can be accessed as a library using its public API


Changelog has been moved here.


istanbul is licensed under the BSD License.

Third-party libraries

The following third-party libraries are used by this module:

Inspired by

  • YUI test coverage - - the grand-daddy of JS coverage tools. Istanbul has been specifically designed to offer an alternative to this library with an easy migration path.
  • cover: - the inspiration for the cover command, modeled after the run command in that tool. The coverage methodology used by istanbul is quite different, however

Shout out to

  • mfncooper - for great brainstorming discussions
  • reid, davglass, the YUI dudes, for interesting conversations, encouragement, support and gentle pressure to get it done :)

Why the funky name?

Since all the good ones are taken. Comes from the loose association of ideas across coverage, carpet-area coverage, the country that makes good carpets and so on...


My personal profiling tool for node.js




No releases published


No packages published


You can’t perform that action at this time.