Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(46)

Side by Side Diff: base/trace_event/process_memory_dump_unittest.cc

Issue 2650863003: [tracing] Switch to new heap dump format. (Closed)
Patch Set: DCHECK for continuous mode Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/memory_allocator_dump_guid.h" 12 #include "base/trace_event/memory_allocator_dump_guid.h"
13 #include "base/trace_event/memory_infra_background_whitelist.h" 13 #include "base/trace_event/memory_infra_background_whitelist.h"
14 #include "base/trace_event/trace_event_argument.h" 14 #include "base/trace_event/trace_event_argument.h"
15 #include "testing/gtest/include/gtest/gtest.h" 15 #include "testing/gtest/include/gtest/gtest.h"
16 16
17 namespace base { 17 namespace base {
18 namespace trace_event { 18 namespace trace_event {
19 19
20 namespace { 20 namespace {
21 21
22 const MemoryDumpArgs kDetailedDumpArgs = {MemoryDumpLevelOfDetail::DETAILED}; 22 const MemoryDumpArgs kDetailedDumpArgs = {MemoryDumpLevelOfDetail::DETAILED};
23 const char* const kTestDumpNameWhitelist[] = { 23 const char* const kTestDumpNameWhitelist[] = {
24 "Whitelisted/TestName", "Whitelisted/TestName_0x?", 24 "Whitelisted/TestName", "Whitelisted/TestName_0x?",
25 "Whitelisted/0x?/TestName", nullptr}; 25 "Whitelisted/0x?/TestName", nullptr};
26 26
27 #if 0
Primiano Tucci (use gerrit) 2017/03/09 11:47:45 uh? I think this is a leftover
DmitrySkiba 2017/03/14 22:12:48 Done.
27 TracedValue* GetHeapDump(const ProcessMemoryDump& pmd, const char* name) { 28 TracedValue* GetHeapDump(const ProcessMemoryDump& pmd, const char* name) {
28 auto it = pmd.heap_dumps().find(name); 29 auto it = pmd.heap_dumps().find(name);
29 return it == pmd.heap_dumps().end() ? nullptr : it->second.get(); 30 return it == pmd.heap_dumps().end() ? nullptr : it->second.get();
30 } 31 }
32 #endif
31 33
32 } // namespace 34 } // namespace
33 35
34 TEST(ProcessMemoryDumpTest, Clear) { 36 TEST(ProcessMemoryDumpTest, Clear) {
35 std::unique_ptr<ProcessMemoryDump> pmd1( 37 std::unique_ptr<ProcessMemoryDump> pmd1(
36 new ProcessMemoryDump(nullptr, kDetailedDumpArgs)); 38 new ProcessMemoryDump(nullptr, kDetailedDumpArgs));
37 pmd1->CreateAllocatorDump("mad1"); 39 pmd1->CreateAllocatorDump("mad1");
38 pmd1->CreateAllocatorDump("mad2"); 40 pmd1->CreateAllocatorDump("mad2");
39 ASSERT_FALSE(pmd1->allocator_dumps().empty()); 41 ASSERT_FALSE(pmd1->allocator_dumps().empty());
40 42
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
81 ASSERT_EQ(MemoryAllocatorDump::Flags::DEFAULT, shared_mad1->flags()); 83 ASSERT_EQ(MemoryAllocatorDump::Flags::DEFAULT, shared_mad1->flags());
82 ASSERT_EQ(shared_mad2, pmd1->GetSharedGlobalAllocatorDump(shared_mad_guid2)); 84 ASSERT_EQ(shared_mad2, pmd1->GetSharedGlobalAllocatorDump(shared_mad_guid2));
83 ASSERT_EQ(MemoryAllocatorDump::Flags::WEAK, shared_mad2->flags()); 85 ASSERT_EQ(MemoryAllocatorDump::Flags::WEAK, shared_mad2->flags());
84 86
85 traced_value.reset(new TracedValue); 87 traced_value.reset(new TracedValue);
86 pmd1->AsValueInto(traced_value.get()); 88 pmd1->AsValueInto(traced_value.get());
87 89
88 pmd1.reset(); 90 pmd1.reset();
89 } 91 }
90 92
93 #if 0
Primiano Tucci (use gerrit) 2017/03/09 11:47:45 ditto
DmitrySkiba 2017/03/14 22:12:48 Done.
91 TEST(ProcessMemoryDumpTest, TakeAllDumpsFrom) { 94 TEST(ProcessMemoryDumpTest, TakeAllDumpsFrom) {
92 std::unique_ptr<TracedValue> traced_value(new TracedValue); 95 std::unique_ptr<TracedValue> traced_value(new TracedValue);
93 hash_map<AllocationContext, AllocationMetrics> metrics_by_context; 96 hash_map<AllocationContext, AllocationMetrics> metrics_by_context;
94 metrics_by_context[AllocationContext()] = { 1, 1 }; 97 metrics_by_context[AllocationContext()] = { 1, 1 };
95 TraceEventMemoryOverhead overhead; 98 TraceEventMemoryOverhead overhead;
96 99
97 scoped_refptr<MemoryDumpSessionState> session_state = 100 scoped_refptr<MemoryDumpSessionState> session_state =
98 new MemoryDumpSessionState; 101 new MemoryDumpSessionState;
99 session_state->SetStackFrameDeduplicator( 102 session_state->SetStackFrameDeduplicator(
100 WrapUnique(new StackFrameDeduplicator)); 103 WrapUnique(new StackFrameDeduplicator));
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
156 ASSERT_TRUE(GetHeapDump(*pmd1, "pmd1/heap_dump2") != nullptr); 159 ASSERT_TRUE(GetHeapDump(*pmd1, "pmd1/heap_dump2") != nullptr);
157 ASSERT_TRUE(GetHeapDump(*pmd1, "pmd2/heap_dump1") != nullptr); 160 ASSERT_TRUE(GetHeapDump(*pmd1, "pmd2/heap_dump1") != nullptr);
158 ASSERT_TRUE(GetHeapDump(*pmd1, "pmd2/heap_dump2") != nullptr); 161 ASSERT_TRUE(GetHeapDump(*pmd1, "pmd2/heap_dump2") != nullptr);
159 162
160 // Check that calling AsValueInto() doesn't cause a crash. 163 // Check that calling AsValueInto() doesn't cause a crash.
161 traced_value.reset(new TracedValue); 164 traced_value.reset(new TracedValue);
162 pmd1->AsValueInto(traced_value.get()); 165 pmd1->AsValueInto(traced_value.get());
163 166
164 pmd1.reset(); 167 pmd1.reset();
165 } 168 }
169 #endif
166 170
167 TEST(ProcessMemoryDumpTest, Suballocations) { 171 TEST(ProcessMemoryDumpTest, Suballocations) {
168 std::unique_ptr<ProcessMemoryDump> pmd( 172 std::unique_ptr<ProcessMemoryDump> pmd(
169 new ProcessMemoryDump(nullptr, kDetailedDumpArgs)); 173 new ProcessMemoryDump(nullptr, kDetailedDumpArgs));
170 const std::string allocator_dump_name = "fakealloc/allocated_objects"; 174 const std::string allocator_dump_name = "fakealloc/allocated_objects";
171 pmd->CreateAllocatorDump(allocator_dump_name); 175 pmd->CreateAllocatorDump(allocator_dump_name);
172 176
173 // Create one allocation with an auto-assigned guid and mark it as a 177 // Create one allocation with an auto-assigned guid and mark it as a
174 // suballocation of "fakealloc/allocated_objects". 178 // suballocation of "fakealloc/allocated_objects".
175 auto* pic1_dump = pmd->CreateAllocatorDump("picturemanager/picture1"); 179 auto* pic1_dump = pmd->CreateAllocatorDump("picturemanager/picture1");
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
297 static_cast<char*>(base::AlignedAlloc(kVeryLargeMemorySize, page_size))); 301 static_cast<char*>(base::AlignedAlloc(kVeryLargeMemorySize, page_size)));
298 memset(memory2.get(), 0, kVeryLargeMemorySize); 302 memset(memory2.get(), 0, kVeryLargeMemorySize);
299 size_t res2 = ProcessMemoryDump::CountResidentBytes(memory2.get(), 303 size_t res2 = ProcessMemoryDump::CountResidentBytes(memory2.get(),
300 kVeryLargeMemorySize); 304 kVeryLargeMemorySize);
301 ASSERT_EQ(res2, kVeryLargeMemorySize); 305 ASSERT_EQ(res2, kVeryLargeMemorySize);
302 } 306 }
303 #endif // defined(COUNT_RESIDENT_BYTES_SUPPORTED) 307 #endif // defined(COUNT_RESIDENT_BYTES_SUPPORTED)
304 308
305 } // namespace trace_event 309 } // namespace trace_event
306 } // namespace base 310 } // namespace base
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698