Coder Social home page Coder Social logo

foresightimaging / v8-heapsnapshot Goto Github PK

View Code? Open in Web Editor NEW

This project forked from srtobi/v8-heapsnapshot

0.0 0.0 0.0 20 KB

An npm module to parse and work with heapsnapshots.

License: MIT License

Shell 11.42% TypeScript 78.62% Dockerfile 9.96%

v8-heapsnapshot's Introduction

v8-heapsnapshot

A npm module to parse and work with v8's heapsnapshots.

For more information about heapsnapshots see here

Install

Just add the package v8-heapsnapshot to your dependencies.

npm install --save v8-heapsnapshot

How to use

JavaScript:

var v8hs = require("v8-heapsnapshot")

v8hs.parseSnapshotFromFile()
    .then(function(snapshot) {
        // all nodes
        snapshot.nodes

        // all edges
        snapshot.edges

        // the global object
        snapshot.global

        // a list of loaded modules
        snapshot.modules

        // find node by id
        snapshot.findNodeById(id)
    })

TypeScript:

import {parseSnapshotFromFile} from 'v8-heapsnapshot'

// ...

const snapshot = await v8hs.parseSnapshotFromFile()

// all nodes
snapshot.nodes

// all edges
snapshot.edges

// the global object
snapshot.global

// a list of loaded modules
snapshot.modules

// find node by id
snapshot.findNodeById(id)

API

Parse a Snapshot

Parse the Snapshot with the data already in memory:

async function parseSnapshot(stream: fs.ReadStream): Promise<Snapshot>
async function parseSnapshot(json: string): Promise<Snapshot>
async function parseSnapshot(obj: Object): Promise<Snapshot>

Read a file and parse the Snapshot:

/* option type is the same as fs.createReadStream's option parameter */
async function parseSnapshotFromFile(filename: fs.PathLike, options?): Promise<Snapshot>

Work with a Snapshot

A snapshot consists of nodes and edges. The node of the global object (name: global / ) and the list of modules (name: Module) are already found. Use findNodeById to find a node by its id.

interface Snapshot {
    // Whether the field detached is present in Node
    readonly hasDetachedness: boolean

    readonly nodes: Node[]
    readonly edges: Edge[]

    readonly global: Node
    readonly modules: Node[]

    findNodeById(id: number): Node | undefined
}

You can then go through the snapshot graph:

export interface Node {
    readonly type: NodeType
    readonly name: string
    readonly id: number
    readonly self_size: number
    readonly edge_count: number
    readonly trace_node_id: number

    // Indicates whether the node is unreachable from the window object.
    // Might be undefined on older heap snapshots.
    readonly detached?: boolean

    readonly out_edges: Edge[]
    readonly in_edges: Edge[]

    toLongString(): string

    // print the node and `deep` reffered nodes to console
    print(deep?: number): void
}

export interface Edge {
    readonly type: EdgeType
    readonly name: string | number
    readonly from: Node
    readonly to: Node

    toLongString(): string
}

v8-heapsnapshot's People

Contributors

srtobi 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.