| Index: base/trace_event/memory_allocator_dump_unittest.cc
|
| diff --git a/base/trace_event/memory_allocator_dump_unittest.cc b/base/trace_event/memory_allocator_dump_unittest.cc
|
| index a0b56f5ad047e77bc0f2ce1b9f5254062995f792..110a25d93c44b06acc9b4a5e908740e1d081e14b 100644
|
| --- a/base/trace_event/memory_allocator_dump_unittest.cc
|
| +++ b/base/trace_event/memory_allocator_dump_unittest.cc
|
| @@ -7,88 +7,108 @@
|
| #include "base/trace_event/memory_dump_provider.h"
|
| #include "base/trace_event/memory_dump_session_state.h"
|
| #include "base/trace_event/process_memory_dump.h"
|
| +#include "base/trace_event/trace_event_argument.h"
|
| #include "testing/gtest/include/gtest/gtest.h"
|
|
|
| namespace base {
|
| namespace trace_event {
|
|
|
| namespace {
|
| +
|
| class FakeMemoryAllocatorDumpProvider : public MemoryDumpProvider {
|
| public:
|
| FakeMemoryAllocatorDumpProvider() {
|
| - DeclareAllocatorAttribute({"attr1", "count"});
|
| - DeclareAllocatorAttribute({"attr2", "bytes"});
|
| + DeclareAllocatorAttribute("foobar_allocator", "attr1", "count");
|
| + DeclareAllocatorAttribute("foobar_allocator", "attr2", "bytes");
|
| }
|
|
|
| bool DumpInto(ProcessMemoryDump* pmd) override {
|
| - MemoryAllocatorDump* mad_foo = pmd->CreateAllocatorDump("foo");
|
| - mad_foo->set_physical_size_in_bytes(4096);
|
| - mad_foo->set_allocated_objects_count(42);
|
| - mad_foo->set_allocated_objects_size_in_bytes(1000);
|
| - mad_foo->SetExtraAttribute("attr1", 1234);
|
| - mad_foo->SetExtraAttribute("attr2", 99);
|
| -
|
| - MemoryAllocatorDump* mad_bar = pmd->CreateAllocatorDump("foo/bar", mad_foo);
|
| - mad_bar->set_physical_size_in_bytes(1);
|
| - mad_bar->set_allocated_objects_count(2);
|
| - mad_bar->set_allocated_objects_size_in_bytes(3);
|
| -
|
| - pmd->CreateAllocatorDump("baz");
|
| - // Leave the rest of |baz| deliberately uninitialized, to check that
|
| + MemoryAllocatorDump* root_heap = pmd->CreateAllocatorDump(
|
| + "foobar_allocator", MemoryAllocatorDump::kRootHeap);
|
| + root_heap->set_physical_size_in_bytes(4096);
|
| + root_heap->set_allocated_objects_count(42);
|
| + root_heap->set_allocated_objects_size_in_bytes(1000);
|
| + root_heap->SetAttribute("attr1", 1234);
|
| + root_heap->SetAttribute("attr2", 99);
|
| +
|
| + MemoryAllocatorDump* sub_heap =
|
| + pmd->CreateAllocatorDump("foobar_allocator", "sub_heap");
|
| + sub_heap->set_physical_size_in_bytes(1);
|
| + sub_heap->set_allocated_objects_count(2);
|
| + sub_heap->set_allocated_objects_size_in_bytes(3);
|
| +
|
| + pmd->CreateAllocatorDump("foobar_allocator", "sub_heap/empty");
|
| + // Leave the rest of sub heap deliberately uninitialized, to check that
|
| // CreateAllocatorDump returns a properly zero-initialized object.
|
|
|
| return true;
|
| }
|
|
|
| - const char* GetFriendlyName() const override { return "mock_allocator"; }
|
| + const char* GetFriendlyName() const override { return "FooBar Allocator"; }
|
| };
|
| } // namespace
|
|
|
| TEST(MemoryAllocatorDumpTest, DumpIntoProcessMemoryDump) {
|
| FakeMemoryAllocatorDumpProvider fmadp;
|
| ProcessMemoryDump pmd(make_scoped_refptr(new MemoryDumpSessionState()));
|
| + pmd.session_state()->allocators_attributes_type_info.Update(
|
| + fmadp.allocator_attributes_type_info());
|
|
|
| fmadp.DumpInto(&pmd);
|
|
|
| ASSERT_EQ(3u, pmd.allocator_dumps().size());
|
|
|
| - const MemoryAllocatorDump* mad_foo = pmd.GetAllocatorDump("foo");
|
| - ASSERT_NE(nullptr, mad_foo);
|
| - EXPECT_EQ("foo", mad_foo->name());
|
| - ASSERT_EQ(nullptr, mad_foo->parent());
|
| - EXPECT_EQ(4096u, mad_foo->physical_size_in_bytes());
|
| - EXPECT_EQ(42u, mad_foo->allocated_objects_count());
|
| - EXPECT_EQ(1000u, mad_foo->allocated_objects_size_in_bytes());
|
| -
|
| - // Check the extra attributes of |mad_foo|.
|
| - EXPECT_EQ(1234, mad_foo->GetExtraIntegerAttribute("attr1"));
|
| - EXPECT_EQ(99, mad_foo->GetExtraIntegerAttribute("attr2"));
|
| -
|
| - const MemoryAllocatorDump* mad_bar = pmd.GetAllocatorDump("foo/bar");
|
| - ASSERT_NE(nullptr, mad_bar);
|
| - EXPECT_EQ("foo/bar", mad_bar->name());
|
| - ASSERT_EQ(mad_foo, mad_bar->parent());
|
| - EXPECT_EQ(1u, mad_bar->physical_size_in_bytes());
|
| - EXPECT_EQ(2u, mad_bar->allocated_objects_count());
|
| - EXPECT_EQ(3u, mad_bar->allocated_objects_size_in_bytes());
|
| -
|
| - const MemoryAllocatorDump* mad_baz = pmd.GetAllocatorDump("baz");
|
| - ASSERT_NE(nullptr, mad_baz);
|
| - EXPECT_EQ("baz", mad_baz->name());
|
| - ASSERT_EQ(nullptr, mad_baz->parent());
|
| - EXPECT_EQ(0u, mad_baz->physical_size_in_bytes());
|
| - EXPECT_EQ(0u, mad_baz->allocated_objects_count());
|
| - EXPECT_EQ(0u, mad_baz->allocated_objects_size_in_bytes());
|
| + const MemoryAllocatorDump* root_heap =
|
| + pmd.GetAllocatorDump("foobar_allocator", MemoryAllocatorDump::kRootHeap);
|
| + ASSERT_NE(nullptr, root_heap);
|
| + EXPECT_EQ("foobar_allocator", root_heap->allocator_name());
|
| + EXPECT_EQ("", root_heap->heap_name());
|
| + EXPECT_NE("", root_heap->GetAbsoluteName());
|
| + EXPECT_EQ(4096u, root_heap->physical_size_in_bytes());
|
| + EXPECT_EQ(42u, root_heap->allocated_objects_count());
|
| + EXPECT_EQ(1000u, root_heap->allocated_objects_size_in_bytes());
|
| +
|
| + // Check the extra attributes of |root_heap|.
|
| + EXPECT_EQ(1234, root_heap->GetIntegerAttribute("attr1"));
|
| + EXPECT_EQ(99, root_heap->GetIntegerAttribute("attr2"));
|
| +
|
| + const MemoryAllocatorDump* sub_heap =
|
| + pmd.GetAllocatorDump("foobar_allocator", "sub_heap");
|
| + ASSERT_NE(nullptr, sub_heap);
|
| + EXPECT_EQ("foobar_allocator", sub_heap->allocator_name());
|
| + EXPECT_EQ("sub_heap", sub_heap->heap_name());
|
| + EXPECT_NE("", sub_heap->GetAbsoluteName());
|
| + EXPECT_EQ(1u, sub_heap->physical_size_in_bytes());
|
| + EXPECT_EQ(2u, sub_heap->allocated_objects_count());
|
| + EXPECT_EQ(3u, sub_heap->allocated_objects_size_in_bytes());
|
| +
|
| + const MemoryAllocatorDump* empty_sub_heap =
|
| + pmd.GetAllocatorDump("foobar_allocator", "sub_heap/empty");
|
| + ASSERT_NE(nullptr, empty_sub_heap);
|
| + EXPECT_EQ("foobar_allocator", empty_sub_heap->allocator_name());
|
| + EXPECT_EQ("sub_heap/empty", empty_sub_heap->heap_name());
|
| + EXPECT_NE("", sub_heap->GetAbsoluteName());
|
| + EXPECT_EQ(0u, empty_sub_heap->physical_size_in_bytes());
|
| + EXPECT_EQ(0u, empty_sub_heap->allocated_objects_count());
|
| + EXPECT_EQ(0u, empty_sub_heap->allocated_objects_size_in_bytes());
|
| +
|
| + // Check that the AsValueInfo doesn't hit any DCHECK.
|
| + scoped_refptr<TracedValue> traced_value(new TracedValue());
|
| + pmd.AsValueInto(traced_value.get());
|
| }
|
|
|
| // DEATH tests are not supported in Android / iOS.
|
| #if !defined(NDEBUG) && !defined(OS_ANDROID) && !defined(OS_IOS)
|
| TEST(MemoryAllocatorDumpTest, ForbidDuplicatesDeathTest) {
|
| FakeMemoryAllocatorDumpProvider fmadp;
|
| - ProcessMemoryDump pmd(nullptr /* session_state */);
|
| - pmd.CreateAllocatorDump("dump_1");
|
| - pmd.CreateAllocatorDump("dump_2");
|
| - ASSERT_DEATH(pmd.CreateAllocatorDump("dump_1"), "");
|
| + ProcessMemoryDump pmd(make_scoped_refptr(new MemoryDumpSessionState()));
|
| + pmd.CreateAllocatorDump("foo_allocator", MemoryAllocatorDump::kRootHeap);
|
| + pmd.CreateAllocatorDump("bar_allocator", "heap");
|
| + ASSERT_DEATH(
|
| + pmd.CreateAllocatorDump("foo_allocator", MemoryAllocatorDump::kRootHeap),
|
| + "");
|
| + ASSERT_DEATH(pmd.CreateAllocatorDump("bar_allocator", "heap"), "");
|
| + ASSERT_DEATH(pmd.CreateAllocatorDump("", "must_have_allocator_name"), "");
|
| }
|
| #endif
|
|
|
|
|