Code Monkey home page Code Monkey logo

v8-profiler's Introduction

Build Status Build status npm version

v8-profiler provides node bindings for the v8 profiler and integration with node-inspector

Installation

npm install v8-profiler

Usage

var profiler = require('v8-profiler');

API

takeSnapshot([name]) - returns new HEAP Snapshot instance. name is optional argument, by default snapshot name will be constructed from his uid.

deleteAllSnapshots() - works as described in name.

var snapshot1 = profiler.takeSnapshot('1');
var snapshot2 = profiler.takeSnapshot();
profiler.deleteAllSnapshots();

startProfiling([name], [recsamples]) - start CPU profiling. name is optional argument, by default profile name will be constructed from his uid. recsamples is true by default.

stopProfiling([name]) - returns new CPU Profile instance. There is no strictly described behavior for usage without name argument.

setSamplingInterval([num]) - Changes default CPU profiler sampling interval to the specified number of microseconds. Default interval is 1000us. This method must be called when there are no profiles being recorded. If called without arguments it resets interval to default.

deleteAllProfiles() - works as described in name.

profiler.startProfiling('', true);
setTimeout(function() {
  var profile = profiler.stopProfiling('');
  profiler.deleteAllProfiles();
}, 1000);

HEAP Snapshot API

Snapshot.getHeader() - provides short information about snapshot.

Snapshot.compare(snapshot) - creates HEAP diff for two snapshots.

Snapshot.delete() - removes snapshot from memory.

Snapshot.export([callback]) - provides simple export API for snapshot. callback(error, data) receives serialized snapshot as second argument. (Serialization is not equal to JSON.stringify result).

If callback will not be passed, export returns transform stream.

Snapshot.serialize - low level serialization method. Look Snapshot.export source for usage example.

var fs = require('fs');
var profiler = require('v8-profiler');
var snapshot1 = profiler.takeSnapshot();
var snapshot2 = profiler.takeSnapshot();

console.log(snapshot1.getHeader(), snapshot2.getHeader());

console.log(snapshot1.compare(snapshot2));

// Export snapshot to file file
snapshot1.export(function(error, result) {
  fs.writeFileSync('snapshot1.json', result);
  snapshot1.delete();
});

// Export snapshot to file stream
snapshot2.export()
  .pipe(fs.createWriteStream('snapshot2.json'))
  .on('finish', snapshot2.delete);

CPU Profile API

Profile.getHeader() - provides short information about profile.

Profile.delete() - removes profile from memory.

Profile.export([callback]) - provides simple export API for profile. callback(error, data) receives serialized profile as second argument. (Serialization is equal to JSON.stringify result).

var fs = require('fs');
var profiler = require('v8-profiler');
profiler.startProfiling('1', true);
var profile1 = profiler.stopProfiling();
profiler.startProfiling('2', true);
var profile2 = profiler.stopProfiling();

console.log(snapshot1.getHeader(), snapshot2.getHeader());

profile1.export(function(error, result) {
  fs.writeFileSync('profile1.json', result);
  profile1.delete();
});

profile2.export()
  .pipe(fs.createWriteStream('profile2.json'))
  .on('finish', function() {
    profile2.delete();
  });

node-inspector

Cpu profiles can be viewed and heap snapshots may be taken and viewed from the profiles panel.

v8-profiler's People

Contributors

3y3 avatar arunoda avatar bajtos avatar bnoordhuis avatar c4milo avatar dannycoates avatar hustxiaoc avatar jimthedev avatar mutantcornholio avatar ofrobots avatar rvagg avatar sebdeckers avatar smikes avatar thlorenz avatar yorkie avatar

Stargazers

 avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.