Chromium Code Reviews| 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_stack_frame_deduplicator.h" | |
|
petrcermak
2016/02/26 10:21:03
I don't think you need these imports here
Primiano Tucci (use gerrit)
2016/02/26 22:52:49
Done.
| |
| 12 #include "base/trace_event/heap_profiler_type_name_deduplicator.h" | |
| 11 #include "base/trace_event/memory_allocator_dump_guid.h" | 13 #include "base/trace_event/memory_allocator_dump_guid.h" |
| 12 #include "base/trace_event/memory_dump_provider.h" | 14 #include "base/trace_event/memory_dump_provider.h" |
| 13 #include "base/trace_event/memory_dump_session_state.h" | 15 #include "base/trace_event/memory_dump_session_state.h" |
| 14 #include "base/trace_event/process_memory_dump.h" | 16 #include "base/trace_event/process_memory_dump.h" |
| 15 #include "base/trace_event/trace_event_argument.h" | 17 #include "base/trace_event/trace_event_argument.h" |
| 16 #include "base/values.h" | 18 #include "base/values.h" |
| 17 #include "build/build_config.h" | 19 #include "build/build_config.h" |
| 18 #include "testing/gtest/include/gtest/gtest.h" | 20 #include "testing/gtest/include/gtest/gtest.h" |
| 19 | 21 |
| 20 namespace base { | 22 namespace base { |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 121 const MemoryAllocatorDumpGuid guid_bar_2 = mad->guid(); | 123 const MemoryAllocatorDumpGuid guid_bar_2 = mad->guid(); |
| 122 ASSERT_EQ(guid_bar, guid_bar_2); | 124 ASSERT_EQ(guid_bar, guid_bar_2); |
| 123 | 125 |
| 124 mad.reset(new MemoryAllocatorDump("baz", nullptr)); | 126 mad.reset(new MemoryAllocatorDump("baz", nullptr)); |
| 125 const MemoryAllocatorDumpGuid guid_baz = mad->guid(); | 127 const MemoryAllocatorDumpGuid guid_baz = mad->guid(); |
| 126 ASSERT_NE(guid_bar, guid_baz); | 128 ASSERT_NE(guid_bar, guid_baz); |
| 127 } | 129 } |
| 128 | 130 |
| 129 TEST(MemoryAllocatorDumpTest, DumpIntoProcessMemoryDump) { | 131 TEST(MemoryAllocatorDumpTest, DumpIntoProcessMemoryDump) { |
| 130 FakeMemoryAllocatorDumpProvider fmadp; | 132 FakeMemoryAllocatorDumpProvider fmadp; |
| 131 ProcessMemoryDump pmd(new MemoryDumpSessionState(nullptr, nullptr)); | 133 ProcessMemoryDump pmd(new MemoryDumpSessionState); |
| 132 MemoryDumpArgs dump_args = {MemoryDumpLevelOfDetail::DETAILED}; | 134 MemoryDumpArgs dump_args = {MemoryDumpLevelOfDetail::DETAILED}; |
| 133 | 135 |
| 134 fmadp.OnMemoryDump(dump_args, &pmd); | 136 fmadp.OnMemoryDump(dump_args, &pmd); |
| 135 | 137 |
| 136 ASSERT_EQ(3u, pmd.allocator_dumps().size()); | 138 ASSERT_EQ(3u, pmd.allocator_dumps().size()); |
| 137 | 139 |
| 138 const MemoryAllocatorDump* root_heap = | 140 const MemoryAllocatorDump* root_heap = |
| 139 pmd.GetAllocatorDump("foobar_allocator"); | 141 pmd.GetAllocatorDump("foobar_allocator"); |
| 140 ASSERT_NE(nullptr, root_heap); | 142 ASSERT_NE(nullptr, root_heap); |
| 141 EXPECT_EQ("foobar_allocator", root_heap->absolute_name()); | 143 EXPECT_EQ("foobar_allocator", root_heap->absolute_name()); |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 160 pmd.GetAllocatorDump("foobar_allocator/sub_heap/empty"); | 162 pmd.GetAllocatorDump("foobar_allocator/sub_heap/empty"); |
| 161 ASSERT_NE(nullptr, empty_sub_heap); | 163 ASSERT_NE(nullptr, empty_sub_heap); |
| 162 EXPECT_EQ("foobar_allocator/sub_heap/empty", empty_sub_heap->absolute_name()); | 164 EXPECT_EQ("foobar_allocator/sub_heap/empty", empty_sub_heap->absolute_name()); |
| 163 auto raw_attrs = empty_sub_heap->attributes_for_testing()->ToBaseValue(); | 165 auto raw_attrs = empty_sub_heap->attributes_for_testing()->ToBaseValue(); |
| 164 DictionaryValue* attrs = nullptr; | 166 DictionaryValue* attrs = nullptr; |
| 165 ASSERT_TRUE(raw_attrs->GetAsDictionary(&attrs)); | 167 ASSERT_TRUE(raw_attrs->GetAsDictionary(&attrs)); |
| 166 ASSERT_FALSE(attrs->HasKey(MemoryAllocatorDump::kNameSize)); | 168 ASSERT_FALSE(attrs->HasKey(MemoryAllocatorDump::kNameSize)); |
| 167 ASSERT_FALSE(attrs->HasKey(MemoryAllocatorDump::kNameObjectCount)); | 169 ASSERT_FALSE(attrs->HasKey(MemoryAllocatorDump::kNameObjectCount)); |
| 168 | 170 |
| 169 // Check that the AsValueInfo doesn't hit any DCHECK. | 171 // Check that the AsValueInfo doesn't hit any DCHECK. |
| 170 scoped_refptr<TracedValue> traced_value(new TracedValue()); | 172 scoped_ptr<TracedValue> traced_value(new TracedValue); |
| 171 pmd.AsValueInto(traced_value.get()); | 173 pmd.AsValueInto(traced_value.get()); |
| 172 } | 174 } |
| 173 | 175 |
| 174 // DEATH tests are not supported in Android / iOS. | 176 // DEATH tests are not supported in Android / iOS. |
| 175 #if !defined(NDEBUG) && !defined(OS_ANDROID) && !defined(OS_IOS) | 177 #if !defined(NDEBUG) && !defined(OS_ANDROID) && !defined(OS_IOS) |
| 176 TEST(MemoryAllocatorDumpTest, ForbidDuplicatesDeathTest) { | 178 TEST(MemoryAllocatorDumpTest, ForbidDuplicatesDeathTest) { |
| 177 FakeMemoryAllocatorDumpProvider fmadp; | 179 FakeMemoryAllocatorDumpProvider fmadp; |
| 178 ProcessMemoryDump pmd(new MemoryDumpSessionState(nullptr, nullptr)); | 180 ProcessMemoryDump pmd(new MemoryDumpSessionState); |
| 179 pmd.CreateAllocatorDump("foo_allocator"); | 181 pmd.CreateAllocatorDump("foo_allocator"); |
| 180 pmd.CreateAllocatorDump("bar_allocator/heap"); | 182 pmd.CreateAllocatorDump("bar_allocator/heap"); |
| 181 ASSERT_DEATH(pmd.CreateAllocatorDump("foo_allocator"), ""); | 183 ASSERT_DEATH(pmd.CreateAllocatorDump("foo_allocator"), ""); |
| 182 ASSERT_DEATH(pmd.CreateAllocatorDump("bar_allocator/heap"), ""); | 184 ASSERT_DEATH(pmd.CreateAllocatorDump("bar_allocator/heap"), ""); |
| 183 ASSERT_DEATH(pmd.CreateAllocatorDump(""), ""); | 185 ASSERT_DEATH(pmd.CreateAllocatorDump(""), ""); |
| 184 } | 186 } |
| 185 #endif | 187 #endif |
| 186 | 188 |
| 187 } // namespace trace_event | 189 } // namespace trace_event |
| 188 } // namespace base | 190 } // namespace base |
| OLD | NEW |