Commit 5da78ea4 authored by Ulan Degenbaev's avatar Ulan Degenbaev Committed by Commit Bot

[heap-profiler] Allow embedder to specify node name prefix.

This patch adds EmbedderGraph::Node::NamePrefix method that will be used
by Chrome for detached DOM nodes.

Bug: chromium:811925
Cq-Include-Trybots: master.tryserver.chromium.linux:linux_chromium_rel_ng
Change-Id: I89d3b88a3b90ed85addb1d34f08dd15e0559aa9a
Reviewed-on: https://chromium-review.googlesource.com/926362
Commit-Queue: Ulan Degenbaev <ulan@chromium.org>
Reviewed-by: 's avatarMichael Lippautz <mlippautz@chromium.org>
Reviewed-by: 's avatarHannes Payer <hpayer@chromium.org>
Cr-Commit-Position: refs/heads/master@{#51464}
parent 962f025a
......@@ -657,6 +657,10 @@ class V8_EXPORT EmbedderGraph {
virtual bool IsRootNode() { return false; }
/** Must return true for non-V8 nodes. */
virtual bool IsEmbedderNode() { return true; }
/**
* Optional name prefix. It is used in Chrome for tagging detached nodes.
*/
virtual const char* NamePrefix() { return nullptr; }
private:
Node(const Node&) = delete;
......
......@@ -2032,7 +2032,9 @@ namespace {
const char* EmbedderGraphNodeName(StringsStorage* names,
EmbedderGraphImpl::Node* node) {
return names->GetCopy(node->Name());
const char* prefix = node->NamePrefix();
return prefix ? names->GetFormatted("%s %s", prefix, node->Name())
: names->GetCopy(node->Name());
}
HeapEntry::Type EmbedderGraphNodeType(EmbedderGraphImpl::Node* node) {
......
......@@ -2981,6 +2981,48 @@ TEST(EmbedderGraphWithWrapperNode) {
CHECK(!wrapper_node2);
}
class EmbedderNodeWithPrefix : public v8::EmbedderGraph::Node {
public:
EmbedderNodeWithPrefix(const char* prefix, const char* name)
: prefix_(prefix), name_(name) {}
// Graph::Node overrides.
const char* Name() override { return name_; }
size_t SizeInBytes() override { return 0; }
const char* NamePrefix() override { return prefix_; }
private:
const char* prefix_;
const char* name_;
};
void BuildEmbedderGraphWithPrefix(v8::Isolate* v8_isolate,
v8::EmbedderGraph* graph) {
using Node = v8::EmbedderGraph::Node;
Node* global_node = graph->V8Node(*global_object_pointer);
Node* node = graph->AddNode(
std::unique_ptr<Node>(new EmbedderNodeWithPrefix("Detached", "Node")));
graph->AddEdge(global_node, node);
}
TEST(EmbedderGraphWithPrefix) {
i::FLAG_heap_profiler_use_embedder_graph = true;
LocalContext env;
v8::HandleScope scope(env->GetIsolate());
i::Isolate* isolate = reinterpret_cast<i::Isolate*>(env->GetIsolate());
v8::Local<v8::Value> global_object =
v8::Utils::ToLocal(i::Handle<i::JSObject>(
(isolate->context()->native_context()->global_object())));
global_object_pointer = &global_object;
v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler();
heap_profiler->SetBuildEmbedderGraphCallback(BuildEmbedderGraphWithPrefix);
const v8::HeapSnapshot* snapshot = heap_profiler->TakeHeapSnapshot();
CHECK(ValidateSnapshot(snapshot));
const v8::HeapGraphNode* global = GetGlobalObject(snapshot);
const v8::HeapGraphNode* node = GetChildByName(global, "Detached Node");
CHECK(node);
}
static inline i::Address ToAddress(int n) {
return reinterpret_cast<i::Address>(n);
}
......
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