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

gc-heap-stats

v1.0.0

Published

Emits detailed stats about V8 heap usage after each V8 garbage collector run

Downloads

9

Readme

gc-heap-stats

Build Status

Emits detailed stats about V8 heap usage after each V8 garbage collector run.

Install

npm install gc-heap-stats

Basic usage

var gcHeapStats = require('gc-heap-stats')();
gcHeapStats.on('stats', function (stats) {
    console.log(JSON.stringify(stats, null, 2));
});

Advanced usage

// init GC heap stats emitter as "deferred"
var gcHeapStats = require('gc-heap-stats')({deferred: true});
gcHeapStats.on('stats', function (stats) {
    console.log(JSON.stringify(stats, null, 2));
});

// no events will be emitted until you call
gcHeapStats.start();

// stop it
gcHeapStats.stop();

// ... start again, ... etc
gcHeapStats.start();

Sample output

Sample output in node.js >= 4.0 (there won't be spaces[] stats in older versions of node.js).

The output contains 3 sections: heap stats before garbage collector run was triggered, heap stats after garbage collector run and the diff (after - before).

Top level properties:

  • type: type of GC (can have one of the following values):
  • 1: Scavenge (minor GC)
  • 2: Mark/Sweep/Compact (major GC)
  • 4: Incremental marking
  • 8: Weak/Phantom callback processing
  • 15: All
  • took: milliseconds that GC run took

Section properties:

  • total_heap_size: Number of bytes V8 has allocated for the heap. This can grow if usedHeap needs more.
  • used_heap_size: Number of bytes in used by application data
  • total_heap_size_executable: Number of bytes for compiled bytecode and JITed code
  • heap_size_limit: The absolute limit the heap cannot exceed (default limit or --max_old_space_size)
  • total_physical_size: Committed size

Heap space properties:

  • space_name: Name of a heap space
  • space_size: Number of bytes allocated for a heap space
  • space_used_size: Number of bytes allocated (used) in a heap space
  • space_available_size: Number of bytes available in a heap space
  • physical_space_size: Committed size of a heap space
{
  "type": 1,
  "took": 1.102,
  "before": {
    "total_heap_size": 10522624,
    "total_heap_size_executable": 5242880,
    "total_physical_size": 10522624,
    "total_available_size": 1487252192,
    "used_heap_size": 4941096,
    "heap_size_limit": 1501560832,
    "spaces": [
      {
        "space_name": "new_space",
        "space_size": 4194304,
        "space_used_size": 1638368,
        "space_available_size": 424992,
        "physical_space_size": 4194304
      },
      {
        "space_name": "old_space",
        "space_size": 3100672,
        "space_used_size": 2499536,
        "space_available_size": 192,
        "physical_space_size": 3100672
      },
      {
        "space_name": "code_space",
        "space_size": 2097152,
        "space_used_size": 631328,
        "space_available_size": 0,
        "physical_space_size": 2097152
      },
      {
        "space_name": "map_space",
        "space_size": 1130496,
        "space_used_size": 171864,
        "space_available_size": 0,
        "physical_space_size": 1130496
      },
      {
        "space_name": "large_object_space",
        "space_size": 0,
        "space_used_size": 0,
        "space_available_size": 1486827008,
        "physical_space_size": 0
      }
    ]
  },
  "after": {
    "total_heap_size": 11571200,
    "total_heap_size_executable": 5242880,
    "total_physical_size": 11571200,
    "total_available_size": 1487833096,
    "used_heap_size": 3879584,
    "heap_size_limit": 1501560832,
    "spaces": [
      {
        "space_name": "new_space",
        "space_size": 4194304,
        "space_used_size": 8832,
        "space_available_size": 2054528,
        "physical_space_size": 4194304
      },
      {
        "space_name": "old_space",
        "space_size": 4149248,
        "space_used_size": 3067560,
        "space_available_size": 136,
        "physical_space_size": 4149248
      },
      {
        "space_name": "code_space",
        "space_size": 2097152,
        "space_used_size": 631328,
        "space_available_size": 0,
        "physical_space_size": 2097152
      },
      {
        "space_name": "map_space",
        "space_size": 1130496,
        "space_used_size": 171864,
        "space_available_size": 0,
        "physical_space_size": 1130496
      },
      {
        "space_name": "large_object_space",
        "space_size": 0,
        "space_used_size": 0,
        "space_available_size": 1485778432,
        "physical_space_size": 0
      }
    ]
  },
  "diff": {
    "total_heap_size": 1048576,
    "total_heap_size_executable": 0,
    "total_physical_size": 1048576,
    "total_available_size": 580904,
    "used_heap_size": -1061512,
    "heap_size_limit": 0,
    "spaces": [
      {
        "space_name": "new_space",
        "space_size": 0,
        "space_used_size": -1629536,
        "space_available_size": 1629536,
        "physical_space_size": 0
      },
      {
        "space_name": "old_space",
        "space_size": 1048576,
        "space_used_size": 568024,
        "space_available_size": -56,
        "physical_space_size": 1048576
      },
      {
        "space_name": "code_space",
        "space_size": 0,
        "space_used_size": 0,
        "space_available_size": 0,
        "physical_space_size": 0
      },
      {
        "space_name": "map_space",
        "space_size": 0,
        "space_used_size": 0,
        "space_available_size": 0,
        "physical_space_size": 0
      },
      {
        "space_name": "large_object_space",
        "space_size": 0,
        "space_used_size": 0,
        "space_available_size": -1048576,
        "physical_space_size": 0
      }
    ]
  }
}

Compatibility

gc-heap-stats is compatible with node.js >= 0.12 however the best results (including V8 heap spaces stats) you will get with node.js >= 4.0. Version 0.10 is not supported, for node.js 0.10 please use similar package: https://github.com/dainis/node-gcstats