| 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/process/process_metrics.h" | 11 #include "base/process/process_metrics.h" |
| 11 #include "base/trace_event/memory_allocator_dump_guid.h" | 12 #include "base/trace_event/memory_allocator_dump_guid.h" |
| 12 #include "base/trace_event/trace_event_argument.h" | 13 #include "base/trace_event/trace_event_argument.h" |
| 13 #include "testing/gtest/include/gtest/gtest.h" | 14 #include "testing/gtest/include/gtest/gtest.h" |
| 14 | 15 |
| 15 namespace base { | 16 namespace base { |
| 16 namespace trace_event { | 17 namespace trace_event { |
| 17 | 18 |
| 18 namespace { | 19 namespace { |
| 19 TracedValue* GetHeapDump(const ProcessMemoryDump& pmd, const char* name) { | 20 TracedValue* GetHeapDump(const ProcessMemoryDump& pmd, const char* name) { |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 77 | 78 |
| 78 pmd1.reset(); | 79 pmd1.reset(); |
| 79 } | 80 } |
| 80 | 81 |
| 81 TEST(ProcessMemoryDumpTest, TakeAllDumpsFrom) { | 82 TEST(ProcessMemoryDumpTest, TakeAllDumpsFrom) { |
| 82 std::unique_ptr<TracedValue> traced_value(new TracedValue); | 83 std::unique_ptr<TracedValue> traced_value(new TracedValue); |
| 83 hash_map<AllocationContext, AllocationMetrics> metrics_by_context; | 84 hash_map<AllocationContext, AllocationMetrics> metrics_by_context; |
| 84 metrics_by_context[AllocationContext()] = { 1, 1 }; | 85 metrics_by_context[AllocationContext()] = { 1, 1 }; |
| 85 TraceEventMemoryOverhead overhead; | 86 TraceEventMemoryOverhead overhead; |
| 86 | 87 |
| 88 scoped_refptr<MemoryDumpSessionState> session_state = |
| 89 new MemoryDumpSessionState; |
| 90 session_state->SetStackFrameDeduplicator( |
| 91 WrapUnique(new StackFrameDeduplicator)); |
| 92 session_state->SetTypeNameDeduplicator( |
| 93 WrapUnique(new TypeNameDeduplicator)); |
| 87 std::unique_ptr<ProcessMemoryDump> pmd1( | 94 std::unique_ptr<ProcessMemoryDump> pmd1( |
| 88 new ProcessMemoryDump(new MemoryDumpSessionState())); | 95 new ProcessMemoryDump(session_state.get())); |
| 89 auto mad1_1 = pmd1->CreateAllocatorDump("pmd1/mad1"); | 96 auto mad1_1 = pmd1->CreateAllocatorDump("pmd1/mad1"); |
| 90 auto mad1_2 = pmd1->CreateAllocatorDump("pmd1/mad2"); | 97 auto mad1_2 = pmd1->CreateAllocatorDump("pmd1/mad2"); |
| 91 pmd1->AddOwnershipEdge(mad1_1->guid(), mad1_2->guid()); | 98 pmd1->AddOwnershipEdge(mad1_1->guid(), mad1_2->guid()); |
| 92 pmd1->DumpHeapUsage(metrics_by_context, overhead, "pmd1/heap_dump1"); | 99 pmd1->DumpHeapUsage(metrics_by_context, overhead, "pmd1/heap_dump1"); |
| 93 pmd1->DumpHeapUsage(metrics_by_context, overhead, "pmd1/heap_dump2"); | 100 pmd1->DumpHeapUsage(metrics_by_context, overhead, "pmd1/heap_dump2"); |
| 94 | 101 |
| 95 std::unique_ptr<ProcessMemoryDump> pmd2( | 102 std::unique_ptr<ProcessMemoryDump> pmd2( |
| 96 new ProcessMemoryDump(new MemoryDumpSessionState())); | 103 new ProcessMemoryDump(session_state.get())); |
| 97 auto mad2_1 = pmd2->CreateAllocatorDump("pmd2/mad1"); | 104 auto mad2_1 = pmd2->CreateAllocatorDump("pmd2/mad1"); |
| 98 auto mad2_2 = pmd2->CreateAllocatorDump("pmd2/mad2"); | 105 auto mad2_2 = pmd2->CreateAllocatorDump("pmd2/mad2"); |
| 99 pmd2->AddOwnershipEdge(mad2_1->guid(), mad2_2->guid()); | 106 pmd2->AddOwnershipEdge(mad2_1->guid(), mad2_2->guid()); |
| 100 pmd2->DumpHeapUsage(metrics_by_context, overhead, "pmd2/heap_dump1"); | 107 pmd2->DumpHeapUsage(metrics_by_context, overhead, "pmd2/heap_dump1"); |
| 101 pmd2->DumpHeapUsage(metrics_by_context, overhead, "pmd2/heap_dump2"); | 108 pmd2->DumpHeapUsage(metrics_by_context, overhead, "pmd2/heap_dump2"); |
| 102 | 109 |
| 103 MemoryAllocatorDumpGuid shared_mad_guid1(1); | 110 MemoryAllocatorDumpGuid shared_mad_guid1(1); |
| 104 MemoryAllocatorDumpGuid shared_mad_guid2(2); | 111 MemoryAllocatorDumpGuid shared_mad_guid2(2); |
| 105 auto shared_mad1 = pmd2->CreateSharedGlobalAllocatorDump(shared_mad_guid1); | 112 auto shared_mad1 = pmd2->CreateSharedGlobalAllocatorDump(shared_mad_guid1); |
| 106 auto shared_mad2 = | 113 auto shared_mad2 = |
| (...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 234 static_cast<char*>(base::AlignedAlloc(kVeryLargeMemorySize, page_size))); | 241 static_cast<char*>(base::AlignedAlloc(kVeryLargeMemorySize, page_size))); |
| 235 memset(memory2.get(), 0, kVeryLargeMemorySize); | 242 memset(memory2.get(), 0, kVeryLargeMemorySize); |
| 236 size_t res2 = ProcessMemoryDump::CountResidentBytes(memory2.get(), | 243 size_t res2 = ProcessMemoryDump::CountResidentBytes(memory2.get(), |
| 237 kVeryLargeMemorySize); | 244 kVeryLargeMemorySize); |
| 238 ASSERT_EQ(res2, kVeryLargeMemorySize); | 245 ASSERT_EQ(res2, kVeryLargeMemorySize); |
| 239 } | 246 } |
| 240 #endif // defined(COUNT_RESIDENT_BYTES_SUPPORTED) | 247 #endif // defined(COUNT_RESIDENT_BYTES_SUPPORTED) |
| 241 | 248 |
| 242 } // namespace trace_event | 249 } // namespace trace_event |
| 243 } // namespace base | 250 } // namespace base |
| OLD | NEW |