V8 Project
v8::HeapProfiler Class Reference

Interface for controlling heap profiling. More...

#include <v8-profiler.h>

+ Collaboration diagram for v8::HeapProfiler:

Classes

class  ObjectNameResolver
 Callback interface for retrieving user friendly names of global objects. More...
 

Public Types

typedef RetainedObjectInfo *(* WrapperInfoCallback) (uint16_t class_id, Handle< Value > wrapper)
 Callback function invoked for obtaining RetainedObjectInfo for the given JavaScript wrapper object. More...
 

Public Member Functions

int GetSnapshotCount ()
 Returns the number of snapshots taken. More...
 
const HeapSnapshotGetHeapSnapshot (int index)
 Returns a snapshot by index. More...
 
SnapshotObjectId GetObjectId (Handle< Value > value)
 Returns SnapshotObjectId for a heap object referenced by |value| if it has been seen by the heap profiler, kUnknownObjectId otherwise. More...
 
Handle< ValueFindObjectById (SnapshotObjectId id)
 Returns heap object with given SnapshotObjectId if the object is alive, otherwise empty handle is returned. More...
 
void ClearObjectIds ()
 Clears internal map from SnapshotObjectId to heap object. More...
 
const HeapSnapshotTakeHeapSnapshot (Handle< String > title, ActivityControl *control=NULL, ObjectNameResolver *global_object_name_resolver=NULL)
 Takes a heap snapshot and returns it. More...
 
void StartTrackingHeapObjects (bool track_allocations=false)
 Starts tracking of heap objects population statistics. More...
 
SnapshotObjectId GetHeapStats (OutputStream *stream)
 Adds a new time interval entry to the aggregated statistics array. More...
 
void StopTrackingHeapObjects ()
 Stops tracking of heap objects population statistics, cleans up all collected data. More...
 
void DeleteAllHeapSnapshots ()
 Deletes all snapshots taken. More...
 
void SetWrapperClassInfoProvider (uint16_t class_id, WrapperInfoCallback callback)
 Binds a callback to embedder's class ID. More...
 
size_t GetProfilerMemorySize ()
 Returns memory used for profiler internal data and snapshots. More...
 
void SetRetainedObjectInfo (UniqueId id, RetainedObjectInfo *info)
 Sets a RetainedObjectInfo for an object group (see V8::SetObjectGroupId). More...
 

Static Public Attributes

static const SnapshotObjectId kUnknownObjectId = 0
 A constant for invalid SnapshotObjectId. More...
 
static const uint16_t kPersistentHandleNoClassId = 0
 Default value of persistent handle class ID. More...
 

Private Member Functions

 HeapProfiler ()
 
 ~HeapProfiler ()
 
 HeapProfiler (const HeapProfiler &)
 
HeapProfileroperator= (const HeapProfiler &)
 

Detailed Description

Interface for controlling heap profiling.

Instance of the profiler can be retrieved using v8::Isolate::GetHeapProfiler.

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

Member Typedef Documentation

◆ WrapperInfoCallback

typedef RetainedObjectInfo*(* v8::HeapProfiler::WrapperInfoCallback) (uint16_t class_id, Handle< Value > wrapper)

Callback function invoked for obtaining RetainedObjectInfo for the given JavaScript wrapper object.

It is prohibited to enter V8 while the callback is running: only getters on the handle and GetPointerFromInternalField on the objects are allowed.

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

Constructor & Destructor Documentation

◆ HeapProfiler() [1/2]

v8::HeapProfiler::HeapProfiler ( )
private

◆ ~HeapProfiler()

v8::HeapProfiler::~HeapProfiler ( )
private

◆ HeapProfiler() [2/2]

v8::HeapProfiler::HeapProfiler ( const HeapProfiler )
private

Member Function Documentation

◆ ClearObjectIds()

void v8::HeapProfiler::ClearObjectIds ( )

Clears internal map from SnapshotObjectId to heap object.

The new objects will not be added into it unless a heap snapshot is taken or heap object tracking is kicked off.

Definition at line 7397 of file api.cc.

7397  {
7398  reinterpret_cast<i::HeapProfiler*>(this)->ClearHeapObjectMap();
7399 }

◆ DeleteAllHeapSnapshots()

void v8::HeapProfiler::DeleteAllHeapSnapshots ( )

Deletes all snapshots taken.

All previously returned pointers to snapshots and their contents become invalid after this call.

Definition at line 7428 of file api.cc.

7428  {
7429  reinterpret_cast<i::HeapProfiler*>(this)->DeleteAllSnapshots();
7430 }

◆ FindObjectById()

Handle< Value > v8::HeapProfiler::FindObjectById ( SnapshotObjectId  id)

Returns heap object with given SnapshotObjectId if the object is alive, otherwise empty handle is returned.

Definition at line 7389 of file api.cc.

7389  {
7390  i::Handle<i::Object> obj =
7391  reinterpret_cast<i::HeapProfiler*>(this)->FindHeapObjectById(id);
7392  if (obj.is_null()) return Local<Value>();
7393  return Utils::ToLocal(obj);
7394 }
static Local< Context > ToLocal(v8::internal::Handle< v8::internal::Context > obj)
bool is_null() const
Definition: handles.h:124

References v8::internal::Handle< T >::is_null(), and v8::Utils::ToLocal().

+ Here is the call graph for this function:

◆ GetHeapSnapshot()

const HeapSnapshot * v8::HeapProfiler::GetHeapSnapshot ( int  index)

Returns a snapshot by index.

Definition at line 7377 of file api.cc.

7377  {
7378  return reinterpret_cast<const HeapSnapshot*>(
7379  reinterpret_cast<i::HeapProfiler*>(this)->GetSnapshot(index));
7380 }

