Commit bfe58719 authored by Ulan Degenbaev's avatar Ulan Degenbaev Committed by Commit Bot

[tracing] Dump context counts in v8 memory dump provider.

This patch adds the following dumps in v8 memory dump provider:
- v8/isolate/contexts/detached_context
- v8/isolate/contexts/native_context
Both dumps contain an "object_count" scalar value.

The value of detached_context is the number of contexts that were
detached (due to iframe navigation or removal) and not yet garbage
collected. This number being non-zero indicates potential memory leak.

The value of native_context is the number of the top-level contexts
created for the main window and iframes. Increase of this number
over time indicates a memory leak.

Bug: 793789
Change-Id: I4753454747c398fac4fc153fcccb1288d28f2a2d
Reviewed-on: https://chromium-review.googlesource.com/822336
Commit-Queue: Ulan Degenbaev <ulan@chromium.org>
Reviewed-by: default avatarRoss McIlroy <rmcilroy@chromium.org>
Reviewed-by: default avatarPrimiano Tucci <primiano@chromium.org>
Cr-Commit-Position: refs/heads/master@{#524438}
parent 37950cec
...@@ -179,6 +179,8 @@ const char* const kAllocatorDumpNameWhitelist[] = { ...@@ -179,6 +179,8 @@ const char* const kAllocatorDumpNameWhitelist[] = {
"skia/sk_resource_cache", "skia/sk_resource_cache",
"sqlite", "sqlite",
"ui/resource_manager_0x?", "ui/resource_manager_0x?",
"v8/isolate_0x?/contexts/detached_context",
"v8/isolate_0x?/contexts/native_context",
"v8/isolate_0x?/heap_spaces", "v8/isolate_0x?/heap_spaces",
"v8/isolate_0x?/heap_spaces/code_space", "v8/isolate_0x?/heap_spaces/code_space",
"v8/isolate_0x?/heap_spaces/large_object_space", "v8/isolate_0x?/heap_spaces/large_object_space",
......
...@@ -81,6 +81,36 @@ void DumpCodeStatistics( ...@@ -81,6 +81,36 @@ void DumpCodeStatistics(
code_statistics.bytecode_and_metadata_size()); code_statistics.bytecode_and_metadata_size());
} }
// Dump the number of native and detached contexts.
// The result looks as follows in the Chrome trace viewer:
// ======================================
// Component object_count
// - v8
// - isolate
// - contexts
// - detached_context 10
// - native_context 20
// ======================================
void DumpContextStatistics(
base::trace_event::ProcessMemoryDump* process_memory_dump,
std::string dump_base_name,
size_t number_of_detached_contexts,
size_t number_of_native_contexts) {
std::string dump_name_prefix = dump_base_name + "/contexts";
std::string native_context_name = dump_name_prefix + "/native_context";
auto* native_context_dump =
process_memory_dump->CreateAllocatorDump(native_context_name);
native_context_dump->AddScalar(
"object_count", base::trace_event::MemoryAllocatorDump::kUnitsObjects,
number_of_native_contexts);
std::string detached_context_name = dump_name_prefix + "/detached_context";
auto* detached_context_dump =
process_memory_dump->CreateAllocatorDump(detached_context_name);
detached_context_dump->AddScalar(
"object_count", base::trace_event::MemoryAllocatorDump::kUnitsObjects,
number_of_detached_contexts);
}
} // namespace anonymous } // namespace anonymous
void V8IsolateMemoryDumpProvider::DumpHeapStatistics( void V8IsolateMemoryDumpProvider::DumpHeapStatistics(
...@@ -176,6 +206,10 @@ void V8IsolateMemoryDumpProvider::DumpHeapStatistics( ...@@ -176,6 +206,10 @@ void V8IsolateMemoryDumpProvider::DumpHeapStatistics(
system_allocator_name); system_allocator_name);
} }
DumpContextStatistics(process_memory_dump, dump_base_name,
heap_statistics.number_of_detached_contexts(),
heap_statistics.number_of_native_contexts());
// Add an empty row for the heap_spaces. This is to keep the shape of the // Add an empty row for the heap_spaces. This is to keep the shape of the
// dump stable, whether code stats are enabled or not. // dump stable, whether code stats are enabled or not.
auto* heap_spaces_dump = auto* heap_spaces_dump =
......
...@@ -52,4 +52,30 @@ TEST_F(V8MemoryDumpProviderTest, DumpStatistics) { ...@@ -52,4 +52,30 @@ TEST_F(V8MemoryDumpProviderTest, DumpStatistics) {
ASSERT_TRUE(did_dump_objects_stats); ASSERT_TRUE(did_dump_objects_stats);
} }
TEST_F(V8MemoryDumpProviderTest, DumpContextStatistics) {
base::trace_event::MemoryDumpArgs dump_args = {
base::trace_event::MemoryDumpLevelOfDetail::LIGHT};
std::unique_ptr<base::trace_event::ProcessMemoryDump> process_memory_dump(
new base::trace_event::ProcessMemoryDump(nullptr, dump_args));
instance_->isolate_memory_dump_provider_for_testing()->OnMemoryDump(
dump_args, process_memory_dump.get());
const base::trace_event::ProcessMemoryDump::AllocatorDumpsMap&
allocator_dumps = process_memory_dump->allocator_dumps();
bool did_dump_detached_contexts = false;
bool did_dump_native_contexts = false;
for (const auto& it : allocator_dumps) {
const std::string& dump_name = it.first;
if (dump_name.find("contexts/detached_context") != std::string::npos) {
did_dump_detached_contexts = true;
}
if (dump_name.find("contexts/native_context") != std::string::npos) {
did_dump_native_contexts = true;
}
}
ASSERT_TRUE(did_dump_detached_contexts);
ASSERT_TRUE(did_dump_native_contexts);
}
} // namespace gin } // namespace gin
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