Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(179)

Unified Diff: ui/android/resources/resource_manager_impl.cc

Issue 2440393002: [tracing] Implement composable memory usage estimators. (Closed)
Patch Set: Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « ui/android/resources/resource_manager.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 0f8fbdf7037cc6f0c27798865a6afb41b3557b26..11e27804cfd3154ca4b14d4bb2909d144047bff3 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"
@@ -300,31 +301,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();
« no previous file with comments | « ui/android/resources/resource_manager.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698