Chromium Code Reviews| Index: cc/resources/resource_provider.cc |
| diff --git a/cc/resources/resource_provider.cc b/cc/resources/resource_provider.cc |
| index 4c7c9dae8aedbca3ac221362f45a60ad9f90daa3..386ab57997e29642984d3f02f0ee3006ee63062e 100644 |
| --- a/cc/resources/resource_provider.cc |
| +++ b/cc/resources/resource_provider.cc |
| @@ -8,11 +8,14 @@ |
| #include <limits> |
| #include "base/containers/hash_tables.h" |
| +#include "base/format_macros.h" |
| #include "base/metrics/histogram.h" |
| #include "base/numerics/safe_math.h" |
| #include "base/stl_util.h" |
| #include "base/strings/string_split.h" |
| #include "base/strings/string_util.h" |
| +#include "base/strings/stringprintf.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" |
| @@ -404,6 +407,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()) |
| @@ -1146,6 +1152,9 @@ void ResourceProvider::Initialize() { |
| new TextureIdAllocator(gl, id_allocation_chunk_size_)); |
| buffer_id_allocator_.reset( |
| new BufferIdAllocator(gl, id_allocation_chunk_size_)); |
| + |
| + base::trace_event::MemoryDumpManager::GetInstance()->RegisterDumpProvider( |
| + this); |
|
reveman
2015/07/24 21:16:35
You'll need to provide a ThreadTaskRunnerHandle he
ericrk
2015/07/28 21:02:32
Done. Also moved this above (we were skipping regi
|
| } |
| int ResourceProvider::CreateChild(const ReturnCallback& return_callback) { |
| @@ -1952,4 +1961,51 @@ 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()); |
| + |
| + // We currently only support memory dumping GL resources. |
|
reveman
2015/07/24 21:16:36
FYI, we should dump memory usage of shared bitmaps
ericrk
2015/07/28 21:02:32
Added this for Shared Bitmaps and for GPU Memory B
|
| + if (default_resource_type_ == RESOURCE_TYPE_GL_TEXTURE) { |
|
reveman
2015/07/24 21:16:36
is the resource.gl_id check below not enough? what
ericrk
2015/07/28 21:02:32
True - now that we log all types this no longer ap
|
| + 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 memory if we find an internal GL resource with an allocated |
| + // ID. |
| + if (resource.gl_id && resource.allocated && |
| + resource.origin == Resource::INTERNAL) { |
| + std::string dump_name = |
| + base::StringPrintf("gl/CC/textures/%d", resource.gl_id); |
|
reveman
2015/07/24 21:16:36
I think the naming convention I used in my one-cop
ericrk
2015/07/28 21:02:32
Makes sense.
|
| + 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.org/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)); |
| + |
| + // Generate a global GUID used to share this allocation with the GPU |
| + // process. |
| + auto guid = base::trace_event::MemoryAllocatorDumpGuid( |
| + base::StringPrintf("gl-x-process/%" PRIx64 "/texture_%d", |
| + tracing_process_id, resource.gl_id)); |
|
reveman
2015/07/24 21:16:36
This is not going to be correct if the resource is
ericrk
2015/07/28 21:02:32
Done.
|
| + const int kImportance = 2; |
| + pmd->AddOwnershipEdge(dump->guid(), guid, kImportance); |
| + } |
| + } |
| + } |
| + |
| + return true; |
| +} |
| + |
| } // namespace cc |