# gc-stats

> Exposes node v8 garbage collection stats

Latest version **1.4.1** (published 2024-02-18) · Unlicense license · 0 weekly downloads

> **Deprecated.** This package is deprecated.

## Install

```sh
npm install gc-stats
pnpm add gc-stats
yarn add gc-stats
bun add gc-stats
```

## Health

**Score 10/100 (F)** — status: deprecated.

Negative: deprecated.

## Facts

| | |
|---|---|
| Version | 1.4.1 |
| Published | 2024-02-18 |
| First published | 2013-08-24 |
| Weekly downloads | 0 |
| License | Unlicense |
| TypeScript types | separate (@types/gc-stats) |
| Module format | CommonJS |
| Node | >=16 |
| Dependencies | 2 |
| Unpacked size | 16.1 KB |
| Known vulnerabilities | 0 |
| Install scripts | yes |
| GitHub stars | 155 |
| Maintainers | dainis |

## Links

- npm: https://www.npmjs.com/package/gc-stats
- Repository: https://github.com/dainis/node-gcstats
- Homepage: https://github.com/dainis/node-gcstats#readme
- Issues: https://github.com/dainis/node-gcstats/issues
- npm.io page: https://npm.io/package/gc-stats

## Dependencies (2)

- [nan](https://npm.io/package/nan.md) ^2.18.0
- [node-gyp-build](https://npm.io/package/node-gyp-build.md) ^4.8.0

## Recent versions

- 1.4.1 (latest) — 2024-02-18
- 1.4.1-0 (next) — 2024-02-18
- 1.4.0 — 2019-05-30
- 1.3.0 — 2019-05-04
- 1.2.1 — 2018-11-20
- 1.2.0 — 2018-06-05
- 1.1.1 — 2018-03-23
- 1.1.0 — 2017-12-05
- 1.0.2 — 2017-06-22
- 1.0.1 — 2017-06-19
- 1.0.0 — 2015-10-28
- 0.0.6 — 2015-08-16
- 0.0.5 — 2015-05-04
- 0.0.4 — 2015-04-30
- 0.0.3 — 2015-03-14
- … 2 more at https://npm.io/package/gc-stats/versions

## README

# GCStats
[![Build Status](https://travis-ci.org/dainis/node-gcstats.svg?branch=master)](https://travis-ci.org/dainis/node-gcstats) [![Build status](https://ci.appveyor.com/api/projects/status/oeu171tgxbsac88q/branch/master?svg=true)](https://ci.appveyor.com/project/dainis/node-gcstats/branch/master)

Exposes stats about V8 GC after it has been executed.

# Usage

Create a new instance of the module and subscribe to `stats`-events from that:

    var gc = (require('gc-stats'))();

    gc.on('stats', function (stats) {
        console.log('GC happened', stats);
    });

This will print blobs like this whenever a GC happened:

    GC happened {
      startTime: 9426055813976,
      endTime: 9426057735390,
      pause: 1921414,
      pauseMS: 1,
      gctype: 1,
      before: {
         totalHeapSize: 11354112,
         totalHeapExecutableSize: 3670016,
         usedHeapSize: 7457184,
         heapSizeLimit: 1501560832,
         totalPhysicalSize: 9725880,
         totalAvailableSize: 1488434544,
         mallocedMemory: 8192,
         peakMallocedMemory: 1186040
      },
      after: {
         totalHeapSize: 12402688,
         totalHeapExecutableSize: 3670016,
         usedHeapSize: 6485792,
         heapSizeLimit: 1501560832,
         totalPhysicalSize: 10166144,
         totalAvailableSize: 1489388528,
         mallocedMemory: 8192,
         peakMallocedMemory: 1186040
      },
      diff: {
         totalHeapSize: 1048576,
         totalHeapExecutableSize: 0,
         usedHeapSize: -971392,
         heapSizeLimit: 0,
         totalPhysicalSize: 440264,
         totalAvailableSize: 953984,
         mallocedMemory: 0,
         peakMallocedMemory: 0
      }
    }

## Property insights
* totalHeapSize: Number of bytes V8 has allocated for the heap. This can grow if usedHeap needs more.
* usedHeapSize: Number of bytes in use by application data
* total HeapExecutableSize: Number of bytes for compiled bytecode and JITed code
* heapSizeLimit: The absolute limit the heap cannot exceed
* totalPhysicalSize: Committed size (node 0.11+)
* totalAvailableSize: Available heap size(node 4+)
* startTime: Nanoseconds for start, using hrtime()
* endTime: Nanoseconds for end, using hrtime()
* pause: Nanoseconds from start to end of GC using hrtime()
* pauseMS: pause expressed in milliseconds
* mallocedMemory
* peakMallocedMemory
* numberOfNativeContexts
* numberOfDetachedContexts
* gctype can have the following values([v8 source](https://github.com/nodejs/node/blob/554fa24916c5c6d052b51c5cee9556b76489b3f7/deps/v8/include/v8.h#L6137-L6144)):
  * 1: Scavenge (minor GC)
  * 2: Mark/Sweep/Compact (major GC)
  * 4: Incremental marking
  * 8: Weak/Phantom callback processing
  * 15: All

# Installation

    npm install gc-stats

# Node version support
node-gcstats depends on C++ extensions which are compiled when the *gc-stats* module is installed. Compatibility information can be inspected via the [Travis-CI build jobs](https://travis-ci.org/dainis/node-gcstats/).

---
_Source: https://npm.io/package/gc-stats · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
