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/memory_allocator_dump.h" | 5 #include "base/trace_event/memory_allocator_dump.h" |
6 | 6 |
7 #include <stdint.h> | 7 #include <stdint.h> |
8 | 8 |
9 #include "base/format_macros.h" | 9 #include "base/format_macros.h" |
10 #include "base/strings/stringprintf.h" | 10 #include "base/strings/stringprintf.h" |
| 11 #include "base/trace_event/heap_profiler_serialization_state.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/memory_dump_provider.h" | 13 #include "base/trace_event/memory_dump_provider.h" |
13 #include "base/trace_event/memory_dump_session_state.h" | |
14 #include "base/trace_event/process_memory_dump.h" | 14 #include "base/trace_event/process_memory_dump.h" |
15 #include "base/trace_event/trace_event_argument.h" | 15 #include "base/trace_event/trace_event_argument.h" |
16 #include "base/values.h" | 16 #include "base/values.h" |
17 #include "build/build_config.h" | 17 #include "build/build_config.h" |
18 #include "testing/gtest/include/gtest/gtest.h" | 18 #include "testing/gtest/include/gtest/gtest.h" |
19 | 19 |
20 namespace base { | 20 namespace base { |
21 namespace trace_event { | 21 namespace trace_event { |
22 | 22 |
23 namespace { | 23 namespace { |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
123 ASSERT_EQ(guid_bar, guid_bar_2); | 123 ASSERT_EQ(guid_bar, guid_bar_2); |
124 | 124 |
125 mad.reset(new MemoryAllocatorDump("baz", nullptr)); | 125 mad.reset(new MemoryAllocatorDump("baz", nullptr)); |
126 const MemoryAllocatorDumpGuid guid_baz = mad->guid(); | 126 const MemoryAllocatorDumpGuid guid_baz = mad->guid(); |
127 ASSERT_NE(guid_bar, guid_baz); | 127 ASSERT_NE(guid_bar, guid_baz); |
128 } | 128 } |
129 | 129 |
130 TEST(MemoryAllocatorDumpTest, DumpIntoProcessMemoryDump) { | 130 TEST(MemoryAllocatorDumpTest, DumpIntoProcessMemoryDump) { |
131 FakeMemoryAllocatorDumpProvider fmadp; | 131 FakeMemoryAllocatorDumpProvider fmadp; |
132 MemoryDumpArgs dump_args = {MemoryDumpLevelOfDetail::DETAILED}; | 132 MemoryDumpArgs dump_args = {MemoryDumpLevelOfDetail::DETAILED}; |
133 ProcessMemoryDump pmd(new MemoryDumpSessionState, dump_args); | 133 ProcessMemoryDump pmd(new HeapProfilerSerializationState, dump_args); |
134 | 134 |
135 fmadp.OnMemoryDump(dump_args, &pmd); | 135 fmadp.OnMemoryDump(dump_args, &pmd); |
136 | 136 |
137 ASSERT_EQ(3u, pmd.allocator_dumps().size()); | 137 ASSERT_EQ(3u, pmd.allocator_dumps().size()); |
138 | 138 |
139 const MemoryAllocatorDump* root_heap = | 139 const MemoryAllocatorDump* root_heap = |
140 pmd.GetAllocatorDump("foobar_allocator"); | 140 pmd.GetAllocatorDump("foobar_allocator"); |
141 ASSERT_NE(nullptr, root_heap); | 141 ASSERT_NE(nullptr, root_heap); |
142 EXPECT_EQ("foobar_allocator", root_heap->absolute_name()); | 142 EXPECT_EQ("foobar_allocator", root_heap->absolute_name()); |
143 CheckScalar(root_heap, MemoryAllocatorDump::kNameSize, | 143 CheckScalar(root_heap, MemoryAllocatorDump::kNameSize, |
(...skipping 23 matching lines...) Expand all Loading... |
167 ASSERT_FALSE(attrs->HasKey(MemoryAllocatorDump::kNameSize)); | 167 ASSERT_FALSE(attrs->HasKey(MemoryAllocatorDump::kNameSize)); |
168 ASSERT_FALSE(attrs->HasKey(MemoryAllocatorDump::kNameObjectCount)); | 168 ASSERT_FALSE(attrs->HasKey(MemoryAllocatorDump::kNameObjectCount)); |
169 | 169 |
170 // Check that the AsValueInfo doesn't hit any DCHECK. | 170 // Check that the AsValueInfo doesn't hit any DCHECK. |
171 std::unique_ptr<TracedValue> traced_value(new TracedValue); | 171 std::unique_ptr<TracedValue> traced_value(new TracedValue); |
172 pmd.AsValueInto(traced_value.get()); | 172 pmd.AsValueInto(traced_value.get()); |
173 } | 173 } |
174 | 174 |
175 TEST(MemoryAllocatorDumpTest, GetSize) { | 175 TEST(MemoryAllocatorDumpTest, GetSize) { |
176 MemoryDumpArgs dump_args = {MemoryDumpLevelOfDetail::DETAILED}; | 176 MemoryDumpArgs dump_args = {MemoryDumpLevelOfDetail::DETAILED}; |
177 ProcessMemoryDump pmd(new MemoryDumpSessionState, dump_args); | 177 ProcessMemoryDump pmd(new HeapProfilerSerializationState, dump_args); |
178 MemoryAllocatorDump* dump = pmd.CreateAllocatorDump("allocator_for_size"); | 178 MemoryAllocatorDump* dump = pmd.CreateAllocatorDump("allocator_for_size"); |
179 dump->AddScalar(MemoryAllocatorDump::kNameSize, | 179 dump->AddScalar(MemoryAllocatorDump::kNameSize, |
180 MemoryAllocatorDump::kUnitsBytes, 1); | 180 MemoryAllocatorDump::kUnitsBytes, 1); |
181 dump->AddScalar("foo", MemoryAllocatorDump::kUnitsBytes, 2); | 181 dump->AddScalar("foo", MemoryAllocatorDump::kUnitsBytes, 2); |
182 EXPECT_EQ(1u, dump->GetSize()); | 182 EXPECT_EQ(1u, dump->GetSize()); |
183 } | 183 } |
184 | 184 |
185 // DEATH tests are not supported in Android / iOS. | 185 // DEATH tests are not supported in Android / iOS. |
186 #if !defined(NDEBUG) && !defined(OS_ANDROID) && !defined(OS_IOS) | 186 #if !defined(NDEBUG) && !defined(OS_ANDROID) && !defined(OS_IOS) |
187 TEST(MemoryAllocatorDumpTest, ForbidDuplicatesDeathTest) { | 187 TEST(MemoryAllocatorDumpTest, ForbidDuplicatesDeathTest) { |
188 FakeMemoryAllocatorDumpProvider fmadp; | 188 FakeMemoryAllocatorDumpProvider fmadp; |
189 MemoryDumpArgs dump_args = {MemoryDumpLevelOfDetail::DETAILED}; | 189 MemoryDumpArgs dump_args = {MemoryDumpLevelOfDetail::DETAILED}; |
190 ProcessMemoryDump pmd(new MemoryDumpSessionState, dump_args); | 190 ProcessMemoryDump pmd(new HeapProfilerSerializationState, dump_args); |
191 pmd.CreateAllocatorDump("foo_allocator"); | 191 pmd.CreateAllocatorDump("foo_allocator"); |
192 pmd.CreateAllocatorDump("bar_allocator/heap"); | 192 pmd.CreateAllocatorDump("bar_allocator/heap"); |
193 ASSERT_DEATH(pmd.CreateAllocatorDump("foo_allocator"), ""); | 193 ASSERT_DEATH(pmd.CreateAllocatorDump("foo_allocator"), ""); |
194 ASSERT_DEATH(pmd.CreateAllocatorDump("bar_allocator/heap"), ""); | 194 ASSERT_DEATH(pmd.CreateAllocatorDump("bar_allocator/heap"), ""); |
195 ASSERT_DEATH(pmd.CreateAllocatorDump(""), ""); | 195 ASSERT_DEATH(pmd.CreateAllocatorDump(""), ""); |
196 } | 196 } |
197 #endif | 197 #endif |
198 | 198 |
199 } // namespace trace_event | 199 } // namespace trace_event |
200 } // namespace base | 200 } // namespace base |
OLD | NEW |