V8 Project
v8::HeapSnapshot Class Reference

HeapSnapshots record the state of the JS heap at some moment. More...

#include <v8-profiler.h>

+ Collaboration diagram for v8::HeapSnapshot:

Public Types

enum  SerializationFormat { kJSON = 0 }
 

Public Member Functions

unsigned GetUid () const
 Returns heap snapshot UID (assigned by the profiler.) More...
 
Handle< StringGetTitle () const
 Returns heap snapshot title. More...
 
const HeapGraphNodeGetRoot () const
 Returns the root node of the heap graph. More...
 
const HeapGraphNodeGetNodeById (SnapshotObjectId id) const
 Returns a node by its id. More...
 
int GetNodesCount () const
 Returns total nodes count in the snapshot. More...
 
const HeapGraphNodeGetNode (int index) const
 Returns a node by index. More...
 
SnapshotObjectId GetMaxSnapshotJSObjectId () const
 Returns a max seen JS object Id. More...
 
void Delete ()
 Deletes the snapshot and removes it from HeapProfiler's list. More...
 
void Serialize (OutputStream *stream, SerializationFormat format) const
 Prepare a serialized representation of the snapshot. More...
 

Detailed Description

HeapSnapshots record the state of the JS heap at some moment.

Definition at line 303 of file v8-profiler.h.

Member Enumeration Documentation

◆ SerializationFormat

Enumerator
kJSON 

Definition at line 305 of file v8-profiler.h.

305  {
306  kJSON = 0 // See format description near 'Serialize' method.
307  };

Member Function Documentation

◆ Delete()

void v8::HeapSnapshot::Delete ( )

Deletes the snapshot and removes it from HeapProfiler's list.

All pointers to nodes, edges and paths previously returned become invalid.

Definition at line 7309 of file api.cc.

7309  {
7310  i::Isolate* isolate = i::Isolate::Current();
7311  if (isolate->heap_profiler()->GetSnapshotsCount() > 1) {
7312  ToInternal(this)->Delete();
7313  } else {
7314  // If this is the last snapshot, clean up all accessory data as well.
7315  isolate->heap_profiler()->DeleteAllSnapshots();
7316  }
7317 }
HeapProfiler * heap_profiler() const
Definition: isolate.h:972
static i::HeapGraphEdge * ToInternal(const HeapGraphEdge *edge)
Definition: api.cc:7213

References v8::internal::HeapProfiler::DeleteAllSnapshots(), v8::internal::HeapProfiler::GetSnapshotsCount(), v8::internal::Isolate::heap_profiler(), and v8::ToInternal().

+ Here is the call graph for this function:

◆ GetMaxSnapshotJSObjectId()

SnapshotObjectId v8::HeapSnapshot::GetMaxSnapshotJSObjectId ( ) const

Returns a max seen JS object Id.

Definition at line 7354 of file api.cc.

7354  {
7355  return ToInternal(this)->max_snapshot_js_object_id();
7356 }

References v8::ToInternal().

+ Here is the call graph for this function:

◆ GetNode()

const HeapGraphNode * v8::HeapSnapshot::GetNode ( int  index) const

Returns a node by index.

Definition at line 7348 of file api.cc.

7348  {
7349  return reinterpret_cast<const HeapGraphNode*>(
7350  &ToInternal(this)->entries().at(index));
7351 }

References v8::ToInternal().

+ Here is the call graph for this function:

◆ GetNodeById()

const HeapGraphNode * v8::HeapSnapshot::GetNodeById ( SnapshotObjectId  id) const

Returns a node by its id.

Definition at line 7337 of file api.cc.

7337  {
7338  return reinterpret_cast<const HeapGraphNode*>(
7339  ToInternal(this)->GetEntryById(id));
7340 }

References v8::ToInternal().

+ Here is the call graph for this function:

◆ GetNodesCount()

int v8::HeapSnapshot::GetNodesCount ( ) const

Returns total nodes count in the snapshot.

Definition at line 7343 of file api.cc.

7343  {
7344  return ToInternal(this)->entries().length();
7345 }

References v8::ToInternal().

+ Here is the call graph for this function:

◆ GetRoot()

const HeapGraphNode * v8::HeapSnapshot::GetRoot ( ) const

Returns the root node of the heap graph.

Definition at line 7332 of file api.cc.

7332  {
7333  return reinterpret_cast<const HeapGraphNode*>(ToInternal(this)->root());
7334 }

References v8::ToInternal().

+ Here is the call graph for this function:

◆ GetTitle()

Handle< String > v8::HeapSnapshot::GetTitle ( ) const

Returns heap snapshot title.

Definition at line 7325 of file api.cc.

7325  {
7326  i::Isolate* isolate = i::Isolate::Current();
7327  return ToApiHandle<String>(
7328  isolate->factory()->InternalizeUtf8String(ToInternal(this)->title()));
7329 }
Factory * factory()
Definition: isolate.h:982

References v8::internal::Isolate::factory(), and v8::ToInternal().

+ Here is the call graph for this function:

◆ GetUid()

unsigned v8::HeapSnapshot::GetUid ( ) const

Returns heap snapshot UID (assigned by the profiler.)

Definition at line 7320 of file api.cc.

7320  {
7321  return ToInternal(this)->uid();
7322 }

References v8::ToInternal().

+ Here is the call graph for this function:

◆ Serialize()

void v8::HeapSnapshot::Serialize ( OutputStream stream,
HeapSnapshot::SerializationFormat  format 
) const

Prepare a serialized representation of the snapshot.

The result is written into the stream provided in chunks of specified size. The total length of the serialized snapshot is unknown in advance, it can be roughly equal to JS heap size (that means, it can be really big - tens of megabytes).

For the JSON format, heap contents are represented as an object with the following structure:

{ snapshot: { title: "...", uid: nnn, meta: { meta-info }, node_count: nnn, edge_count: nnn }, nodes: [nodes array], edges: [edges array], strings: [strings array] }

Nodes reference strings, other nodes, and edges by their indexes in corresponding arrays.

Definition at line 7359 of file api.cc.

7360  {
7361  Utils::ApiCheck(format == kJSON,
7362  "v8::HeapSnapshot::Serialize",
7363  "Unknown serialization format");
7364  Utils::ApiCheck(stream->GetChunkSize() > 0,
7365  "v8::HeapSnapshot::Serialize",
7366  "Invalid stream chunk size");
7367  i::HeapSnapshotJSONSerializer serializer(ToInternal(this));
7368  serializer.Serialize(stream);
7369 }
static bool ApiCheck(bool condition, const char *location, const char *message)
Definition: api.h:177

References v8::Utils::ApiCheck(), v8::OutputStream::GetChunkSize(), v8::internal::HeapSnapshotJSONSerializer::Serialize(), and v8::ToInternal().

+ Here is the call graph for this function:

The documentation for this class was generated from the following files: