| 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 0b2cbdf513d01de3762debf8b9a709078186b64c..b9adbae07da093aeba98c78768a5d1750ac614ca 100644
|
| --- a/base/trace_event/memory_allocator_dump_unittest.cc
|
| +++ b/base/trace_event/memory_allocator_dump_unittest.cc
|
| @@ -6,6 +6,7 @@
|
|
|
| #include "base/format_macros.h"
|
| #include "base/strings/stringprintf.h"
|
| +#include "base/trace_event/memory_allocator_dump_guid.h"
|
| #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"
|
| @@ -23,21 +24,18 @@ class FakeMemoryAllocatorDumpProvider : public MemoryDumpProvider {
|
| MemoryAllocatorDump* root_heap =
|
| pmd->CreateAllocatorDump("foobar_allocator");
|
|
|
| - root_heap->AddScalar(MemoryAllocatorDump::kNameOuterSize,
|
| + root_heap->AddScalar(MemoryAllocatorDump::kNameSize,
|
| MemoryAllocatorDump::kUnitsBytes, 4096);
|
| - root_heap->AddScalar(MemoryAllocatorDump::kNameInnerSize,
|
| - MemoryAllocatorDump::kUnitsBytes, 1000);
|
| root_heap->AddScalar(MemoryAllocatorDump::kNameObjectsCount,
|
| MemoryAllocatorDump::kUnitsObjects, 42);
|
| root_heap->AddScalar("attr1", "units1", 1234);
|
| root_heap->AddString("attr2", "units2", "string_value");
|
| + root_heap->AddScalarF("attr3", "units3", 42.5f);
|
|
|
| MemoryAllocatorDump* sub_heap =
|
| pmd->CreateAllocatorDump("foobar_allocator/sub_heap");
|
| - sub_heap->AddScalar(MemoryAllocatorDump::kNameOuterSize,
|
| + sub_heap->AddScalar(MemoryAllocatorDump::kNameSize,
|
| MemoryAllocatorDump::kUnitsBytes, 1);
|
| - sub_heap->AddScalar(MemoryAllocatorDump::kNameInnerSize,
|
| - MemoryAllocatorDump::kUnitsBytes, 2);
|
| sub_heap->AddScalar(MemoryAllocatorDump::kNameObjectsCount,
|
| MemoryAllocatorDump::kUnitsObjects, 3);
|
|
|
| @@ -49,35 +47,84 @@ class FakeMemoryAllocatorDumpProvider : public MemoryDumpProvider {
|
| }
|
| };
|
|
|
| -void CheckAttribute(const MemoryAllocatorDump* dump,
|
| +bool CheckAttribute(const MemoryAllocatorDump* dump,
|
| const std::string& name,
|
| const char* expected_type,
|
| const char* expected_units,
|
| - const std::string& expected_value) {
|
| + const Value** out_value) {
|
| const char* attr_type;
|
| const char* attr_units;
|
| - const Value* attr_value;
|
| - std::string attr_str_value;
|
| - bool res = dump->Get(name, &attr_type, &attr_units, &attr_value);
|
| + bool res = dump->Get(name, &attr_type, &attr_units, out_value);
|
| EXPECT_TRUE(res);
|
| if (!res)
|
| - return;
|
| + return false;
|
| EXPECT_EQ(expected_type, std::string(attr_type));
|
| EXPECT_EQ(expected_units, std::string(attr_units));
|
| + return true;
|
| +}
|
| +
|
| +void CheckString(const MemoryAllocatorDump* dump,
|
| + const std::string& name,
|
| + const char* expected_type,
|
| + const char* expected_units,
|
| + const std::string& expected_value) {
|
| + const Value* attr_value = nullptr;
|
| + std::string attr_str_value;
|
| + bool res =
|
| + CheckAttribute(dump, name, expected_type, expected_units, &attr_value);
|
| + if (!res)
|
| + return;
|
| EXPECT_TRUE(attr_value->GetAsString(&attr_str_value));
|
| EXPECT_EQ(expected_value, attr_str_value);
|
| }
|
|
|
| -void CheckAttribute(const MemoryAllocatorDump* dump,
|
| - const std::string& name,
|
| - const char* expected_type,
|
| - const char* expected_units,
|
| - uint64 expected_value) {
|
| - CheckAttribute(dump, name, expected_type, expected_units,
|
| - StringPrintf("%" PRIx64, expected_value));
|
| +void CheckScalar(const MemoryAllocatorDump* dump,
|
| + const std::string& name,
|
| + const char* expected_units,
|
| + uint64 expected_value) {
|
| + CheckString(dump, name, MemoryAllocatorDump::kTypeScalar, expected_units,
|
| + StringPrintf("%" PRIx64, expected_value));
|
| +}
|
| +
|
| +void CheckScalarF(const MemoryAllocatorDump* dump,
|
| + const std::string& name,
|
| + const char* expected_units,
|
| + double expected_value) {
|
| + const Value* attr_value = nullptr;
|
| + double attr_double_value;
|
| + bool res = CheckAttribute(dump, name, MemoryAllocatorDump::kTypeScalar,
|
| + expected_units, &attr_value);
|
| + if (!res)
|
| + return;
|
| + EXPECT_TRUE(attr_value->GetAsDouble(&attr_double_value));
|
| + EXPECT_EQ(expected_value, attr_double_value);
|
| }
|
| +
|
| } // namespace
|
|
|
| +TEST(MemoryAllocatorDumpTest, GuidGeneration) {
|
| + scoped_ptr<MemoryAllocatorDump> mad(
|
| + new MemoryAllocatorDump("foo", nullptr, MemoryAllocatorDumpGuid(0x42u)));
|
| + ASSERT_EQ("42", mad->guid().ToString());
|
| +
|
| + // If the dumper does not provide a Guid, the MAD will make one up on the
|
| + // flight. Furthermore that Guid will stay stable across across multiple
|
| + // snapshots if the |absolute_name| of the dump doesn't change
|
| + mad.reset(new MemoryAllocatorDump("bar", nullptr));
|
| + const MemoryAllocatorDumpGuid guid_bar = mad->guid();
|
| + ASSERT_FALSE(guid_bar.empty());
|
| + ASSERT_FALSE(guid_bar.ToString().empty());
|
| + ASSERT_EQ(guid_bar, mad->guid());
|
| +
|
| + mad.reset(new MemoryAllocatorDump("bar", nullptr));
|
| + const MemoryAllocatorDumpGuid guid_bar_2 = mad->guid();
|
| + ASSERT_EQ(guid_bar, guid_bar_2);
|
| +
|
| + mad.reset(new MemoryAllocatorDump("baz", nullptr));
|
| + const MemoryAllocatorDumpGuid guid_baz = mad->guid();
|
| + ASSERT_NE(guid_bar, guid_baz);
|
| +}
|
| +
|
| TEST(MemoryAllocatorDumpTest, DumpIntoProcessMemoryDump) {
|
| FakeMemoryAllocatorDumpProvider fmadp;
|
| ProcessMemoryDump pmd(make_scoped_refptr(new MemoryDumpSessionState()));
|
| @@ -90,41 +137,29 @@ TEST(MemoryAllocatorDumpTest, DumpIntoProcessMemoryDump) {
|
| pmd.GetAllocatorDump("foobar_allocator");
|
| ASSERT_NE(nullptr, root_heap);
|
| EXPECT_EQ("foobar_allocator", root_heap->absolute_name());
|
| - CheckAttribute(root_heap, MemoryAllocatorDump::kNameOuterSize,
|
| - MemoryAllocatorDump::kTypeScalar,
|
| - MemoryAllocatorDump::kUnitsBytes, 4096);
|
| - CheckAttribute(root_heap, MemoryAllocatorDump::kNameInnerSize,
|
| - MemoryAllocatorDump::kTypeScalar,
|
| - MemoryAllocatorDump::kUnitsBytes, 1000);
|
| - CheckAttribute(root_heap, MemoryAllocatorDump::kNameObjectsCount,
|
| - MemoryAllocatorDump::kTypeScalar,
|
| - MemoryAllocatorDump::kUnitsObjects, 42);
|
| - CheckAttribute(root_heap, "attr1", MemoryAllocatorDump::kTypeScalar, "units1",
|
| - 1234);
|
| - CheckAttribute(root_heap, "attr2", MemoryAllocatorDump::kTypeString, "units2",
|
| - "string_value");
|
| + CheckScalar(root_heap, MemoryAllocatorDump::kNameSize,
|
| + MemoryAllocatorDump::kUnitsBytes, 4096);
|
| + CheckScalar(root_heap, MemoryAllocatorDump::kNameObjectsCount,
|
| + MemoryAllocatorDump::kUnitsObjects, 42);
|
| + CheckScalar(root_heap, "attr1", "units1", 1234);
|
| + CheckString(root_heap, "attr2", MemoryAllocatorDump::kTypeString, "units2",
|
| + "string_value");
|
| + CheckScalarF(root_heap, "attr3", "units3", 42.5f);
|
|
|
| const MemoryAllocatorDump* sub_heap =
|
| pmd.GetAllocatorDump("foobar_allocator/sub_heap");
|
| ASSERT_NE(nullptr, sub_heap);
|
| EXPECT_EQ("foobar_allocator/sub_heap", sub_heap->absolute_name());
|
| - CheckAttribute(sub_heap, MemoryAllocatorDump::kNameOuterSize,
|
| - MemoryAllocatorDump::kTypeScalar,
|
| - MemoryAllocatorDump::kUnitsBytes, 1);
|
| - CheckAttribute(sub_heap, MemoryAllocatorDump::kNameInnerSize,
|
| - MemoryAllocatorDump::kTypeScalar,
|
| - MemoryAllocatorDump::kUnitsBytes, 2);
|
| - CheckAttribute(sub_heap, MemoryAllocatorDump::kNameObjectsCount,
|
| - MemoryAllocatorDump::kTypeScalar,
|
| - MemoryAllocatorDump::kUnitsObjects, 3);
|
| + CheckScalar(sub_heap, MemoryAllocatorDump::kNameSize,
|
| + MemoryAllocatorDump::kUnitsBytes, 1);
|
| + CheckScalar(sub_heap, MemoryAllocatorDump::kNameObjectsCount,
|
| + MemoryAllocatorDump::kUnitsObjects, 3);
|
|
|
| const MemoryAllocatorDump* empty_sub_heap =
|
| pmd.GetAllocatorDump("foobar_allocator/sub_heap/empty");
|
| ASSERT_NE(nullptr, empty_sub_heap);
|
| EXPECT_EQ("foobar_allocator/sub_heap/empty", empty_sub_heap->absolute_name());
|
| - ASSERT_FALSE(empty_sub_heap->Get(MemoryAllocatorDump::kNameOuterSize, nullptr,
|
| - nullptr, nullptr));
|
| - ASSERT_FALSE(empty_sub_heap->Get(MemoryAllocatorDump::kNameInnerSize, nullptr,
|
| + ASSERT_FALSE(empty_sub_heap->Get(MemoryAllocatorDump::kNameSize, nullptr,
|
| nullptr, nullptr));
|
| ASSERT_FALSE(empty_sub_heap->Get(MemoryAllocatorDump::kNameObjectsCount,
|
| nullptr, nullptr, nullptr));
|
|
|