Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "base/trace_event/process_memory_dump.h" | 5 #include "base/trace_event/process_memory_dump.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include "base/memory/aligned_memory.h" | 9 #include "base/memory/aligned_memory.h" |
| 10 #include "base/memory/ptr_util.h" | 10 #include "base/memory/ptr_util.h" |
| 11 #include "base/process/process_metrics.h" | 11 #include "base/process/process_metrics.h" |
| 12 #include "base/trace_event/heap_profiler_allocation_register.h" | |
| 12 #include "base/trace_event/memory_allocator_dump_guid.h" | 13 #include "base/trace_event/memory_allocator_dump_guid.h" |
| 13 #include "base/trace_event/memory_infra_background_whitelist.h" | 14 #include "base/trace_event/memory_infra_background_whitelist.h" |
| 14 #include "base/trace_event/trace_event_argument.h" | 15 #include "base/trace_event/trace_event_argument.h" |
| 15 #include "testing/gtest/include/gtest/gtest.h" | 16 #include "testing/gtest/include/gtest/gtest.h" |
| 16 | 17 |
| 17 namespace base { | 18 namespace base { |
| 18 namespace trace_event { | 19 namespace trace_event { |
| 19 | 20 |
| 20 namespace { | 21 namespace { |
| 21 | 22 |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 83 ASSERT_EQ(MemoryAllocatorDump::Flags::WEAK, shared_mad2->flags()); | 84 ASSERT_EQ(MemoryAllocatorDump::Flags::WEAK, shared_mad2->flags()); |
| 84 | 85 |
| 85 traced_value.reset(new TracedValue); | 86 traced_value.reset(new TracedValue); |
| 86 pmd1->AsValueInto(traced_value.get()); | 87 pmd1->AsValueInto(traced_value.get()); |
| 87 | 88 |
| 88 pmd1.reset(); | 89 pmd1.reset(); |
| 89 } | 90 } |
| 90 | 91 |
| 91 TEST(ProcessMemoryDumpTest, TakeAllDumpsFrom) { | 92 TEST(ProcessMemoryDumpTest, TakeAllDumpsFrom) { |
| 92 std::unique_ptr<TracedValue> traced_value(new TracedValue); | 93 std::unique_ptr<TracedValue> traced_value(new TracedValue); |
| 93 hash_map<AllocationContext, AllocationMetrics> metrics_by_context; | 94 AllocationRegister allocation_register(10, 10); |
| 94 metrics_by_context[AllocationContext()] = { 1, 1 }; | 95 allocation_register.Insert("", 100, AllocationContext()); |
| 95 TraceEventMemoryOverhead overhead; | |
| 96 | 96 |
| 97 scoped_refptr<MemoryDumpSessionState> session_state = | 97 scoped_refptr<MemoryDumpSessionState> session_state = |
| 98 new MemoryDumpSessionState; | 98 new MemoryDumpSessionState; |
| 99 session_state->SetStackFrameDeduplicator( | 99 session_state->CreateDeduplicators(); |
| 100 WrapUnique(new StackFrameDeduplicator)); | |
| 101 session_state->SetTypeNameDeduplicator( | |
| 102 WrapUnique(new TypeNameDeduplicator)); | |
| 103 std::unique_ptr<ProcessMemoryDump> pmd1( | 100 std::unique_ptr<ProcessMemoryDump> pmd1( |
| 104 new ProcessMemoryDump(session_state.get(), kDetailedDumpArgs)); | 101 new ProcessMemoryDump(session_state.get(), kDetailedDumpArgs)); |
| 105 auto* mad1_1 = pmd1->CreateAllocatorDump("pmd1/mad1"); | 102 auto* mad1_1 = pmd1->CreateAllocatorDump("pmd1/mad1"); |
| 106 auto* mad1_2 = pmd1->CreateAllocatorDump("pmd1/mad2"); | 103 auto* mad1_2 = pmd1->CreateAllocatorDump("pmd1/mad2"); |
| 107 pmd1->AddOwnershipEdge(mad1_1->guid(), mad1_2->guid()); | 104 pmd1->AddOwnershipEdge(mad1_1->guid(), mad1_2->guid()); |
| 108 pmd1->DumpHeapUsage(metrics_by_context, overhead, "pmd1/heap_dump1"); | 105 pmd1->DumpHeapUsage(allocation_register, "pmd1/heap_dump1"); |
| 109 pmd1->DumpHeapUsage(metrics_by_context, overhead, "pmd1/heap_dump2"); | 106 pmd1->DumpHeapUsage(allocation_register, "pmd1/heap_dump2"); |
| 110 | 107 |
| 111 std::unique_ptr<ProcessMemoryDump> pmd2( | 108 std::unique_ptr<ProcessMemoryDump> pmd2( |
| 112 new ProcessMemoryDump(session_state.get(), kDetailedDumpArgs)); | 109 new ProcessMemoryDump(session_state.get(), kDetailedDumpArgs)); |
| 113 auto* mad2_1 = pmd2->CreateAllocatorDump("pmd2/mad1"); | 110 auto* mad2_1 = pmd2->CreateAllocatorDump("pmd2/mad1"); |
| 114 auto* mad2_2 = pmd2->CreateAllocatorDump("pmd2/mad2"); | 111 auto* mad2_2 = pmd2->CreateAllocatorDump("pmd2/mad2"); |
| 115 pmd2->AddOwnershipEdge(mad2_1->guid(), mad2_2->guid()); | 112 pmd2->AddOwnershipEdge(mad2_1->guid(), mad2_2->guid()); |
| 116 pmd2->DumpHeapUsage(metrics_by_context, overhead, "pmd2/heap_dump1"); | 113 pmd2->DumpHeapUsage(allocation_register, "pmd2/heap_dump1"); |
| 117 pmd2->DumpHeapUsage(metrics_by_context, overhead, "pmd2/heap_dump2"); | 114 pmd2->DumpHeapUsage(allocation_register, "pmd2/heap_dump2"); |
| 118 | 115 |
| 119 MemoryAllocatorDumpGuid shared_mad_guid1(1); | 116 MemoryAllocatorDumpGuid shared_mad_guid1(1); |
| 120 MemoryAllocatorDumpGuid shared_mad_guid2(2); | 117 MemoryAllocatorDumpGuid shared_mad_guid2(2); |
| 121 auto* shared_mad1 = pmd2->CreateSharedGlobalAllocatorDump(shared_mad_guid1); | 118 auto* shared_mad1 = pmd2->CreateSharedGlobalAllocatorDump(shared_mad_guid1); |
| 122 auto* shared_mad2 = | 119 auto* shared_mad2 = |
| 123 pmd2->CreateWeakSharedGlobalAllocatorDump(shared_mad_guid2); | 120 pmd2->CreateWeakSharedGlobalAllocatorDump(shared_mad_guid2); |
| 124 | 121 |
| 122 LOG(INFO) << "About to merge"; | |
|
ssid
2017/03/16 02:09:20
Isn't the test logs going to help with debugging h
DmitrySkiba
2017/03/17 04:01:38
Done. Thanks for noticing!
| |
| 123 | |
| 125 pmd1->TakeAllDumpsFrom(pmd2.get()); | 124 pmd1->TakeAllDumpsFrom(pmd2.get()); |
| 126 | 125 |
| 127 // Make sure that pmd2 is empty but still usable after it has been emptied. | 126 // Make sure that pmd2 is empty but still usable after it has been emptied. |
| 128 ASSERT_TRUE(pmd2->allocator_dumps().empty()); | 127 ASSERT_TRUE(pmd2->allocator_dumps().empty()); |
| 129 ASSERT_TRUE(pmd2->allocator_dumps_edges().empty()); | 128 ASSERT_TRUE(pmd2->allocator_dumps_edges().empty()); |
| 130 ASSERT_TRUE(pmd2->heap_dumps().empty()); | 129 ASSERT_TRUE(pmd2->heap_dumps().empty()); |
| 131 pmd2->CreateAllocatorDump("pmd2/this_mad_stays_with_pmd2"); | 130 pmd2->CreateAllocatorDump("pmd2/this_mad_stays_with_pmd2"); |
| 132 ASSERT_EQ(1u, pmd2->allocator_dumps().size()); | 131 ASSERT_EQ(1u, pmd2->allocator_dumps().size()); |
| 133 ASSERT_EQ(1u, pmd2->allocator_dumps().count("pmd2/this_mad_stays_with_pmd2")); | 132 ASSERT_EQ(1u, pmd2->allocator_dumps().count("pmd2/this_mad_stays_with_pmd2")); |
| 134 pmd2->AddOwnershipEdge(MemoryAllocatorDumpGuid(42), | 133 pmd2->AddOwnershipEdge(MemoryAllocatorDumpGuid(42), |
| 135 MemoryAllocatorDumpGuid(4242)); | 134 MemoryAllocatorDumpGuid(4242)); |
| 136 | 135 |
| 137 // Check that calling AsValueInto() doesn't cause a crash. | 136 // Check that calling AsValueInto() doesn't cause a crash. |
| 138 pmd2->AsValueInto(traced_value.get()); | 137 pmd2->AsValueInto(traced_value.get()); |
| 139 | 138 |
| 140 // Free the |pmd2| to check that the memory ownership of the two MAD(s) | 139 // Free the |pmd2| to check that the memory ownership of the two MAD(s) |
| 141 // has been transferred to |pmd1|. | 140 // has been transferred to |pmd1|. |
| 142 pmd2.reset(); | 141 pmd2.reset(); |
| 143 | 142 |
| 144 // Now check that |pmd1| has been effectively merged. | 143 // Now check that |pmd1| has been effectively merged. |
| 145 ASSERT_EQ(6u, pmd1->allocator_dumps().size()); | 144 // Note that DumpHeapUsage() adds an implicit dump for AllocationRegister's |
| 145 // memory overhead. | |
|
ssid
2017/03/16 02:09:20
Can you add asserts that these overhead dumps exis
DmitrySkiba
2017/03/17 04:01:38
That's an interesting test, but I don't think it's
| |
| 146 ASSERT_EQ(10u, pmd1->allocator_dumps().size()); | |
| 146 ASSERT_EQ(1u, pmd1->allocator_dumps().count("pmd1/mad1")); | 147 ASSERT_EQ(1u, pmd1->allocator_dumps().count("pmd1/mad1")); |
| 147 ASSERT_EQ(1u, pmd1->allocator_dumps().count("pmd1/mad2")); | 148 ASSERT_EQ(1u, pmd1->allocator_dumps().count("pmd1/mad2")); |
| 148 ASSERT_EQ(1u, pmd1->allocator_dumps().count("pmd2/mad1")); | 149 ASSERT_EQ(1u, pmd1->allocator_dumps().count("pmd2/mad1")); |
| 149 ASSERT_EQ(1u, pmd1->allocator_dumps().count("pmd1/mad2")); | 150 ASSERT_EQ(1u, pmd1->allocator_dumps().count("pmd1/mad2")); |
| 150 ASSERT_EQ(2u, pmd1->allocator_dumps_edges().size()); | 151 ASSERT_EQ(2u, pmd1->allocator_dumps_edges().size()); |
| 151 ASSERT_EQ(shared_mad1, pmd1->GetSharedGlobalAllocatorDump(shared_mad_guid1)); | 152 ASSERT_EQ(shared_mad1, pmd1->GetSharedGlobalAllocatorDump(shared_mad_guid1)); |
| 152 ASSERT_EQ(shared_mad2, pmd1->GetSharedGlobalAllocatorDump(shared_mad_guid2)); | 153 ASSERT_EQ(shared_mad2, pmd1->GetSharedGlobalAllocatorDump(shared_mad_guid2)); |
| 153 ASSERT_TRUE(MemoryAllocatorDump::Flags::WEAK & shared_mad2->flags()); | 154 ASSERT_TRUE(MemoryAllocatorDump::Flags::WEAK & shared_mad2->flags()); |
| 154 ASSERT_EQ(4u, pmd1->heap_dumps().size()); | 155 ASSERT_EQ(4u, pmd1->heap_dumps().size()); |
| 155 ASSERT_TRUE(GetHeapDump(*pmd1, "pmd1/heap_dump1") != nullptr); | 156 ASSERT_TRUE(GetHeapDump(*pmd1, "pmd1/heap_dump1") != nullptr); |
| (...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 297 static_cast<char*>(base::AlignedAlloc(kVeryLargeMemorySize, page_size))); | 298 static_cast<char*>(base::AlignedAlloc(kVeryLargeMemorySize, page_size))); |
| 298 memset(memory2.get(), 0, kVeryLargeMemorySize); | 299 memset(memory2.get(), 0, kVeryLargeMemorySize); |
| 299 size_t res2 = ProcessMemoryDump::CountResidentBytes(memory2.get(), | 300 size_t res2 = ProcessMemoryDump::CountResidentBytes(memory2.get(), |
| 300 kVeryLargeMemorySize); | 301 kVeryLargeMemorySize); |
| 301 ASSERT_EQ(res2, kVeryLargeMemorySize); | 302 ASSERT_EQ(res2, kVeryLargeMemorySize); |
| 302 } | 303 } |
| 303 #endif // defined(COUNT_RESIDENT_BYTES_SUPPORTED) | 304 #endif // defined(COUNT_RESIDENT_BYTES_SUPPORTED) |
| 304 | 305 |
| 305 } // namespace trace_event | 306 } // namespace trace_event |
| 306 } // namespace base | 307 } // namespace base |
| OLD | NEW |