Commit fc3ad4fd authored by Siddhartha's avatar Siddhartha Committed by Commit Bot

Add more details about UI resources in memory dump

Add details about number of resources and type of bitmap in UI resource
memory dump.

BUG=780547

Change-Id: Iaea7854db074a74a2a1340881ae3450756e74525
Reviewed-on: https://chromium-review.googlesource.com/879593
Commit-Queue: Siddhartha S <ssid@chromium.org>
Reviewed-by: default avatarDavid Trainor <dtrainor@chromium.org>
Cr-Commit-Position: refs/heads/master@{#531735}
parent a22eb8ca
......@@ -176,7 +176,8 @@ const char* const kAllocatorDumpNameWhitelist[] = {
"skia/sk_glyph_cache",
"skia/sk_resource_cache",
"sqlite",
"ui/resource_manager_0x?",
"ui/resource_manager_0x?/default_resource/0x?",
"ui/resource_manager_0x?/tinted_resource",
"v8/isolate_0x?/contexts/detached_context",
"v8/isolate_0x?/contexts/native_context",
"v8/isolate_0x?/heap_spaces",
......
......@@ -34,6 +34,27 @@ using base::android::JavaArrayOfIntArrayToIntVector;
using base::android::JavaParamRef;
using base::android::JavaRef;
namespace {
base::trace_event::MemoryAllocatorDump* CreateMemoryDump(
const std::string& name,
size_t memory_usage,
base::trace_event::ProcessMemoryDump* pmd) {
base::trace_event::MemoryAllocatorDump* dump = pmd->CreateAllocatorDump(name);
dump->AddScalar(base::trace_event::MemoryAllocatorDump::kNameSize,
base::trace_event::MemoryAllocatorDump::kUnitsBytes,
memory_usage);
static const char* system_allocator_name =
base::trace_event::MemoryDumpManager::GetInstance()
->system_allocator_pool_name();
if (system_allocator_name)
pmd->AddSuballocation(dump->guid(), system_allocator_name);
return dump;
}
} // namespace
namespace ui {
// static
......@@ -212,24 +233,21 @@ void ResourceManagerImpl::RemoveResource(
bool ResourceManagerImpl::OnMemoryDump(
const base::trace_event::MemoryDumpArgs& args,
base::trace_event::ProcessMemoryDump* pmd) {
size_t memory_usage =
base::trace_event::EstimateMemoryUsage(resources_) +
base::trace_event::EstimateMemoryUsage(tinted_resources_);
base::trace_event::MemoryAllocatorDump* dump = pmd->CreateAllocatorDump(
base::StringPrintf("ui/resource_manager_0x%" PRIXPTR,
reinterpret_cast<uintptr_t>(this)));
dump->AddScalar(base::trace_event::MemoryAllocatorDump::kNameSize,
base::trace_event::MemoryAllocatorDump::kUnitsBytes,
memory_usage);
const char* system_allocator_name =
base::trace_event::MemoryDumpManager::GetInstance()
->system_allocator_pool_name();
if (system_allocator_name) {
pmd->AddSuballocation(dump->guid(), system_allocator_name);
std::string prefix = base::StringPrintf("ui/resource_manager_0x%" PRIXPTR,
reinterpret_cast<uintptr_t>(this));
for (uint32_t type = static_cast<uint32_t>(ANDROID_RESOURCE_TYPE_FIRST);
type <= static_cast<uint32_t>(ANDROID_RESOURCE_TYPE_LAST); ++type) {
size_t usage = base::trace_event::EstimateMemoryUsage(resources_[type]);
auto* dump = CreateMemoryDump(
prefix + base::StringPrintf("/default_resource/0x%u",
static_cast<uint32_t>(type)),
usage, pmd);
dump->AddScalar("resource_count", "objects", resources_[type].size());
}
size_t tinted_resource_usage =
base::trace_event::EstimateMemoryUsage(tinted_resources_);
CreateMemoryDump(prefix + "/tinted_resource", tinted_resource_usage, pmd);
return true;
}
......
......@@ -154,8 +154,8 @@ TEST_F(ResourceManagerTest, TestOnMemoryDumpEmitsData) {
const char* system_allocator_pool_name =
base::trace_event::MemoryDumpManager::GetInstance()
->system_allocator_pool_name();
size_t expected_dump_count = system_allocator_pool_name ? 2 : 1;
EXPECT_EQ(expected_dump_count, allocator_dumps.size());
size_t kExpectedDumpCount = 10;
EXPECT_EQ(kExpectedDumpCount, allocator_dumps.size());
for (const auto& dump : allocator_dumps) {
ASSERT_TRUE(dump.first.find("ui/resource_manager") == 0 ||
dump.first.find(system_allocator_pool_name) == 0);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment