Home Manual Reference Source Repository
import HeapSnapshot from 'snapshot-utils/lib/HeapSnapshot.js'
public class | source

HeapSnapshot

Representation for iterating over a snapshot's Nodes and Edges. The structure of a snapshot's Node and Edge is defined within the contents of the snapshot.

Constructor Summary

Public Constructor
public

Method Summary

Public Methods
public

getNode(node_index: number): NodeResult

Gets a Node by index, not by ID.

public

Gets a Node by ID.

public

getSample(sample_index: number): Sample

Gets a Sample by index.

public

samples(): Iterator<Sample>

Walks over all the Samples in the HeapSnapshot in order.

public

walk(callbacks: WalkCallbacks): Iterator

Helper function that performs a depth first pre order traversal of the nodes of a HeapSnapshot.

Public Constructors

public constructor(provider: SplitSnapshotProvider) source

Params:

NameTypeAttributeDescription
provider SplitSnapshotProvider

Snapshot data provider

Public Methods

public getNode(node_index: number): NodeResult source

Gets a Node by index, not by ID. The root Node is at index 0.

Params:

NameTypeAttributeDescription
node_index number

Return:

NodeResult

Example:

const root = snapshot.getNode(0);

public getNodeById(node_id: number): NodeResult source

Gets a Node by ID. This can be SIGNIFICANTLY SLOWER than looking up the Node by index since IDs are sparse.

Params:

NameTypeAttributeDescription
node_id number

Return:

NodeResult

Example:

const myNode = snapshot.getNodeById(42);

public getSample(sample_index: number): Sample source

Gets a Sample by index.

Params:

NameTypeAttributeDescription
sample_index number

Return:

Sample

Example:

const first = snapshot.getSample(0);
const second = snapshot.getSample(1);
console.log('delay', second.time - first.time);

public samples(): Iterator<Sample> source

Walks over all the Samples in the HeapSnapshot in order.

Return:

Iterator<Sample>

Iterator to walk over all of the Samples.

public walk(callbacks: WalkCallbacks): Iterator source

Helper function that performs a depth first pre order traversal of the nodes of a HeapSnapshot. This will only visit each Node once, but will visit all Edges of a HeapSnapshot. Since this can be a costly operation it uses an iterator to allow chunked processing.

Params:

NameTypeAttributeDescription
callbacks WalkCallbacks

Return:

Iterator

iterator to continue walking by calling .next

Example:

let walker = walk(console.log);
// the iterator does not return a value it is purely a controller
for (const _ of walker) {}