GithubHelp home page GithubHelp logo

hhy5277 / node-heapdump Goto Github PK

View Code? Open in Web Editor NEW

This project forked from bnoordhuis/node-heapdump

0.0 1.0 0.0 78 KB

Make a dump of the V8 heap for later inspection.

License: Other

Python 6.66% JavaScript 50.29% C++ 35.38% C 7.68%

node-heapdump's Introduction

node-heapdump

Make a dump of the V8 heap for later inspection.

Install

npm install heapdump

Or, if you are running node.js v0.6 or v0.8:

npm install [email protected]

Build

node-gyp configure build

Usage

Load the add-on in your application:

var heapdump = require('heapdump');

The module exports a single writeSnapshot([filename], [callback]) function that writes out a snapshot. filename defaults to heapdump-<sec>.<usec>.heapsnapshot when omitted.

heapdump.writeSnapshot('/var/local/' + Date.now() + '.heapsnapshot');

The function also takes an optional callback function which is called upon completion of the heap dump.

heapdump.writeSnapshot(function(err, filename) {
  console.log('dump written to', filename);
});

The snapshot is written synchronously to disk. When the JS heap is large, it may introduce a noticeable "hitch".

On UNIX platforms, you can force a snapshot by sending the node.js process a SIGUSR2 signal:

$ kill -USR2 <pid>

The SIGUSR2 signal handler is enabled by default but you can disable it by setting NODE_HEAPDUMP_OPTIONS=nosignal in the environment:

$ env NODE_HEAPDUMP_OPTIONS=nosignal node script.js

Inspecting the snapshot

Open Google Chrome and press F12 to open the developer toolbar.

Go to the Memory tab, right-click in the tab pane and select Load profile....

Select the dump file and click Open. You can now inspect the heap snapshot at your leisure. Some snapshots may take a long time to load, on the order of minutes or even hours.

Note that Chrome will refuse to load the file unless it has the .heapsnapshot extension.

Caveats

On UNIX systems, the rule of thumb for creating a heap snapshot is that it requires memory twice the size of the heap at the time of the snapshot. If you end up with empty or truncated snapshot files, check the output of dmesg; you may have had a run-in with the system's OOM killer or a resource limit enforcing policy, like ulimit -u (max user processes) or ulimit -v (max virtual memory size).

node-heapdump's People

Contributors

bnoordhuis avatar kraman avatar runk avatar waldyrious avatar

Watchers

 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.