Index: cc/resources/resource_provider.cc |
diff --git a/cc/resources/resource_provider.cc b/cc/resources/resource_provider.cc |
index c22115a1e4d53435834b3cf281c938464cf8f592..10fe534b14d5e7fe7eb7bf068ecbc291f8767bf6 100644 |
--- a/cc/resources/resource_provider.cc |
+++ b/cc/resources/resource_provider.cc |
@@ -13,6 +13,9 @@ |
#include "base/stl_util.h" |
#include "base/strings/string_split.h" |
#include "base/strings/string_util.h" |
+#include "base/strings/stringprintf.h" |
+#include "base/thread_task_runner_handle.h" |
+#include "base/trace_event/memory_dump_manager.h" |
#include "base/trace_event/trace_event.h" |
#include "cc/resources/platform_color.h" |
#include "cc/resources/resource_util.h" |
@@ -30,6 +33,7 @@ |
#include "ui/gfx/geometry/rect.h" |
#include "ui/gfx/geometry/vector2d.h" |
#include "ui/gfx/gpu_memory_buffer.h" |
+#include "ui/gl/trace_util.h" |
using gpu::gles2::GLES2Interface; |
@@ -404,6 +408,9 @@ scoped_ptr<ResourceProvider> ResourceProvider::Create( |
} |
ResourceProvider::~ResourceProvider() { |
+ base::trace_event::MemoryDumpManager::GetInstance()->UnregisterDumpProvider( |
+ this); |
+ |
while (!children_.empty()) |
DestroyChildInternal(children_.begin(), FOR_SHUTDOWN); |
while (!resources_.empty()) |
@@ -1114,6 +1121,14 @@ ResourceProvider::ResourceProvider( |
void ResourceProvider::Initialize() { |
DCHECK(thread_checker_.CalledOnValidThread()); |
+ // In certain cases, ThreadTaskRunnerHandle isn't set (Android Webview). |
+ // Don't register a dump provider in these cases. |
+ // TODO(ericrk): Get this working in Android Webview. crbug.com/517156 |
+ if (base::ThreadTaskRunnerHandle::IsSet()) { |
+ base::trace_event::MemoryDumpManager::GetInstance()->RegisterDumpProvider( |
+ this, base::ThreadTaskRunnerHandle::Get()); |
+ } |
+ |
GLES2Interface* gl = ContextGL(); |
if (!gl) { |
default_resource_type_ = RESOURCE_TYPE_BITMAP; |
@@ -1953,4 +1968,49 @@ class GrContext* ResourceProvider::GrContext(bool worker_context) const { |
return context_provider ? context_provider->GrContext() : NULL; |
} |
+bool ResourceProvider::OnMemoryDump(base::trace_event::ProcessMemoryDump* pmd) { |
+ DCHECK(thread_checker_.CalledOnValidThread()); |
+ |
+ const uint64 tracing_process_id = |
+ base::trace_event::MemoryDumpManager::GetInstance() |
+ ->GetTracingProcessId(); |
+ |
+ for (const auto& resource_entry : resources_) { |
+ const auto& resource = resource_entry.second; |
+ |
+ std::string dump_name = base::StringPrintf("cc/resource_memory/resource_%d", |
+ resource_entry.first); |
+ base::trace_event::MemoryAllocatorDump* dump = |
+ pmd->CreateAllocatorDump(dump_name); |
+ |
+ uint64_t total_bytes = ResourceUtil::UncheckedSizeInBytesAligned<size_t>( |
+ resource.size, resource.format); |
+ dump->AddScalar(base::trace_event::MemoryAllocatorDump::kNameSize, |
+ base::trace_event::MemoryAllocatorDump::kUnitsBytes, |
+ static_cast<uint64_t>(total_bytes)); |
+ |
+ // Resources which are shared across processes require a shared GUID to |
+ // prevent double counting the memory. We currently support shared GUIDs for |
+ // GpuMemoryBuffer, SharedBitmap, and GL backed resources. |
+ base::trace_event::MemoryAllocatorDumpGuid guid; |
+ if (resource.gpu_memory_buffer) { |
+ guid = gfx::GetGpuMemoryBufferGUIDForTracing( |
+ tracing_process_id, resource.gpu_memory_buffer->GetHandle().id); |
+ } else if (resource.shared_bitmap) { |
+ guid = GetSharedBitmapGUIDForTracing(resource.shared_bitmap->id()); |
+ } else if (resource.gl_id && resource.allocated) { |
+ guid = |
+ gfx::GetGLTextureGUIDForTracing(tracing_process_id, resource.gl_id); |
+ } |
+ |
+ if (!guid.empty()) { |
+ const int kImportance = 2; |
+ pmd->CreateSharedGlobalAllocatorDump(guid); |
+ pmd->AddOwnershipEdge(dump->guid(), guid, kImportance); |
+ } |
+ } |
+ |
+ return true; |
+} |
+ |
} // namespace cc |