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

Unified Diff: cc/resources/resource_pool.cc

Issue 1265183002: Add memory tracking to TexturePool. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@textures3
Patch Set: review feedback Created 5 years, 4 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
Index: cc/resources/resource_pool.cc
diff --git a/cc/resources/resource_pool.cc b/cc/resources/resource_pool.cc
index 300c48f3d652a94458fa868f37c18da42995a933..c51c4d9c8626230563143c2f8f87ca21c080b481 100644
--- a/cc/resources/resource_pool.cc
+++ b/cc/resources/resource_pool.cc
@@ -4,6 +4,12 @@
#include "cc/resources/resource_pool.h"
+#include <algorithm>
+
+#include "base/format_macros.h"
+#include "base/strings/stringprintf.h"
+#include "base/thread_task_runner_handle.h"
+#include "base/trace_event/memory_dump_manager.h"
#include "cc/resources/resource_provider.h"
#include "cc/resources/resource_util.h"
#include "cc/resources/scoped_resource.h"
@@ -18,9 +24,14 @@ ResourcePool::ResourcePool(ResourceProvider* resource_provider, GLenum target)
max_resource_count_(0),
memory_usage_bytes_(0),
unused_memory_usage_bytes_(0),
- resource_count_(0) {}
+ resource_count_(0) {
+ base::trace_event::MemoryDumpManager::GetInstance()->RegisterDumpProvider(
+ this, base::ThreadTaskRunnerHandle::Get());
+}
ResourcePool::~ResourcePool() {
+ base::trace_event::MemoryDumpManager::GetInstance()->UnregisterDumpProvider(
+ this);
while (!busy_resources_.empty()) {
auto const& front = busy_resources_.front();
DidFinishUsingResource(front.resource, front.content_id);
@@ -167,4 +178,39 @@ void ResourcePool::DidFinishUsingResource(ScopedResource* resource,
unused_resources_.push_back(PoolResource(resource, content_id));
}
+bool ResourcePool::OnMemoryDump(base::trace_event::ProcessMemoryDump* pmd) {
+ for (const auto& resource : unused_resources_) {
+ resource.OnMemoryDump(pmd, true /* is_free */);
+ }
+ for (const auto& resource : busy_resources_) {
+ resource.OnMemoryDump(pmd, false /* is_free */);
+ }
+ // TODO(ericrk): Dump vended out resources once that data is available.
+ // crbug.com/516541
+ return true;
+}
+
+void ResourcePool::PoolResource::OnMemoryDump(
reveman 2015/08/05 01:26:59 nit: definition of nested class usually go before
ericrk 2015/08/05 20:41:08 Done.
+ base::trace_event::ProcessMemoryDump* pmd,
+ bool is_free) const {
+ // TODO(ericrk): Add per-compositor ID in name.
+ std::string parent_node =
+ base::StringPrintf("cc/resource_memory/resource_%d", resource->id());
+ std::string dump_name =
+ base::StringPrintf("cc/tile_memory/resource_%d", resource->id());
+ base::trace_event::MemoryAllocatorDump* dump =
+ pmd->CreateAllocatorDump(dump_name);
+
+ pmd->AddSuballocation(dump->guid(), parent_node);
+
+ uint64_t total_bytes = ResourceUtil::UncheckedSizeInBytesAligned<size_t>(
+ resource->size(), resource->format());
+ dump->AddScalar(base::trace_event::MemoryAllocatorDump::kNameSize,
+ base::trace_event::MemoryAllocatorDump::kUnitsBytes,
+ total_bytes);
+ dump->AddScalar("free_size",
+ base::trace_event::MemoryAllocatorDump::kUnitsBytes,
+ is_free ? total_bytes : 0);
+}
+
} // namespace cc

Powered by Google App Engine
This is Rietveld 408576698