Index: cc/resources/resource_provider.cc |
diff --git a/cc/resources/resource_provider.cc b/cc/resources/resource_provider.cc |
index 9f680669c089de2a3781732f5f4fca54987caf44..286ad8fd74e0ba9ac0ef4304ee61b88d6c0df14d 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/base/math_util.h" |
#include "cc/resources/platform_color.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()) |
@@ -1117,6 +1124,9 @@ ResourceProvider::ResourceProvider( |
void ResourceProvider::Initialize() { |
DCHECK(thread_checker_.CalledOnValidThread()); |
+ base::trace_event::MemoryDumpManager::GetInstance()->RegisterDumpProvider( |
+ this, base::ThreadTaskRunnerHandle::Get()); |
+ |
GLES2Interface* gl = ContextGL(); |
if (!gl) { |
default_resource_type_ = RESOURCE_TYPE_BITMAP; |
@@ -1958,4 +1968,78 @@ class GrContext* ResourceProvider::GrContext(bool worker_context) const { |
return context_provider ? context_provider->GrContext() : NULL; |
} |
+base::trace_event::MemoryAllocatorDump* ResourceProvider::DumpForResource( |
+ base::trace_event::ProcessMemoryDump* pmd, |
+ const ResourceId& id, |
+ const Resource& resource) const { |
+ std::string dump_name = |
+ base::StringPrintf("CC/resource_memory/resource_%d", id); |
reveman
2015/07/28 21:38:49
nit: I'm using lower case "cc/..." in one-copy dum
ericrk
2015/07/29 18:46:45
Done.
|
+ base::trace_event::MemoryAllocatorDump* dump = |
+ pmd->CreateAllocatorDump(dump_name); |
+ |
+ // Calculate the size of the current resource. |
+ // TODO(ericrk): Replace this with helper fn once crrev.com/1202843008 |
+ // goes in. |
+ unsigned bytes_per_pixel = BitsPerPixel(resource.format) / 8; |
+ uint32_t total_bytes = |
+ resource.size.height() * |
+ MathUtil::RoundUp(bytes_per_pixel * resource.size.width(), 4u); |
+ |
+ dump->AddScalar(base::trace_event::MemoryAllocatorDump::kNameSize, |
+ base::trace_event::MemoryAllocatorDump::kUnitsBytes, |
+ static_cast<uint64_t>(total_bytes)); |
+ |
+ return dump; |
+} |
+ |
+bool ResourceProvider::OnMemoryDump(base::trace_event::ProcessMemoryDump* pmd) { |
+ DCHECK(thread_checker_.CalledOnValidThread()); |
+ |
+ const uint64 tracing_process_id = |
+ base::trace_event::MemoryDumpManager::GetInstance()->tracing_process_id(); |
+ |
+ for (const auto& resource_entry : resources_) { |
+ const auto& resource = resource_entry.second; |
+ |
+ // Only log INTERNAL resources - other resources are owned by (and will be |
+ // logged by) another ResourceProvider. |
+ if (resource.origin != Resource::INTERNAL) |
+ continue; |
+ |
+ if (resource.gpu_memory_buffer) { |
+ auto dump = |
+ DumpForResource(pmd, resource_entry.first, resource_entry.second); |
+ |
+ // Generate a global GUID used to share this allocation with the GPU |
+ // process. |
reveman
2015/07/28 21:38:49
Not just the GPU process but also the browser proc
ericrk
2015/07/29 18:46:46
Done.
|
+ auto guid = gfx::GetSharedBitmapGUIDForTracing( |
reveman
2015/07/28 21:38:49
SharedBitmap? shouldn't this be gfx::GetGpuMemoryB
ssid
2015/07/29 11:17:43
+1
ericrk
2015/07/29 18:46:46
my bad, did a re-name right at the end and replace
|
+ tracing_process_id, resource.gpu_memory_buffer->GetHandle().id); |
+ const int kImportance = 2; |
petrcermak
2015/07/29 16:13:34
This constant is defined three times within this f
ericrk
2015/07/29 18:46:46
refactored this section - should be a lot nicer no
|
+ pmd->AddOwnershipEdge(dump->guid(), guid, kImportance); |
petrcermak
2015/07/29 16:13:34
This call is also repeated three times withing thi
ericrk
2015/07/29 18:46:45
refactored.
|
+ } else if (resource.shared_bitmap) { |
+ auto dump = |
+ DumpForResource(pmd, resource_entry.first, resource_entry.second); |
ssid
2015/07/29 11:17:43
This can be moved out of the if/else. It seems com
ericrk
2015/07/29 18:46:46
Done.
|
+ |
+ // Generate a global GUID used to share this allocation with the GPU |
+ // process. |
reveman
2015/07/28 21:38:49
Not the GPU process. Only the browser process in c
ericrk
2015/07/29 18:46:46
refactored.
|
+ auto guid = |
+ GetSharedMemoryBufferGUIDForTracing(resource.shared_bitmap->id()); |
reveman
2015/07/28 21:38:49
what's GetSharedMemoryBufferGUIDForTracing? is thi
ssid
2015/07/29 11:17:43
I can't find this function?
ericrk
2015/07/29 18:46:45
meant to replace this via rename, replaced the wro
|
+ const int kImportance = 2; |
+ pmd->AddOwnershipEdge(dump->guid(), guid, kImportance); |
+ } else if (resource.gl_id && resource.allocated) { |
+ auto dump = |
+ DumpForResource(pmd, resource_entry.first, resource_entry.second); |
+ |
+ // Generate a global GUID used to share this allocation with the GPU |
+ // process. |
+ auto guid = |
+ gfx::GetGLTextureGUIDForTracing(tracing_process_id, resource.gl_id); |
ssid
2015/07/29 11:17:43
Am i missing a dependent cl?
ericrk
2015/07/29 18:46:46
added missing files.
|
+ const int kImportance = 2; |
+ pmd->AddOwnershipEdge(dump->guid(), guid, kImportance); |
ssid
2015/07/29 11:17:43
I think this memory is shared between processes. I
ericrk
2015/07/29 18:46:45
Interestingly, this was working - probably because
|
+ } |
+ } |
+ |
+ return true; |
+} |
+ |
} // namespace cc |