Index: ui/android/resources/resource_manager_impl.cc |
diff --git a/ui/android/resources/resource_manager_impl.cc b/ui/android/resources/resource_manager_impl.cc |
index 2e60510bc44949c7936b9f35a5b79e8284412092..cc66936704a4d0d0d04b8a3bf38753009912affa 100644 |
--- a/ui/android/resources/resource_manager_impl.cc |
+++ b/ui/android/resources/resource_manager_impl.cc |
@@ -15,6 +15,7 @@ |
#include "base/memory/ptr_util.h" |
#include "base/strings/stringprintf.h" |
#include "base/threading/thread_task_runner_handle.h" |
+#include "base/trace_event/estimate_memory_usage.h" |
#include "base/trace_event/memory_dump_manager.h" |
#include "base/trace_event/process_memory_dump.h" |
#include "base/trace_event/trace_event.h" |
@@ -301,31 +302,18 @@ ResourceManagerImpl::ProcessCrushedSpriteFrameRects( |
bool ResourceManagerImpl::OnMemoryDump( |
const base::trace_event::MemoryDumpArgs& args, |
base::trace_event::ProcessMemoryDump* pmd) { |
- size_t size = 0; |
- for (const auto& resource_map : resources_) { |
- for (const auto& id_and_resource : resource_map) { |
- if (id_and_resource.second && id_and_resource.second->ui_resource) |
- size += id_and_resource.second->ui_resource->GetAllocatedSizeInBytes(); |
- } |
- } |
- for (const auto& id_and_resource : crushed_sprite_resources_) { |
- if (id_and_resource.second) |
- size += id_and_resource.second->GetAllocatedSizeInBytes(); |
- } |
- for (const auto& color_and_resources : tinted_resources_) { |
- for (const auto& id_and_resource : *color_and_resources.second) { |
- if (id_and_resource.second && id_and_resource.second->ui_resource) |
- size += id_and_resource.second->ui_resource->GetAllocatedSizeInBytes(); |
- } |
- } |
+ using base::trace_event::EstimateMemoryUsage; |
+ size_t memory_usage = EstimateMemoryUsage(resources_) + |
+ EstimateMemoryUsage(crushed_sprite_resources_) + |
+ 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, size); |
+ base::trace_event::MemoryAllocatorDump::kUnitsBytes, |
+ memory_usage); |
- // Bitmaps are allocated from malloc. |
const char* system_allocator_name = |
base::trace_event::MemoryDumpManager::GetInstance() |
->system_allocator_pool_name(); |