v8
V8 is Google’s open source high-performance JavaScript and WebAssembly engine, written in C++.
Loading...
Searching...
No Matches
v8::HeapProfiler Class Reference

#include <v8-profiler.h>

Collaboration diagram for v8::HeapProfiler:

Classes

struct  HeapSnapshotOptions
 
class  ObjectNameResolver
 

Public Types

enum  SamplingFlags { kSamplingNoFlags = 0 , kSamplingForceGC = 1 << 0 , kSamplingIncludeObjectsCollectedByMajorGC = 1 << 1 , kSamplingIncludeObjectsCollectedByMinorGC = 1 << 2 }
 
enum class  HeapSnapshotMode { kRegular , kExposeInternals }
 
enum class  NumericsMode { kHideNumericValues , kExposeNumericValues }
 
typedef void(*) BuildEmbedderGraphCallback(v8::Isolate *isolate, v8::EmbedderGraph *graph, void *data)
 
using GetDetachednessCallback
 

Public Member Functions

void QueryObjects (v8::Local< v8::Context > context, QueryObjectPredicate *predicate, std::vector< v8::Global< v8::Object > > *objects)
 
int GetSnapshotCount ()
 
const HeapSnapshotGetHeapSnapshot (int index)
 
SnapshotObjectId GetObjectId (Local< Value > value)
 
SnapshotObjectId GetObjectId (NativeObject value)
 
Local< ValueFindObjectById (SnapshotObjectId id)
 
void ClearObjectIds ()
 
const HeapSnapshotTakeHeapSnapshot (const HeapSnapshotOptions &options=HeapSnapshotOptions())
 
const HeapSnapshotTakeHeapSnapshot (ActivityControl *control, ObjectNameResolver *global_object_name_resolver=nullptr, bool hide_internals=true, bool capture_numeric_value=false)
 
std::vector< v8::Local< v8::Value > > GetDetachedJSWrapperObjects ()
 
void StartTrackingHeapObjects (bool track_allocations=false)
 
SnapshotObjectId GetHeapStats (OutputStream *stream, int64_t *timestamp_us=nullptr)
 
void StopTrackingHeapObjects ()
 
bool StartSamplingHeapProfiler (uint64_t sample_interval=512 *1024, int stack_depth=16, SamplingFlags flags=kSamplingNoFlags)
 
void StopSamplingHeapProfiler ()
 
AllocationProfileGetAllocationProfile ()
 
void DeleteAllHeapSnapshots ()
 
void AddBuildEmbedderGraphCallback (BuildEmbedderGraphCallback callback, void *data)
 
void RemoveBuildEmbedderGraphCallback (BuildEmbedderGraphCallback callback, void *data)
 
void SetGetDetachednessCallback (GetDetachednessCallback callback, void *data)
 
bool IsTakingSnapshot ()
 
const char * CopyNameForHeapSnapshot (const char *name)
 

Static Public Attributes

static const SnapshotObjectId kUnknownObjectId = 0
 
static const uint16_t kPersistentHandleNoClassId = 0
 

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 965 of file v8-profiler.h.

Member Typedef Documentation

◆ BuildEmbedderGraphCallback

void(*) v8::HeapProfiler::BuildEmbedderGraphCallback(v8::Isolate *isolate, v8::EmbedderGraph *graph, void *data)

Callback function invoked during heap snapshot generation to retrieve the embedder object graph. The callback should use graph->AddEdge(..) to add references between the objects. The callback must not trigger garbage collection in V8.

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

◆ GetDetachednessCallback

Initial value:
uint16_t class_id, void* data)
union v8::internal::@341::BuiltinMetadata::KindSpecificData data
Isolate * isolate

Callback function invoked during heap snapshot generation to retrieve the detachedness state of a JS object referenced by a TracedReference.

The callback takes Local<Value> as parameter to allow the embedder to unpack the TracedReference into a Local and reuse that Local for different purposes.

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

Member Enumeration Documentation

◆ HeapSnapshotMode

Enumerator
kRegular 

Heap snapshot for regular developers.

kExposeInternals 

Heap snapshot is exposing internals that may be useful for experts.

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

◆ NumericsMode

enum class v8::HeapProfiler::NumericsMode
strong
Enumerator
kHideNumericValues 

Numeric values are hidden as they are values of the corresponding objects.

kExposeNumericValues 

Numeric values are exposed in artificial fields.

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

◆ SamplingFlags

Enumerator
kSamplingNoFlags 
kSamplingForceGC 
kSamplingIncludeObjectsCollectedByMajorGC 
kSamplingIncludeObjectsCollectedByMinorGC 

Definition at line 971 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

◆ AddBuildEmbedderGraphCallback()

void v8::HeapProfiler::AddBuildEmbedderGraphCallback ( BuildEmbedderGraphCallback callback,
void * data )

Definition at line 11806 of file api.cc.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ 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 11736 of file api.cc.

◆ CopyNameForHeapSnapshot()

const char * v8::HeapProfiler::CopyNameForHeapSnapshot ( const char * name)

Allocates a copy of the provided string within the heap snapshot generator and returns a pointer to the copy. May only be called during heap snapshot generation.

