Commit 45b10228 authored by mlippautz's avatar mlippautz Committed by Commit bot

[api,profiler] Introduce GetRetainerInfos callback for profiling

BUG=679724

Review-Url: https://codereview.chromium.org/2631063003
Cr-Commit-Position: refs/heads/master@{#42506}
parent 453a1df2
......@@ -5,6 +5,7 @@
#ifndef V8_V8_PROFILER_H_
#define V8_V8_PROFILER_H_
#include <unordered_set>
#include <vector>
#include "v8.h" // NOLINT(build/include)
......@@ -630,6 +631,24 @@ class V8_EXPORT HeapProfiler {
kSamplingForceGC = 1 << 0,
};
typedef std::unordered_set<const v8::PersistentBase<v8::Value>*>
RetainerChildren;
typedef std::vector<std::pair<v8::RetainedObjectInfo*, RetainerChildren>>
RetainerGroups;
typedef std::vector<std::pair<const v8::PersistentBase<v8::Value>*,
const v8::PersistentBase<v8::Value>*>>
RetainerEdges;
struct RetainerInfos {
RetainerGroups groups;
RetainerEdges edges;
};
/**
* Callback function invoked to retrieve all RetainerInfos from the embedder.
*/
typedef RetainerInfos (*GetRetainerInfosCallback)(v8::Isolate* isolate);
/**
* Callback function invoked for obtaining RetainedObjectInfo for
* the given JavaScript wrapper object. It is prohibited to enter V8
......@@ -782,6 +801,8 @@ class V8_EXPORT HeapProfiler {
uint16_t class_id,
WrapperInfoCallback callback);
void SetGetRetainerInfosCallback(GetRetainerInfosCallback callback);
/**
* 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
......
......@@ -9755,6 +9755,11 @@ void HeapProfiler::SetWrapperClassInfoProvider(uint16_t class_id,
callback);
}
void HeapProfiler::SetGetRetainerInfosCallback(
GetRetainerInfosCallback callback) {
reinterpret_cast<i::HeapProfiler*>(this)->SetGetRetainerInfosCallback(
callback);
}
size_t HeapProfiler::GetProfilerMemorySize() {
return reinterpret_cast<i::HeapProfiler*>(this)->
......
......@@ -16,9 +16,8 @@ namespace internal {
HeapProfiler::HeapProfiler(Heap* heap)
: ids_(new HeapObjectsMap(heap)),
names_(new StringsStorage(heap)),
is_tracking_object_moves_(false) {
}
is_tracking_object_moves_(false),
get_retainer_infos_callback_(nullptr) {}
static void DeleteHeapSnapshot(HeapSnapshot** snapshot_ptr) {
delete *snapshot_ptr;
......@@ -61,6 +60,19 @@ v8::RetainedObjectInfo* HeapProfiler::ExecuteWrapperClassCallback(
class_id, Utils::ToLocal(Handle<Object>(wrapper)));
}
void HeapProfiler::SetGetRetainerInfosCallback(
v8::HeapProfiler::GetRetainerInfosCallback callback) {
get_retainer_infos_callback_ = callback;
}
v8::HeapProfiler::RetainerInfos HeapProfiler::GetRetainerInfos(
Isolate* isolate) {
v8::HeapProfiler::RetainerInfos infos;
if (get_retainer_infos_callback_ != nullptr)
infos =
get_retainer_infos_callback_(reinterpret_cast<v8::Isolate*>(isolate));
return infos;
}
HeapSnapshot* HeapProfiler::TakeSnapshot(
v8::ActivityControl* control,
......
......@@ -66,6 +66,11 @@ class HeapProfiler {
Object** wrapper);
void SetRetainedObjectInfo(UniqueId id, RetainedObjectInfo* info);
void SetGetRetainerInfosCallback(
v8::HeapProfiler::GetRetainerInfosCallback callback);
v8::HeapProfiler::RetainerInfos GetRetainerInfos(Isolate* isolate);
bool is_tracking_object_moves() const { return is_tracking_object_moves_; }
bool is_tracking_allocations() const { return !!allocation_tracker_; }
......@@ -86,6 +91,7 @@ class HeapProfiler {
bool is_tracking_object_moves_;
base::Mutex profiler_mutex_;
std::unique_ptr<SamplingHeapProfiler> sampling_heap_profiler_;
v8::HeapProfiler::GetRetainerInfosCallback get_retainer_infos_callback_;
DISALLOW_COPY_AND_ASSIGN(HeapProfiler);
};
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment