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 "base/format_macros.h" | 7 #include "base/format_macros.h" |
8 #include "base/strings/stringprintf.h" | 8 #include "base/strings/stringprintf.h" |
9 #include "base/trace_event/memory_allocator_dump_guid.h" | 9 #include "base/trace_event/memory_allocator_dump_guid.h" |
10 #include "base/trace_event/memory_dump_provider.h" | 10 #include "base/trace_event/memory_dump_provider.h" |
11 #include "base/trace_event/memory_dump_session_state.h" | 11 #include "base/trace_event/memory_dump_session_state.h" |
12 #include "base/trace_event/process_memory_dump.h" | 12 #include "base/trace_event/process_memory_dump.h" |
13 #include "base/trace_event/trace_event_argument.h" | 13 #include "base/trace_event/trace_event_argument.h" |
14 #include "base/values.h" | 14 #include "base/values.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 class FakeMemoryAllocatorDumpProvider : public MemoryDumpProvider { | 22 class FakeMemoryAllocatorDumpProvider : public MemoryDumpProvider { |
23 public: | 23 public: |
24 bool OnMemoryDump(ProcessMemoryDump* pmd) override { | 24 bool OnMemoryDump(const MemoryDumpArgs&, ProcessMemoryDump* pmd) override { |
petrcermak
2015/07/31 13:23:01
nit: missing argument name (I know it's not strict
ssid
2015/07/31 15:14:33
Done.
| |
25 MemoryAllocatorDump* root_heap = | 25 MemoryAllocatorDump* root_heap = |
26 pmd->CreateAllocatorDump("foobar_allocator"); | 26 pmd->CreateAllocatorDump("foobar_allocator"); |
27 | 27 |
28 root_heap->AddScalar(MemoryAllocatorDump::kNameSize, | 28 root_heap->AddScalar(MemoryAllocatorDump::kNameSize, |
29 MemoryAllocatorDump::kUnitsBytes, 4096); | 29 MemoryAllocatorDump::kUnitsBytes, 4096); |
30 root_heap->AddScalar(MemoryAllocatorDump::kNameObjectsCount, | 30 root_heap->AddScalar(MemoryAllocatorDump::kNameObjectsCount, |
31 MemoryAllocatorDump::kUnitsObjects, 42); | 31 MemoryAllocatorDump::kUnitsObjects, 42); |
32 root_heap->AddScalar("attr1", "units1", 1234); | 32 root_heap->AddScalar("attr1", "units1", 1234); |
33 root_heap->AddString("attr2", "units2", "string_value"); | 33 root_heap->AddString("attr2", "units2", "string_value"); |
34 root_heap->AddScalarF("attr3", "units3", 42.5f); | 34 root_heap->AddScalarF("attr3", "units3", 42.5f); |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
119 | 119 |
120 mad.reset(new MemoryAllocatorDump("baz", nullptr)); | 120 mad.reset(new MemoryAllocatorDump("baz", nullptr)); |
121 const MemoryAllocatorDumpGuid guid_baz = mad->guid(); | 121 const MemoryAllocatorDumpGuid guid_baz = mad->guid(); |
122 ASSERT_NE(guid_bar, guid_baz); | 122 ASSERT_NE(guid_bar, guid_baz); |
123 } | 123 } |
124 | 124 |
125 TEST(MemoryAllocatorDumpTest, DumpIntoProcessMemoryDump) { | 125 TEST(MemoryAllocatorDumpTest, DumpIntoProcessMemoryDump) { |
126 FakeMemoryAllocatorDumpProvider fmadp; | 126 FakeMemoryAllocatorDumpProvider fmadp; |
127 ProcessMemoryDump pmd(make_scoped_refptr(new MemoryDumpSessionState())); | 127 ProcessMemoryDump pmd(make_scoped_refptr(new MemoryDumpSessionState())); |
128 | 128 |
129 fmadp.OnMemoryDump(&pmd); | 129 fmadp.OnMemoryDump(MemoryDumpArgs(MemoryDumpArgs::LEVEL_OF_DETAIL_HIGH), |
130 &pmd); | |
130 | 131 |
131 ASSERT_EQ(3u, pmd.allocator_dumps().size()); | 132 ASSERT_EQ(3u, pmd.allocator_dumps().size()); |
132 | 133 |
133 const MemoryAllocatorDump* root_heap = | 134 const MemoryAllocatorDump* root_heap = |
134 pmd.GetAllocatorDump("foobar_allocator"); | 135 pmd.GetAllocatorDump("foobar_allocator"); |
135 ASSERT_NE(nullptr, root_heap); | 136 ASSERT_NE(nullptr, root_heap); |
136 EXPECT_EQ("foobar_allocator", root_heap->absolute_name()); | 137 EXPECT_EQ("foobar_allocator", root_heap->absolute_name()); |
137 CheckScalar(root_heap, MemoryAllocatorDump::kNameSize, | 138 CheckScalar(root_heap, MemoryAllocatorDump::kNameSize, |
138 MemoryAllocatorDump::kUnitsBytes, 4096); | 139 MemoryAllocatorDump::kUnitsBytes, 4096); |
139 CheckScalar(root_heap, MemoryAllocatorDump::kNameObjectsCount, | 140 CheckScalar(root_heap, MemoryAllocatorDump::kNameObjectsCount, |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
174 pmd.CreateAllocatorDump("foo_allocator"); | 175 pmd.CreateAllocatorDump("foo_allocator"); |
175 pmd.CreateAllocatorDump("bar_allocator/heap"); | 176 pmd.CreateAllocatorDump("bar_allocator/heap"); |
176 ASSERT_DEATH(pmd.CreateAllocatorDump("foo_allocator"), ""); | 177 ASSERT_DEATH(pmd.CreateAllocatorDump("foo_allocator"), ""); |
177 ASSERT_DEATH(pmd.CreateAllocatorDump("bar_allocator/heap"), ""); | 178 ASSERT_DEATH(pmd.CreateAllocatorDump("bar_allocator/heap"), ""); |
178 ASSERT_DEATH(pmd.CreateAllocatorDump(""), ""); | 179 ASSERT_DEATH(pmd.CreateAllocatorDump(""), ""); |
179 } | 180 } |
180 #endif | 181 #endif |
181 | 182 |
182 } // namespace trace_event | 183 } // namespace trace_event |
183 } // namespace base | 184 } // namespace base |
OLD | NEW |