◆ GetHeapStats()

SnapshotObjectId v8::HeapProfiler::GetHeapStats ( OutputStream stream)

Adds a new time interval entry to the aggregated statistics array.

The time interval entry contains information on the current heap objects population size. The method also updates aggregated statistics and reports updates for all previous time intervals via the OutputStream object. Updates on each time interval are provided as a stream of the HeapStatsUpdate structure instances. The return value of the function is the last seen heap object Id.

StartTrackingHeapObjects must be called before the first call to this method.

Definition at line 7423 of file api.cc.

7423  {
7424  return reinterpret_cast<i::HeapProfiler*>(this)->PushHeapObjectsStats(stream);
7425 }

◆ GetObjectId()

SnapshotObjectId v8::HeapProfiler::GetObjectId ( Handle< Value value)

Returns SnapshotObjectId for a heap object referenced by |value| if it has been seen by the heap profiler, kUnknownObjectId otherwise.

Definition at line 7383 of file api.cc.

7383  {
7385  return reinterpret_cast<i::HeapProfiler*>(this)->GetSnapshotObjectId(obj);
7386 }
static v8::internal::Handle< To > OpenHandle(v8::Local< From > handle)
Definition: api.h:288

References v8::Utils::OpenHandle().

+ Here is the call graph for this function:

◆ GetProfilerMemorySize()

size_t v8::HeapProfiler::GetProfilerMemorySize ( )

Returns memory used for profiler internal data and snapshots.

Definition at line 7440 of file api.cc.

7440  {
7441  return reinterpret_cast<i::HeapProfiler*>(this)->
7442  GetMemorySizeUsedByProfiler();
7443 }

◆ GetSnapshotCount()

int v8::HeapProfiler::GetSnapshotCount ( )

Returns the number of snapshots taken.

Definition at line 7372 of file api.cc.

7372  {
7373  return reinterpret_cast<i::HeapProfiler*>(this)->GetSnapshotsCount();
7374 }

◆ operator=()

HeapProfiler& v8::HeapProfiler::operator= ( const HeapProfiler )
private

◆ SetRetainedObjectInfo()

void v8::HeapProfiler::SetRetainedObjectInfo ( UniqueId  id,
RetainedObjectInfo info 
)

Sets a RetainedObjectInfo for an object group (see V8::SetObjectGroupId).

Definition at line 7446 of file api.cc.

7447  {
7448  reinterpret_cast<i::HeapProfiler*>(this)->SetRetainedObjectInfo(id, info);
7449 }
void SetRetainedObjectInfo(UniqueId id, RetainedObjectInfo *info)
Sets a RetainedObjectInfo for an object group (see V8::SetObjectGroupId).
Definition: api.cc:7446

◆ SetWrapperClassInfoProvider()

void v8::HeapProfiler::SetWrapperClassInfoProvider ( uint16_t  class_id,
WrapperInfoCallback  callback 
)

Binds a callback to embedder's class ID.

Definition at line 7433 of file api.cc.

7434  {
7435  reinterpret_cast<i::HeapProfiler*>(this)->DefineWrapperClass(class_id,
7436  callback);
7437 }

◆ StartTrackingHeapObjects()

void v8::HeapProfiler::StartTrackingHeapObjects ( bool  track_allocations = false)

Starts tracking of heap objects population statistics.

After calling this method, all heap objects relocations done by the garbage collector are being registered.

|track_allocations| parameter controls whether stack trace of each allocation in the heap will be recorded and reported as part of HeapSnapshot.

Definition at line 7412 of file api.cc.

7412  {
7413  reinterpret_cast<i::HeapProfiler*>(this)->StartHeapObjectsTracking(
7414  track_allocations);
7415 }

◆ StopTrackingHeapObjects()

void v8::HeapProfiler::StopTrackingHeapObjects ( )

Stops tracking of heap objects population statistics, cleans up all collected data.

StartHeapObjectsTracking must be called again prior to calling PushHeapObjectsStats next time.

Definition at line 7418 of file api.cc.

7418  {
7419  reinterpret_cast<i::HeapProfiler*>(this)->StopHeapObjectsTracking();
7420 }

◆ TakeHeapSnapshot()

const HeapSnapshot * v8::HeapProfiler::TakeHeapSnapshot ( Handle< String title,
ActivityControl control = NULL,
ObjectNameResolver global_object_name_resolver = NULL 
)

Takes a heap snapshot and returns it.

Title may be an empty string.

Definition at line 7402 of file api.cc.

7405  {
7406  return reinterpret_cast<const HeapSnapshot*>(
7407  reinterpret_cast<i::HeapProfiler*>(this)->TakeSnapshot(
7408  *Utils::OpenHandle(*title), control, resolver));
7409 }

References v8::Utils::OpenHandle().

+ Here is the call graph for this function:

Member Data Documentation

◆ kPersistentHandleNoClassId

const uint16_t v8::HeapProfiler::kPersistentHandleNoClassId = 0
static

Default value of persistent handle class ID.

Must not be used to define a class. Can be used to reset a class of a persistent handle.

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

Referenced by v8::internal::GlobalHandles::Node::Acquire(), v8::internal::HeapProfiler::DefineWrapperClass(), v8::internal::GlobalHandles::Node::has_wrapper_class_id(), and v8::internal::GlobalHandles::Node::Release().

◆ kUnknownObjectId

const SnapshotObjectId v8::HeapProfiler::kUnknownObjectId = 0
static

A constant for invalid SnapshotObjectId.

GetSnapshotObjectId will return it in case heap profiler cannot find id for the object passed as parameter. HeapSnapshot::GetNodeById will always return NULL for such id.

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

Referenced by v8::internal::HeapProfiler::GetSnapshotObjectId().


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