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

Side by Side Diff: content/common/host_shared_bitmap_manager.cc

Issue 2535213002: [WIP] Add SharedMemoryTracker to dump base::SharedMemory usage
Patch Set: Remove unneeded calls Created 4 years 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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 "content/common/host_shared_bitmap_manager.h" 5 #include "content/common/host_shared_bitmap_manager.h"
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8 8
9 #include <utility> 9 #include <utility>
10 10
11 #include "base/lazy_instance.h" 11 #include "base/lazy_instance.h"
12 #include "base/macros.h" 12 #include "base/macros.h"
13 #include "base/memory/ptr_util.h" 13 #include "base/memory/ptr_util.h"
14 #include "base/memory/ref_counted.h" 14 #include "base/memory/ref_counted.h"
15 #include "base/memory/shared_memory_dump_provider.h"
15 #include "base/strings/string_number_conversions.h" 16 #include "base/strings/string_number_conversions.h"
16 #include "base/trace_event/process_memory_dump.h" 17 #include "base/trace_event/process_memory_dump.h"
17 #include "build/build_config.h" 18 #include "build/build_config.h"
18 #include "content/common/view_messages.h" 19 #include "content/common/view_messages.h"
19 #include "ui/gfx/geometry/size.h" 20 #include "ui/gfx/geometry/size.h"
20 21
21 namespace content { 22 namespace content {
22 23
23 class BitmapData : public base::RefCountedThreadSafe<BitmapData> { 24 class BitmapData : public base::RefCountedThreadSafe<BitmapData> {
24 public: 25 public:
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after
171 172
172 dump->AddScalar(base::trace_event::MemoryAllocatorDump::kNameSize, 173 dump->AddScalar(base::trace_event::MemoryAllocatorDump::kNameSize,
173 base::trace_event::MemoryAllocatorDump::kUnitsBytes, 174 base::trace_event::MemoryAllocatorDump::kUnitsBytes,
174 bitmap.second->buffer_size); 175 bitmap.second->buffer_size);
175 176
176 // Generate a global GUID used to share this allocation with renderer 177 // Generate a global GUID used to share this allocation with renderer
177 // processes. 178 // processes.
178 auto guid = cc::GetSharedBitmapGUIDForTracing(bitmap.first); 179 auto guid = cc::GetSharedBitmapGUIDForTracing(bitmap.first);
179 pmd->CreateSharedGlobalAllocatorDump(guid); 180 pmd->CreateSharedGlobalAllocatorDump(guid);
180 pmd->AddOwnershipEdge(dump->guid(), guid); 181 pmd->AddOwnershipEdge(dump->guid(), guid);
182 base::SharedMemoryDumpProvider::GetInstance()->AddSuballocation(
183 pmd, dump->guid());
181 } 184 }
182 185
183 return true; 186 return true;
184 } 187 }
185 188
186 bool HostSharedBitmapManager::ChildAllocatedSharedBitmap( 189 bool HostSharedBitmapManager::ChildAllocatedSharedBitmap(
187 size_t buffer_size, 190 size_t buffer_size,
188 const base::SharedMemoryHandle& handle, 191 const base::SharedMemoryHandle& handle,
189 const cc::SharedBitmapId& id) { 192 const cc::SharedBitmapId& id) {
190 base::AutoLock lock(lock_); 193 base::AutoLock lock(lock_);
(...skipping 27 matching lines...) Expand all
218 221
219 scoped_refptr<BitmapData> data(new BitmapData(buffer_size)); 222 scoped_refptr<BitmapData> data(new BitmapData(buffer_size));
220 data->memory = std::move(shared_memory); 223 data->memory = std::move(shared_memory);
221 224
222 handle_map_[id] = data; 225 handle_map_[id] = data;
223 if (!data->memory->ShareToProcess(process_handle, shared_memory_handle)) { 226 if (!data->memory->ShareToProcess(process_handle, shared_memory_handle)) {
224 LOG(ERROR) << "Cannot share shared memory buffer"; 227 LOG(ERROR) << "Cannot share shared memory buffer";
225 *shared_memory_handle = base::SharedMemory::NULLHandle(); 228 *shared_memory_handle = base::SharedMemory::NULLHandle();
226 return; 229 return;
227 } 230 }
228 data->memory->Close(); 231 data->memory->Close();
229 } 232 }
230 233
231 void HostSharedBitmapManager::ChildDeletedSharedBitmap( 234 void HostSharedBitmapManager::ChildDeletedSharedBitmap(
232 const cc::SharedBitmapId& id) { 235 const cc::SharedBitmapId& id) {
233 base::AutoLock lock(lock_); 236 base::AutoLock lock(lock_);
234 handle_map_.erase(id); 237 handle_map_.erase(id);
235 } 238 }
236 239
237 size_t HostSharedBitmapManager::AllocatedBitmapCount() const { 240 size_t HostSharedBitmapManager::AllocatedBitmapCount() const {
238 base::AutoLock lock(lock_); 241 base::AutoLock lock(lock_);
239 return handle_map_.size(); 242 return handle_map_.size();
240 } 243 }
241 244
242 void HostSharedBitmapManager::FreeSharedMemoryFromMap( 245 void HostSharedBitmapManager::FreeSharedMemoryFromMap(
243 const cc::SharedBitmapId& id) { 246 const cc::SharedBitmapId& id) {
244 base::AutoLock lock(lock_); 247 base::AutoLock lock(lock_);
245 handle_map_.erase(id); 248 handle_map_.erase(id);
246 } 249 }
247 250
248 } // namespace content 251 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698