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

Side by Side Diff: cc/resources/resource_provider.cc

Issue 2535213002: [WIP] Add SharedMemoryTracker to dump base::SharedMemory usage
Patch Set: (wip) Created 3 years, 9 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 unified diff | Download patch
OLDNEW
1 // Copyright 2012 The Chromium Authors. All rights reserved. 1 // Copyright 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "cc/resources/resource_provider.h" 5 #include "cc/resources/resource_provider.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <algorithm> 10 #include <algorithm>
11 #include <limits> 11 #include <limits>
12 #include <unordered_map> 12 #include <unordered_map>
13 13
14 #include "base/atomic_sequence_num.h" 14 #include "base/atomic_sequence_num.h"
15 #include "base/macros.h" 15 #include "base/macros.h"
16 #include "base/memory/shared_memory_tracker.h"
16 #include "base/metrics/histogram.h" 17 #include "base/metrics/histogram.h"
17 #include "base/numerics/safe_math.h" 18 #include "base/numerics/safe_math.h"
18 #include "base/stl_util.h" 19 #include "base/stl_util.h"
19 #include "base/strings/string_split.h" 20 #include "base/strings/string_split.h"
20 #include "base/strings/string_util.h" 21 #include "base/strings/string_util.h"
21 #include "base/strings/stringprintf.h" 22 #include "base/strings/stringprintf.h"
22 #include "base/threading/thread_task_runner_handle.h" 23 #include "base/threading/thread_task_runner_handle.h"
23 #include "base/trace_event/memory_dump_manager.h" 24 #include "base/trace_event/memory_dump_manager.h"
24 #include "base/trace_event/trace_event.h" 25 #include "base/trace_event/trace_event.h"
25 #include "cc/resources/platform_color.h" 26 #include "cc/resources/platform_color.h"
(...skipping 2087 matching lines...) Expand 10 before | Expand all | Expand 10 after
2113 2114
2114 uint64_t total_bytes = ResourceUtil::UncheckedSizeInBytesAligned<size_t>( 2115 uint64_t total_bytes = ResourceUtil::UncheckedSizeInBytesAligned<size_t>(
2115 resource.size, resource.format); 2116 resource.size, resource.format);
2116 dump->AddScalar(base::trace_event::MemoryAllocatorDump::kNameSize, 2117 dump->AddScalar(base::trace_event::MemoryAllocatorDump::kNameSize,
2117 base::trace_event::MemoryAllocatorDump::kUnitsBytes, 2118 base::trace_event::MemoryAllocatorDump::kUnitsBytes,
2118 static_cast<uint64_t>(total_bytes)); 2119 static_cast<uint64_t>(total_bytes));
2119 2120
2120 // Resources may be shared across processes and require a shared GUID to 2121 // Resources may be shared across processes and require a shared GUID to
2121 // prevent double counting the memory. 2122 // prevent double counting the memory.
2122 base::trace_event::MemoryAllocatorDumpGuid guid; 2123 base::trace_event::MemoryAllocatorDumpGuid guid;
2124 base::SharedMemoryHandle shared_memory_handle;
2123 switch (resource.type) { 2125 switch (resource.type) {
2124 case RESOURCE_TYPE_GPU_MEMORY_BUFFER: 2126 case RESOURCE_TYPE_GPU_MEMORY_BUFFER:
2125 guid = gfx::GetGpuMemoryBufferGUIDForTracing( 2127 guid = gfx::GetGpuMemoryBufferGUIDForTracing(
2126 tracing_process_id, resource.gpu_memory_buffer->GetHandle().id); 2128 tracing_process_id, resource.gpu_memory_buffer->GetHandle().id);
2129 shared_memory_handle = resource.gpu_memory_buffer->GetHandle().handle;
2127 break; 2130 break;
2128 case RESOURCE_TYPE_GL_TEXTURE: 2131 case RESOURCE_TYPE_GL_TEXTURE:
2129 DCHECK(resource.gl_id); 2132 DCHECK(resource.gl_id);
2130 guid = gl::GetGLTextureClientGUIDForTracing( 2133 guid = gl::GetGLTextureClientGUIDForTracing(
2131 compositor_context_provider_->ContextSupport() 2134 compositor_context_provider_->ContextSupport()
2132 ->ShareGroupTracingGUID(), 2135 ->ShareGroupTracingGUID(),
2133 resource.gl_id); 2136 resource.gl_id);
2134 break; 2137 break;
2135 case RESOURCE_TYPE_BITMAP: 2138 case RESOURCE_TYPE_BITMAP:
2136 DCHECK(resource.has_shared_bitmap_id); 2139 DCHECK(resource.has_shared_bitmap_id);
2137 guid = GetSharedBitmapGUIDForTracing(resource.shared_bitmap_id); 2140 guid = GetSharedBitmapGUIDForTracing(resource.shared_bitmap_id);
2141 auto* shared_memory = resource.shared_bitmap->shared_memory();
2142 if (shared_memory)
2143 shared_memory_handle = shared_memory->handle();
2138 break; 2144 break;
2139 } 2145 }
2140 2146
2141 DCHECK(!guid.empty()); 2147 DCHECK(!guid.empty());
2142 2148
2143 const int kImportance = 2; 2149 // const int kImportance = 2;
2144 pmd->CreateSharedGlobalAllocatorDump(guid); 2150 if (shared_memory_handle != base::SharedMemory::NULLHandle()) {
2145 pmd->AddOwnershipEdge(dump->guid(), guid, kImportance); 2151 // TODO(hajimehoshi): Fix this
2152 base::SharedMemoryTracker::AddOwnershipEdges(
2153 pmd, guid, shared_memory_handle, total_bytes);
2154 }
2146 } 2155 }
2147 2156
2148 return true; 2157 return true;
2149 } 2158 }
2150 2159
2151 } // namespace cc 2160 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698