Commit 6fd62f38 authored by Lalit Maganti's avatar Lalit Maganti Committed by Commit Bot

memory-infra: assign overhead of tracing to tracing node in graph

Bug: 768373
Change-Id: I1db4191eacb7370afb0abd6c820d52057430fb00
Reviewed-on: https://chromium-review.googlesource.com/705214
Commit-Queue: Lalit Maganti <lalitm@chromium.org>
Reviewed-by: default avatarPrimiano Tucci <primiano@chromium.org>
Cr-Commit-Position: refs/heads/master@{#512902}
parent fbf0a167
...@@ -76,8 +76,10 @@ Node* Process::CreateNode(MemoryAllocatorDumpGuid guid, ...@@ -76,8 +76,10 @@ Node* Process::CreateNode(MemoryAllocatorDumpGuid guid,
current->set_weak(weak); current->set_weak(weak);
current->set_explicit(true); current->set_explicit(true);
// Add to the global guid map as well. // Add to the global guid map as well if it exists.
global_graph_->nodes_by_guid_.emplace(guid, current); if (!guid.empty())
global_graph_->nodes_by_guid_.emplace(guid, current);
return current; return current;
} }
......
...@@ -89,6 +89,18 @@ std::unique_ptr<GlobalDumpGraph> GraphProcessor::ComputeMemoryGraph( ...@@ -89,6 +89,18 @@ std::unique_ptr<GlobalDumpGraph> GraphProcessor::ComputeMemoryGraph(
RemoveWeakNodesRecursively(pid_to_process.second->root()); RemoveWeakNodesRecursively(pid_to_process.second->root());
} }
// Sixth pass: account for tracing overhead in system memory allocators.
for (auto& pid_to_process : global_graph->process_dump_graphs()) {
Process* process = pid_to_process.second.get();
if (process->FindNode("winheap")) {
AssignTracingOverhead("winheap", global_graph.get(),
pid_to_process.second.get());
} else if (process->FindNode("malloc")) {
AssignTracingOverhead("malloc", global_graph.get(),
pid_to_process.second.get());
}
}
return global_graph; return global_graph;
} }
...@@ -263,4 +275,31 @@ void GraphProcessor::RemoveWeakNodesRecursively(Node* node) { ...@@ -263,4 +275,31 @@ void GraphProcessor::RemoveWeakNodesRecursively(Node* node) {
} }
} }
// static
void GraphProcessor::AssignTracingOverhead(base::StringPiece allocator,
GlobalDumpGraph* global_graph,
Process* process) {
// This method should only be called if the allocator node exists.
DCHECK(process->FindNode(allocator));
// Check that the tracing dump exists and isn't already owning another node.
Node* tracing_node = process->FindNode("tracing");
if (!tracing_node)
return;
// This should be first edge associated with the tracing node.
DCHECK(!tracing_node->owns_edge());
// Create the node under the allocator to which tracing overhead can be
// assigned.
std::string child_name =
allocator.as_string() + "/allocated_objects/tracing_overhead";
Node* child_node = process->CreateNode(MemoryAllocatorDumpGuid(), child_name,
false /* weak */);
// Assign the overhead of tracing to the tracing node.
global_graph->AddNodeOwnershipEdge(tracing_node, child_node,
0 /* importance */);
}
} // namespace memory_instrumentation } // namespace memory_instrumentation
\ No newline at end of file
...@@ -39,6 +39,10 @@ class GraphProcessor { ...@@ -39,6 +39,10 @@ class GraphProcessor {
std::set<const GlobalDumpGraph::Node*>* nodes); std::set<const GlobalDumpGraph::Node*>* nodes);
static void RemoveWeakNodesRecursively(GlobalDumpGraph::Node* parent); static void RemoveWeakNodesRecursively(GlobalDumpGraph::Node* parent);
static void AssignTracingOverhead(base::StringPiece allocator,
GlobalDumpGraph* global_graph,
GlobalDumpGraph::Process* process);
}; };
} // namespace memory_instrumentation } // namespace memory_instrumentation
......
...@@ -17,6 +17,7 @@ using base::trace_event::MemoryDumpLevelOfDetail; ...@@ -17,6 +17,7 @@ using base::trace_event::MemoryDumpLevelOfDetail;
using base::trace_event::ProcessMemoryDump; using base::trace_event::ProcessMemoryDump;
using Edge = GlobalDumpGraph::Edge; using Edge = GlobalDumpGraph::Edge;
using Node = GlobalDumpGraph::Node; using Node = GlobalDumpGraph::Node;
using Process = GlobalDumpGraph::Process;
class GraphProcessorTest : public testing::Test { class GraphProcessorTest : public testing::Test {
public: public:
...@@ -34,6 +35,12 @@ class GraphProcessorTest : public testing::Test { ...@@ -34,6 +35,12 @@ class GraphProcessorTest : public testing::Test {
void RemoveWeakNodesRecursively(Node* node) { void RemoveWeakNodesRecursively(Node* node) {
GraphProcessor::RemoveWeakNodesRecursively(node); GraphProcessor::RemoveWeakNodesRecursively(node);
} }
void AssignTracingOverhead(base::StringPiece allocator,
GlobalDumpGraph* global_graph,
GlobalDumpGraph::Process* process) {
GraphProcessor::AssignTracingOverhead(allocator, global_graph, process);
}
}; };
TEST_F(GraphProcessorTest, SmokeComputeMemoryGraph) { TEST_F(GraphProcessorTest, SmokeComputeMemoryGraph) {
...@@ -312,4 +319,26 @@ TEST_F(GraphProcessorTest, RemoveWeakNodesRecursivelyBetweenGraphs) { ...@@ -312,4 +319,26 @@ TEST_F(GraphProcessorTest, RemoveWeakNodesRecursivelyBetweenGraphs) {
ASSERT_TRUE(owned.owned_by_edges()->empty()); ASSERT_TRUE(owned.owned_by_edges()->empty());
} }
TEST_F(GraphProcessorTest, AssignTracingOverhead) {
GlobalDumpGraph graph;
Process process(&graph);
// Now add an allocator node.
Node allocator(&process, process.root());
process.root()->InsertChild("malloc", &allocator);
// If the tracing node does not exist, this should do nothing.
AssignTracingOverhead("malloc", &graph, &process);
ASSERT_TRUE(process.root()->GetChild("malloc")->children()->empty());
// Now add a tracing node.
Node tracing(&process, process.root());
process.root()->InsertChild("tracing", &tracing);
// This should now add a node with the allocator.
AssignTracingOverhead("malloc", &graph, &process);
ASSERT_NE(process.FindNode("malloc/allocated_objects/tracing_overhead"),
nullptr);
}
} // namespace memory_instrumentation } // namespace memory_instrumentation
\ No newline at end of file
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