| 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" |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 87 | 87 |
| 88 pmd1.reset(); | 88 pmd1.reset(); |
| 89 } | 89 } |
| 90 | 90 |
| 91 TEST(ProcessMemoryDumpTest, TakeAllDumpsFrom) { | 91 TEST(ProcessMemoryDumpTest, TakeAllDumpsFrom) { |
| 92 std::unique_ptr<TracedValue> traced_value(new TracedValue); | 92 std::unique_ptr<TracedValue> traced_value(new TracedValue); |
| 93 std::unordered_map<AllocationContext, AllocationMetrics> metrics_by_context; | 93 std::unordered_map<AllocationContext, AllocationMetrics> metrics_by_context; |
| 94 metrics_by_context[AllocationContext()] = { 1, 1 }; | 94 metrics_by_context[AllocationContext()] = { 1, 1 }; |
| 95 TraceEventMemoryOverhead overhead; | 95 TraceEventMemoryOverhead overhead; |
| 96 | 96 |
| 97 scoped_refptr<MemoryDumpSessionState> session_state = | 97 scoped_refptr<HeapProfilerSerializationState> |
| 98 new MemoryDumpSessionState; | 98 heap_profiler_serialization_state = new HeapProfilerSerializationState; |
| 99 session_state->SetStackFrameDeduplicator( | 99 heap_profiler_serialization_state->SetStackFrameDeduplicator( |
| 100 WrapUnique(new StackFrameDeduplicator)); | 100 WrapUnique(new StackFrameDeduplicator)); |
| 101 session_state->SetTypeNameDeduplicator( | 101 heap_profiler_serialization_state->SetTypeNameDeduplicator( |
| 102 WrapUnique(new TypeNameDeduplicator)); | 102 WrapUnique(new TypeNameDeduplicator)); |
| 103 std::unique_ptr<ProcessMemoryDump> pmd1( | 103 std::unique_ptr<ProcessMemoryDump> pmd1(new ProcessMemoryDump( |
| 104 new ProcessMemoryDump(session_state.get(), kDetailedDumpArgs)); | 104 heap_profiler_serialization_state.get(), kDetailedDumpArgs)); |
| 105 auto* mad1_1 = pmd1->CreateAllocatorDump("pmd1/mad1"); | 105 auto* mad1_1 = pmd1->CreateAllocatorDump("pmd1/mad1"); |
| 106 auto* mad1_2 = pmd1->CreateAllocatorDump("pmd1/mad2"); | 106 auto* mad1_2 = pmd1->CreateAllocatorDump("pmd1/mad2"); |
| 107 pmd1->AddOwnershipEdge(mad1_1->guid(), mad1_2->guid()); | 107 pmd1->AddOwnershipEdge(mad1_1->guid(), mad1_2->guid()); |
| 108 pmd1->DumpHeapUsage(metrics_by_context, overhead, "pmd1/heap_dump1"); | 108 pmd1->DumpHeapUsage(metrics_by_context, overhead, "pmd1/heap_dump1"); |
| 109 pmd1->DumpHeapUsage(metrics_by_context, overhead, "pmd1/heap_dump2"); | 109 pmd1->DumpHeapUsage(metrics_by_context, overhead, "pmd1/heap_dump2"); |
| 110 | 110 |
| 111 std::unique_ptr<ProcessMemoryDump> pmd2( | 111 std::unique_ptr<ProcessMemoryDump> pmd2(new ProcessMemoryDump( |
| 112 new ProcessMemoryDump(session_state.get(), kDetailedDumpArgs)); | 112 heap_profiler_serialization_state.get(), kDetailedDumpArgs)); |
| 113 auto* mad2_1 = pmd2->CreateAllocatorDump("pmd2/mad1"); | 113 auto* mad2_1 = pmd2->CreateAllocatorDump("pmd2/mad1"); |
| 114 auto* mad2_2 = pmd2->CreateAllocatorDump("pmd2/mad2"); | 114 auto* mad2_2 = pmd2->CreateAllocatorDump("pmd2/mad2"); |
| 115 pmd2->AddOwnershipEdge(mad2_1->guid(), mad2_2->guid()); | 115 pmd2->AddOwnershipEdge(mad2_1->guid(), mad2_2->guid()); |
| 116 pmd2->DumpHeapUsage(metrics_by_context, overhead, "pmd2/heap_dump1"); | 116 pmd2->DumpHeapUsage(metrics_by_context, overhead, "pmd2/heap_dump1"); |
| 117 pmd2->DumpHeapUsage(metrics_by_context, overhead, "pmd2/heap_dump2"); | 117 pmd2->DumpHeapUsage(metrics_by_context, overhead, "pmd2/heap_dump2"); |
| 118 | 118 |
| 119 MemoryAllocatorDumpGuid shared_mad_guid1(1); | 119 MemoryAllocatorDumpGuid shared_mad_guid1(1); |
| 120 MemoryAllocatorDumpGuid shared_mad_guid2(2); | 120 MemoryAllocatorDumpGuid shared_mad_guid2(2); |
| 121 auto* shared_mad1 = pmd2->CreateSharedGlobalAllocatorDump(shared_mad_guid1); | 121 auto* shared_mad1 = pmd2->CreateSharedGlobalAllocatorDump(shared_mad_guid1); |
| 122 auto* shared_mad2 = | 122 auto* shared_mad2 = |
| (...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 297 static_cast<char*>(base::AlignedAlloc(kVeryLargeMemorySize, page_size))); | 297 static_cast<char*>(base::AlignedAlloc(kVeryLargeMemorySize, page_size))); |
| 298 memset(memory2.get(), 0, kVeryLargeMemorySize); | 298 memset(memory2.get(), 0, kVeryLargeMemorySize); |
| 299 size_t res2 = ProcessMemoryDump::CountResidentBytes(memory2.get(), | 299 size_t res2 = ProcessMemoryDump::CountResidentBytes(memory2.get(), |
| 300 kVeryLargeMemorySize); | 300 kVeryLargeMemorySize); |
| 301 ASSERT_EQ(res2, kVeryLargeMemorySize); | 301 ASSERT_EQ(res2, kVeryLargeMemorySize); |
| 302 } | 302 } |
| 303 #endif // defined(COUNT_RESIDENT_BYTES_SUPPORTED) | 303 #endif // defined(COUNT_RESIDENT_BYTES_SUPPORTED) |
| 304 | 304 |
| 305 } // namespace trace_event | 305 } // namespace trace_event |
| 306 } // namespace base | 306 } // namespace base |
| OLD | NEW |