| 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/process/process_metrics.h" | 10 #include "base/process/process_metrics.h" |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 73 ASSERT_EQ(MemoryAllocatorDump::Flags::WEAK, shared_mad2->flags()); | 73 ASSERT_EQ(MemoryAllocatorDump::Flags::WEAK, shared_mad2->flags()); |
| 74 | 74 |
| 75 traced_value.reset(new TracedValue); | 75 traced_value.reset(new TracedValue); |
| 76 pmd1->AsValueInto(traced_value.get()); | 76 pmd1->AsValueInto(traced_value.get()); |
| 77 | 77 |
| 78 pmd1.reset(); | 78 pmd1.reset(); |
| 79 } | 79 } |
| 80 | 80 |
| 81 TEST(ProcessMemoryDumpTest, TakeAllDumpsFrom) { | 81 TEST(ProcessMemoryDumpTest, TakeAllDumpsFrom) { |
| 82 std::unique_ptr<TracedValue> traced_value(new TracedValue); | 82 std::unique_ptr<TracedValue> traced_value(new TracedValue); |
| 83 TracedValue* heap_dumps_ptr[4]; | 83 hash_map<AllocationContext, AllocationMetrics> metrics_by_context; |
| 84 std::unique_ptr<TracedValue> heap_dump; | 84 metrics_by_context[AllocationContext()] = { 1, 1 }; |
| 85 TraceEventMemoryOverhead overhead; |
| 85 | 86 |
| 86 std::unique_ptr<ProcessMemoryDump> pmd1(new ProcessMemoryDump(nullptr)); | 87 std::unique_ptr<ProcessMemoryDump> pmd1( |
| 88 new ProcessMemoryDump(new MemoryDumpSessionState())); |
| 87 auto mad1_1 = pmd1->CreateAllocatorDump("pmd1/mad1"); | 89 auto mad1_1 = pmd1->CreateAllocatorDump("pmd1/mad1"); |
| 88 auto mad1_2 = pmd1->CreateAllocatorDump("pmd1/mad2"); | 90 auto mad1_2 = pmd1->CreateAllocatorDump("pmd1/mad2"); |
| 89 pmd1->AddOwnershipEdge(mad1_1->guid(), mad1_2->guid()); | 91 pmd1->AddOwnershipEdge(mad1_1->guid(), mad1_2->guid()); |
| 90 heap_dump.reset(new TracedValue); | 92 pmd1->DumpHeapUsage(metrics_by_context, overhead, "pmd1/heap_dump1"); |
| 91 heap_dumps_ptr[0] = heap_dump.get(); | 93 pmd1->DumpHeapUsage(metrics_by_context, overhead, "pmd1/heap_dump2"); |
| 92 pmd1->AddHeapDump("pmd1/heap_dump1", std::move(heap_dump)); | |
| 93 heap_dump.reset(new TracedValue); | |
| 94 heap_dumps_ptr[1] = heap_dump.get(); | |
| 95 pmd1->AddHeapDump("pmd1/heap_dump2", std::move(heap_dump)); | |
| 96 | 94 |
| 97 std::unique_ptr<ProcessMemoryDump> pmd2(new ProcessMemoryDump(nullptr)); | 95 std::unique_ptr<ProcessMemoryDump> pmd2( |
| 96 new ProcessMemoryDump(new MemoryDumpSessionState())); |
| 98 auto mad2_1 = pmd2->CreateAllocatorDump("pmd2/mad1"); | 97 auto mad2_1 = pmd2->CreateAllocatorDump("pmd2/mad1"); |
| 99 auto mad2_2 = pmd2->CreateAllocatorDump("pmd2/mad2"); | 98 auto mad2_2 = pmd2->CreateAllocatorDump("pmd2/mad2"); |
| 100 pmd2->AddOwnershipEdge(mad2_1->guid(), mad2_2->guid()); | 99 pmd2->AddOwnershipEdge(mad2_1->guid(), mad2_2->guid()); |
| 101 heap_dump.reset(new TracedValue); | 100 pmd2->DumpHeapUsage(metrics_by_context, overhead, "pmd2/heap_dump1"); |
| 102 heap_dumps_ptr[2] = heap_dump.get(); | 101 pmd2->DumpHeapUsage(metrics_by_context, overhead, "pmd2/heap_dump2"); |
| 103 pmd2->AddHeapDump("pmd2/heap_dump1", std::move(heap_dump)); | |
| 104 heap_dump.reset(new TracedValue); | |
| 105 heap_dumps_ptr[3] = heap_dump.get(); | |
| 106 pmd2->AddHeapDump("pmd2/heap_dump2", std::move(heap_dump)); | |
| 107 | 102 |
| 108 MemoryAllocatorDumpGuid shared_mad_guid1(1); | 103 MemoryAllocatorDumpGuid shared_mad_guid1(1); |
| 109 MemoryAllocatorDumpGuid shared_mad_guid2(2); | 104 MemoryAllocatorDumpGuid shared_mad_guid2(2); |
| 110 auto shared_mad1 = pmd2->CreateSharedGlobalAllocatorDump(shared_mad_guid1); | 105 auto shared_mad1 = pmd2->CreateSharedGlobalAllocatorDump(shared_mad_guid1); |
| 111 auto shared_mad2 = | 106 auto shared_mad2 = |
| 112 pmd2->CreateWeakSharedGlobalAllocatorDump(shared_mad_guid2); | 107 pmd2->CreateWeakSharedGlobalAllocatorDump(shared_mad_guid2); |
| 113 | 108 |
| 114 pmd1->TakeAllDumpsFrom(pmd2.get()); | 109 pmd1->TakeAllDumpsFrom(pmd2.get()); |
| 115 | 110 |
| 116 // Make sure that pmd2 is empty but still usable after it has been emptied. | 111 // Make sure that pmd2 is empty but still usable after it has been emptied. |
| (...skipping 17 matching lines...) Expand all Loading... |
| 134 ASSERT_EQ(6u, pmd1->allocator_dumps().size()); | 129 ASSERT_EQ(6u, pmd1->allocator_dumps().size()); |
| 135 ASSERT_EQ(1u, pmd1->allocator_dumps().count("pmd1/mad1")); | 130 ASSERT_EQ(1u, pmd1->allocator_dumps().count("pmd1/mad1")); |
| 136 ASSERT_EQ(1u, pmd1->allocator_dumps().count("pmd1/mad2")); | 131 ASSERT_EQ(1u, pmd1->allocator_dumps().count("pmd1/mad2")); |
| 137 ASSERT_EQ(1u, pmd1->allocator_dumps().count("pmd2/mad1")); | 132 ASSERT_EQ(1u, pmd1->allocator_dumps().count("pmd2/mad1")); |
| 138 ASSERT_EQ(1u, pmd1->allocator_dumps().count("pmd1/mad2")); | 133 ASSERT_EQ(1u, pmd1->allocator_dumps().count("pmd1/mad2")); |
| 139 ASSERT_EQ(2u, pmd1->allocator_dumps_edges().size()); | 134 ASSERT_EQ(2u, pmd1->allocator_dumps_edges().size()); |
| 140 ASSERT_EQ(shared_mad1, pmd1->GetSharedGlobalAllocatorDump(shared_mad_guid1)); | 135 ASSERT_EQ(shared_mad1, pmd1->GetSharedGlobalAllocatorDump(shared_mad_guid1)); |
| 141 ASSERT_EQ(shared_mad2, pmd1->GetSharedGlobalAllocatorDump(shared_mad_guid2)); | 136 ASSERT_EQ(shared_mad2, pmd1->GetSharedGlobalAllocatorDump(shared_mad_guid2)); |
| 142 ASSERT_TRUE(MemoryAllocatorDump::Flags::WEAK & shared_mad2->flags()); | 137 ASSERT_TRUE(MemoryAllocatorDump::Flags::WEAK & shared_mad2->flags()); |
| 143 ASSERT_EQ(4u, pmd1->heap_dumps().size()); | 138 ASSERT_EQ(4u, pmd1->heap_dumps().size()); |
| 144 ASSERT_EQ(heap_dumps_ptr[0], GetHeapDump(*pmd1, "pmd1/heap_dump1")); | 139 ASSERT_TRUE(GetHeapDump(*pmd1, "pmd1/heap_dump1") != nullptr); |
| 145 ASSERT_EQ(heap_dumps_ptr[1], GetHeapDump(*pmd1, "pmd1/heap_dump2")); | 140 ASSERT_TRUE(GetHeapDump(*pmd1, "pmd1/heap_dump2") != nullptr); |
| 146 ASSERT_EQ(heap_dumps_ptr[2], GetHeapDump(*pmd1, "pmd2/heap_dump1")); | 141 ASSERT_TRUE(GetHeapDump(*pmd1, "pmd2/heap_dump1") != nullptr); |
| 147 ASSERT_EQ(heap_dumps_ptr[3], GetHeapDump(*pmd1, "pmd2/heap_dump2")); | 142 ASSERT_TRUE(GetHeapDump(*pmd1, "pmd2/heap_dump2") != nullptr); |
| 148 | 143 |
| 149 // Check that calling AsValueInto() doesn't cause a crash. | 144 // Check that calling AsValueInto() doesn't cause a crash. |
| 150 traced_value.reset(new TracedValue); | 145 traced_value.reset(new TracedValue); |
| 151 pmd1->AsValueInto(traced_value.get()); | 146 pmd1->AsValueInto(traced_value.get()); |
| 152 | 147 |
| 153 pmd1.reset(); | 148 pmd1.reset(); |
| 154 } | 149 } |
| 155 | 150 |
| 156 TEST(ProcessMemoryDumpTest, Suballocations) { | 151 TEST(ProcessMemoryDumpTest, Suballocations) { |
| 157 std::unique_ptr<ProcessMemoryDump> pmd(new ProcessMemoryDump(nullptr)); | 152 std::unique_ptr<ProcessMemoryDump> pmd(new ProcessMemoryDump(nullptr)); |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 239 static_cast<char*>(base::AlignedAlloc(kVeryLargeMemorySize, page_size))); | 234 static_cast<char*>(base::AlignedAlloc(kVeryLargeMemorySize, page_size))); |
| 240 memset(memory2.get(), 0, kVeryLargeMemorySize); | 235 memset(memory2.get(), 0, kVeryLargeMemorySize); |
| 241 size_t res2 = ProcessMemoryDump::CountResidentBytes(memory2.get(), | 236 size_t res2 = ProcessMemoryDump::CountResidentBytes(memory2.get(), |
| 242 kVeryLargeMemorySize); | 237 kVeryLargeMemorySize); |
| 243 ASSERT_EQ(res2, kVeryLargeMemorySize); | 238 ASSERT_EQ(res2, kVeryLargeMemorySize); |
| 244 } | 239 } |
| 245 #endif // defined(COUNT_RESIDENT_BYTES_SUPPORTED) | 240 #endif // defined(COUNT_RESIDENT_BYTES_SUPPORTED) |
| 246 | 241 |
| 247 } // namespace trace_event | 242 } // namespace trace_event |
| 248 } // namespace base | 243 } // namespace base |
| OLD | NEW |