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

Side by Side Diff: gpu/command_buffer/client/mapped_memory.cc

Issue 2535213002: [WIP] Add SharedMemoryTracker to dump base::SharedMemory usage
Patch Set: (rebase) Created 3 years, 6 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
« no previous file with comments | « gpu/command_buffer/client/mapped_memory.h ('k') | gpu/command_buffer/client/transfer_buffer.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 "gpu/command_buffer/client/mapped_memory.h" 5 #include "gpu/command_buffer/client/mapped_memory.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 <functional> 11 #include <functional>
12 12
13 #include "base/atomic_sequence_num.h" 13 #include "base/atomic_sequence_num.h"
14 #include "base/logging.h" 14 #include "base/logging.h"
15 #include "base/memory/ptr_util.h" 15 #include "base/memory/ptr_util.h"
16 #include "base/memory/shared_memory_tracker.h"
16 #include "base/strings/stringprintf.h" 17 #include "base/strings/stringprintf.h"
17 #include "base/threading/thread_task_runner_handle.h" 18 #include "base/threading/thread_task_runner_handle.h"
18 #include "base/trace_event/memory_dump_manager.h" 19 #include "base/trace_event/memory_dump_manager.h"
19 #include "base/trace_event/trace_event.h" 20 #include "base/trace_event/trace_event.h"
20 #include "gpu/command_buffer/client/cmd_buffer_helper.h" 21 #include "gpu/command_buffer/client/cmd_buffer_helper.h"
21 #include "gpu/command_buffer/client/shared_memory_limits.h" 22 #include "gpu/command_buffer/client/shared_memory_limits.h"
22 #include "gpu/command_buffer/common/buffer.h" 23 #include "gpu/command_buffer/common/buffer.h"
23 24
24 namespace gpu { 25 namespace gpu {
25 namespace { 26 namespace {
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after
166 std::string dump_name = 167 std::string dump_name =
167 base::StringPrintf("gpu/mapped_memory/manager_%d", tracing_id_); 168 base::StringPrintf("gpu/mapped_memory/manager_%d", tracing_id_);
168 MemoryAllocatorDump* dump = pmd->CreateAllocatorDump(dump_name); 169 MemoryAllocatorDump* dump = pmd->CreateAllocatorDump(dump_name);
169 dump->AddScalar(MemoryAllocatorDump::kNameSize, 170 dump->AddScalar(MemoryAllocatorDump::kNameSize,
170 MemoryAllocatorDump::kUnitsBytes, allocated_memory_); 171 MemoryAllocatorDump::kUnitsBytes, allocated_memory_);
171 172
172 // Early out, no need for more detail in a BACKGROUND dump. 173 // Early out, no need for more detail in a BACKGROUND dump.
173 return true; 174 return true;
174 } 175 }
175 176
176 const uint64_t tracing_process_id =
177 base::trace_event::MemoryDumpManager::GetInstance()
178 ->GetTracingProcessId();
179 for (const auto& chunk : chunks_) { 177 for (const auto& chunk : chunks_) {
180 std::string dump_name = base::StringPrintf( 178 std::string dump_name = base::StringPrintf(
181 "gpu/mapped_memory/manager_%d/chunk_%d", tracing_id_, chunk->shm_id()); 179 "gpu/mapped_memory/manager_%d/chunk_%d", tracing_id_, chunk->shm_id());
182 MemoryAllocatorDump* dump = pmd->CreateAllocatorDump(dump_name); 180 MemoryAllocatorDump* dump = pmd->CreateAllocatorDump(dump_name);
183 181
184 dump->AddScalar(MemoryAllocatorDump::kNameSize, 182 dump->AddScalar(MemoryAllocatorDump::kNameSize,
185 MemoryAllocatorDump::kUnitsBytes, chunk->GetSize()); 183 MemoryAllocatorDump::kUnitsBytes, chunk->GetSize());
186 dump->AddScalar("free_size", MemoryAllocatorDump::kUnitsBytes, 184 dump->AddScalar("free_size", MemoryAllocatorDump::kUnitsBytes,
187 chunk->GetFreeSize()); 185 chunk->GetFreeSize());
188 186
189 auto guid = GetBufferGUIDForTracing(tracing_process_id, chunk->shm_id()); 187 auto* shared_memory = chunk->buffer()->backing()->shared_memory();
190 188 if (shared_memory) {
191 const int kImportance = 2; 189 base::SharedMemoryTracker::AddOwnershipEdges(pmd, dump->guid(),
192 pmd->CreateSharedGlobalAllocatorDump(guid); 190 *shared_memory);
193 pmd->AddOwnershipEdge(dump->guid(), guid, kImportance); 191 } else {
192 const uint64_t tracing_process_id =
193 base::trace_event::MemoryDumpManager::GetInstance()
194 ->GetTracingProcessId();
195 auto guid = GetBufferGUIDForTracing(tracing_process_id, chunk->shm_id());
196 const int kImportance = 2;
197 pmd->CreateSharedGlobalAllocatorDump(guid);
198 pmd->AddOwnershipEdge(dump->guid(), guid, kImportance);
199 }
194 } 200 }
195 201
196 return true; 202 return true;
197 } 203 }
198 204
199 void ScopedMappedMemoryPtr::Release() { 205 void ScopedMappedMemoryPtr::Release() {
200 if (buffer_) { 206 if (buffer_) {
201 mapped_memory_manager_->FreePendingToken(buffer_, helper_->InsertToken()); 207 mapped_memory_manager_->FreePendingToken(buffer_, helper_->InsertToken());
202 buffer_ = nullptr; 208 buffer_ = nullptr;
203 size_ = 0; 209 size_ = 0;
204 shm_id_ = 0; 210 shm_id_ = 0;
205 shm_offset_ = 0; 211 shm_offset_ = 0;
206 212
207 if (flush_after_release_) 213 if (flush_after_release_)
208 helper_->CommandBufferHelper::Flush(); 214 helper_->CommandBufferHelper::Flush();
209 } 215 }
210 } 216 }
211 217
212 void ScopedMappedMemoryPtr::Reset(uint32_t new_size) { 218 void ScopedMappedMemoryPtr::Reset(uint32_t new_size) {
213 Release(); 219 Release();
214 220
215 if (new_size) { 221 if (new_size) {
216 buffer_ = mapped_memory_manager_->Alloc(new_size, &shm_id_, &shm_offset_); 222 buffer_ = mapped_memory_manager_->Alloc(new_size, &shm_id_, &shm_offset_);
217 size_ = buffer_ ? new_size : 0; 223 size_ = buffer_ ? new_size : 0;
218 } 224 }
219 } 225 }
220 226
221 } // namespace gpu 227 } // namespace gpu
OLDNEW
« no previous file with comments | « gpu/command_buffer/client/mapped_memory.h ('k') | gpu/command_buffer/client/transfer_buffer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698