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

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

Issue 1124763003: Update from https://crrev.com/327068 (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: update nacl, buildtools, fix display_change_notifier_unittest Created 5 years, 7 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/memory_allocator_dump.h" 5 #include "base/trace_event/memory_allocator_dump.h"
6 6
7 #include "base/trace_event/memory_dump_provider.h" 7 #include "base/trace_event/memory_dump_provider.h"
8 #include "base/trace_event/memory_dump_session_state.h"
8 #include "base/trace_event/process_memory_dump.h" 9 #include "base/trace_event/process_memory_dump.h"
10 #include "base/trace_event/trace_event_argument.h"
9 #include "testing/gtest/include/gtest/gtest.h" 11 #include "testing/gtest/include/gtest/gtest.h"
10 12
11 namespace base { 13 namespace base {
12 namespace trace_event { 14 namespace trace_event {
13 15
14 namespace { 16 namespace {
17
15 class FakeMemoryAllocatorDumpProvider : public MemoryDumpProvider { 18 class FakeMemoryAllocatorDumpProvider : public MemoryDumpProvider {
16 public: 19 public:
17 FakeMemoryAllocatorDumpProvider() { 20 FakeMemoryAllocatorDumpProvider() {
18 DeclareAllocatorAttribute({"attr1", "count"}); 21 DeclareAllocatorAttribute("foobar_allocator", "attr1", "count");
19 DeclareAllocatorAttribute({"attr2", "bytes"}); 22 DeclareAllocatorAttribute("foobar_allocator", "attr2", "bytes");
20 } 23 }
21 24
22 bool DumpInto(ProcessMemoryDump* pmd) override { 25 bool DumpInto(ProcessMemoryDump* pmd) override {
23 MemoryAllocatorDump* mad_foo = pmd->CreateAllocatorDump("foo"); 26 MemoryAllocatorDump* root_heap = pmd->CreateAllocatorDump(
24 mad_foo->set_physical_size_in_bytes(4096); 27 "foobar_allocator", MemoryAllocatorDump::kRootHeap);
25 mad_foo->set_allocated_objects_count(42); 28 root_heap->set_physical_size_in_bytes(4096);
26 mad_foo->set_allocated_objects_size_in_bytes(1000); 29 root_heap->set_allocated_objects_count(42);
27 mad_foo->SetExtraAttribute("attr1", 1234); 30 root_heap->set_allocated_objects_size_in_bytes(1000);
28 mad_foo->SetExtraAttribute("attr2", 99); 31 root_heap->SetAttribute("attr1", 1234);
32 root_heap->SetAttribute("attr2", 99);
29 33
30 MemoryAllocatorDump* mad_bar = pmd->CreateAllocatorDump("foo/bar", mad_foo); 34 MemoryAllocatorDump* sub_heap =
31 mad_bar->set_physical_size_in_bytes(1); 35 pmd->CreateAllocatorDump("foobar_allocator", "sub_heap");
32 mad_bar->set_allocated_objects_count(2); 36 sub_heap->set_physical_size_in_bytes(1);
33 mad_bar->set_allocated_objects_size_in_bytes(3); 37 sub_heap->set_allocated_objects_count(2);
38 sub_heap->set_allocated_objects_size_in_bytes(3);
34 39
35 pmd->CreateAllocatorDump("baz"); 40 pmd->CreateAllocatorDump("foobar_allocator", "sub_heap/empty");
36 // Leave the rest of |baz| deliberately uninitialized, to check that 41 // Leave the rest of sub heap deliberately uninitialized, to check that
37 // CreateAllocatorDump returns a properly zero-initialized object. 42 // CreateAllocatorDump returns a properly zero-initialized object.
38 43
39 return true; 44 return true;
40 } 45 }
41 46
42 const char* GetFriendlyName() const override { return "mock_allocator"; } 47 const char* GetFriendlyName() const override { return "FooBar Allocator"; }
43 }; 48 };
44 } // namespace 49 } // namespace
45 50
46 TEST(MemoryAllocatorDumpTest, DumpIntoProcessMemoryDump) { 51 TEST(MemoryAllocatorDumpTest, DumpIntoProcessMemoryDump) {
47 FakeMemoryAllocatorDumpProvider fmadp; 52 FakeMemoryAllocatorDumpProvider fmadp;
48 ProcessMemoryDump pmd; 53 ProcessMemoryDump pmd(make_scoped_refptr(new MemoryDumpSessionState()));
54 pmd.session_state()->allocators_attributes_type_info.Update(
55 fmadp.allocator_attributes_type_info());
49 56
50 fmadp.DumpInto(&pmd); 57 fmadp.DumpInto(&pmd);
51 58
52 ASSERT_EQ(3u, pmd.allocator_dumps().size()); 59 ASSERT_EQ(3u, pmd.allocator_dumps().size());
53 60
54 const MemoryAllocatorDump* mad_foo = pmd.GetAllocatorDump("foo"); 61 const MemoryAllocatorDump* root_heap =
55 ASSERT_NE(nullptr, mad_foo); 62 pmd.GetAllocatorDump("foobar_allocator", MemoryAllocatorDump::kRootHeap);
56 EXPECT_EQ("foo", mad_foo->name()); 63 ASSERT_NE(nullptr, root_heap);
57 ASSERT_EQ(nullptr, mad_foo->parent()); 64 EXPECT_EQ("foobar_allocator", root_heap->allocator_name());
58 EXPECT_EQ(4096u, mad_foo->physical_size_in_bytes()); 65 EXPECT_EQ("", root_heap->heap_name());
59 EXPECT_EQ(42u, mad_foo->allocated_objects_count()); 66 EXPECT_NE("", root_heap->GetAbsoluteName());
60 EXPECT_EQ(1000u, mad_foo->allocated_objects_size_in_bytes()); 67 EXPECT_EQ(4096u, root_heap->physical_size_in_bytes());
68 EXPECT_EQ(42u, root_heap->allocated_objects_count());
69 EXPECT_EQ(1000u, root_heap->allocated_objects_size_in_bytes());
61 70
62 // Check the extra attributes of |mad_foo|. 71 // Check the extra attributes of |root_heap|.
63 EXPECT_EQ(1234, mad_foo->GetExtraIntegerAttribute("attr1")); 72 EXPECT_EQ(1234, root_heap->GetIntegerAttribute("attr1"));
64 EXPECT_EQ(99, mad_foo->GetExtraIntegerAttribute("attr2")); 73 EXPECT_EQ(99, root_heap->GetIntegerAttribute("attr2"));
65 74
66 const MemoryAllocatorDump* mad_bar = pmd.GetAllocatorDump("foo/bar"); 75 const MemoryAllocatorDump* sub_heap =
67 ASSERT_NE(nullptr, mad_bar); 76 pmd.GetAllocatorDump("foobar_allocator", "sub_heap");
68 EXPECT_EQ("foo/bar", mad_bar->name()); 77 ASSERT_NE(nullptr, sub_heap);
69 ASSERT_EQ(mad_foo, mad_bar->parent()); 78 EXPECT_EQ("foobar_allocator", sub_heap->allocator_name());
70 EXPECT_EQ(1u, mad_bar->physical_size_in_bytes()); 79 EXPECT_EQ("sub_heap", sub_heap->heap_name());
71 EXPECT_EQ(2u, mad_bar->allocated_objects_count()); 80 EXPECT_NE("", sub_heap->GetAbsoluteName());
72 EXPECT_EQ(3u, mad_bar->allocated_objects_size_in_bytes()); 81 EXPECT_EQ(1u, sub_heap->physical_size_in_bytes());
82 EXPECT_EQ(2u, sub_heap->allocated_objects_count());
83 EXPECT_EQ(3u, sub_heap->allocated_objects_size_in_bytes());
73 84
74 const MemoryAllocatorDump* mad_baz = pmd.GetAllocatorDump("baz"); 85 const MemoryAllocatorDump* empty_sub_heap =
75 ASSERT_NE(nullptr, mad_baz); 86 pmd.GetAllocatorDump("foobar_allocator", "sub_heap/empty");
76 EXPECT_EQ("baz", mad_baz->name()); 87 ASSERT_NE(nullptr, empty_sub_heap);
77 ASSERT_EQ(nullptr, mad_baz->parent()); 88 EXPECT_EQ("foobar_allocator", empty_sub_heap->allocator_name());
78 EXPECT_EQ(0u, mad_baz->physical_size_in_bytes()); 89 EXPECT_EQ("sub_heap/empty", empty_sub_heap->heap_name());
79 EXPECT_EQ(0u, mad_baz->allocated_objects_count()); 90 EXPECT_NE("", sub_heap->GetAbsoluteName());
80 EXPECT_EQ(0u, mad_baz->allocated_objects_size_in_bytes()); 91 EXPECT_EQ(0u, empty_sub_heap->physical_size_in_bytes());
92 EXPECT_EQ(0u, empty_sub_heap->allocated_objects_count());
93 EXPECT_EQ(0u, empty_sub_heap->allocated_objects_size_in_bytes());
94
95 // Check that the AsValueInfo doesn't hit any DCHECK.
96 scoped_refptr<TracedValue> traced_value(new TracedValue());
97 pmd.AsValueInto(traced_value.get());
81 } 98 }
82 99
83 // DEATH tests are not supported in Android / iOS. 100 // DEATH tests are not supported in Android / iOS.
84 #if !defined(NDEBUG) && !defined(OS_ANDROID) && !defined(OS_IOS) 101 #if !defined(NDEBUG) && !defined(OS_ANDROID) && !defined(OS_IOS)
85 TEST(MemoryAllocatorDumpTest, ForbidDuplicatesDeathTest) { 102 TEST(MemoryAllocatorDumpTest, ForbidDuplicatesDeathTest) {
86 FakeMemoryAllocatorDumpProvider fmadp; 103 FakeMemoryAllocatorDumpProvider fmadp;
87 ProcessMemoryDump pmd; 104 ProcessMemoryDump pmd(make_scoped_refptr(new MemoryDumpSessionState()));
88 pmd.CreateAllocatorDump("dump_1"); 105 pmd.CreateAllocatorDump("foo_allocator", MemoryAllocatorDump::kRootHeap);
89 pmd.CreateAllocatorDump("dump_2"); 106 pmd.CreateAllocatorDump("bar_allocator", "heap");
90 ASSERT_DEATH(pmd.CreateAllocatorDump("dump_1"), ""); 107 ASSERT_DEATH(
108 pmd.CreateAllocatorDump("foo_allocator", MemoryAllocatorDump::kRootHeap),
109 "");
110 ASSERT_DEATH(pmd.CreateAllocatorDump("bar_allocator", "heap"), "");
111 ASSERT_DEATH(pmd.CreateAllocatorDump("", "must_have_allocator_name"), "");
91 } 112 }
92 #endif 113 #endif
93 114
94 } // namespace trace_event 115 } // namespace trace_event
95 } // namespace base 116 } // namespace base
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698