npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@risingstack/v8-profiler

v5.7.11

Published

node bindings for the v8 profiler

Downloads

446

Readme

Build Status

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.