Definition at line 11828 of file api.cc.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ 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 11796 of file api.cc.

◆ FindObjectById()

Local< 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 11729 of file api.cc.

Here is the call graph for this function:

◆ GetAllocationProfile()

AllocationProfile * v8::HeapProfiler::GetAllocationProfile ( )

Returns the sampled profile of allocations allocated (and still live) since StartSamplingHeapProfiler was called. The ownership of the pointer is transferred to the caller. Returns nullptr if sampling heap profiler is not active.

Definition at line 11792 of file api.cc.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GetDetachedJSWrapperObjects()

std::vector< v8::Local< v8::Value > > v8::HeapProfiler::GetDetachedJSWrapperObjects ( )

Obtains list of Detached JS Wrapper Objects. This functon calls garbage collection, then iterates over traced handles in the isolate

Definition at line 11761 of file api.cc.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GetHeapSnapshot()

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

Returns a snapshot by index.

Definition at line 11715 of file api.cc.

Here is the call graph for this function:

◆ GetHeapStats()

SnapshotObjectId v8::HeapProfiler::GetHeapStats ( OutputStream * stream,
int64_t * timestamp_us = nullptr )

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. If |timestamp_us| is supplied, timestamp of the new entry will be written into it. 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 11775 of file api.cc.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GetObjectId() [1/2]

SnapshotObjectId v8::HeapProfiler::GetObjectId ( Local< 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 11720 of file api.cc.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GetObjectId() [2/2]

SnapshotObjectId v8::HeapProfiler::GetObjectId ( NativeObject value)

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

Definition at line 11725 of file api.cc.

◆ GetSnapshotCount()

int v8::HeapProfiler::GetSnapshotCount ( )

Returns the number of snapshots taken.

Definition at line 11700 of file api.cc.

◆ IsTakingSnapshot()

bool v8::HeapProfiler::IsTakingSnapshot ( )

Returns whether the heap profiler is currently taking a snapshot.

Definition at line 11824 of file api.cc.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ operator=()

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

◆ QueryObjects()

void v8::HeapProfiler::QueryObjects ( v8::Local< v8::Context > context,
QueryObjectPredicate * predicate,
std::vector< v8::Global< v8::Object > > * objects )

Definition at line 11704 of file api.cc.

Here is the call graph for this function:

◆ RemoveBuildEmbedderGraphCallback()

void v8::HeapProfiler::RemoveBuildEmbedderGraphCallback ( BuildEmbedderGraphCallback callback,
void * data )

Definition at line 11812 of file api.cc.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ SetGetDetachednessCallback()

void v8::HeapProfiler::SetGetDetachednessCallback ( GetDetachednessCallback callback,
void * data )

Definition at line 11818 of file api.cc.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ StartSamplingHeapProfiler()

bool v8::HeapProfiler::StartSamplingHeapProfiler ( uint64_t sample_interval = 512 * 1024,
int stack_depth = 16,
SamplingFlags flags = kSamplingNoFlags )

Starts gathering a sampling heap profile. A sampling heap profile is similar to tcmalloc's heap profiler and Go's mprof. It samples object allocations and builds an online 'sampling' heap profile. At any point in time, this profile is expected to be a representative sample of objects currently live in the system. Each sampled allocation includes the stack trace at the time of allocation, which makes this really useful for memory leak detection.

This mechanism is intended to be cheap enough that it can be used in production with minimal performance overhead.

Allocations are sampled using a randomized Poisson process. On average, one allocation will be sampled every |sample_interval| bytes allocated. The |stack_depth| parameter controls the maximum number of stack frames to be captured on each allocation.

NOTE: Support for native allocations doesn't exist yet, but is anticipated in the future.

Objects allocated before the sampling is started will not be included in the profile.

Returns false if a sampling heap profiler is already running.

Definition at line 11781 of file api.cc.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ 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 11766 of file api.cc.

Here is the caller graph for this function:

◆ StopSamplingHeapProfiler()

void v8::HeapProfiler::StopSamplingHeapProfiler ( )

Stops the sampling heap profile and discards the current profile.

Definition at line 11788 of file api.cc.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ 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 GetHeapStats next time.

Definition at line 11771 of file api.cc.

Here is the caller graph for this function:

◆ TakeHeapSnapshot() [1/2]

const HeapSnapshot * v8::HeapProfiler::TakeHeapSnapshot ( ActivityControl * control,
ObjectNameResolver * global_object_name_resolver = nullptr,
bool hide_internals = true,
bool capture_numeric_value = false )

Takes a heap snapshot. See HeapSnapshotOptions for details on the parameters.

Returns
the snapshot.

Definition at line 11746 of file api.cc.

Here is the call graph for this function:

◆ TakeHeapSnapshot() [2/2]

const HeapSnapshot * v8::HeapProfiler::TakeHeapSnapshot ( const HeapSnapshotOptions & options = HeapSnapshotOptions())

Takes a heap snapshot.

Returns
the snapshot.

Definition at line 11740 of file api.cc.

Here is the call graph for this function:
Here is the caller 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 1236 of file v8-profiler.h.

◆ kUnknownObjectId

STATIC_CONST_MEMBER_DEFINITION 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 1036 of file v8-profiler.h.


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