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

Side by Side Diff: gpu/command_buffer/client/mapped_memory.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 (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 // TODO: importance
192 pmd->CreateSharedGlobalAllocatorDump(guid); 190 base::SharedMemoryTracker::AddOwnershipEdges(
193 pmd->AddOwnershipEdge(dump->guid(), guid, kImportance); 191 pmd, dump->guid(), shared_memory->handle(),
192 shared_memory->mapped_size());
193 }
194 } 194 }
195 195
196 return true; 196 return true;
197 } 197 }
198 198
199 void ScopedMappedMemoryPtr::Release() { 199 void ScopedMappedMemoryPtr::Release() {
200 if (buffer_) { 200 if (buffer_) {
201 mapped_memory_manager_->FreePendingToken(buffer_, helper_->InsertToken()); 201 mapped_memory_manager_->FreePendingToken(buffer_, helper_->InsertToken());
202 buffer_ = nullptr; 202 buffer_ = nullptr;
203 size_ = 0; 203 size_ = 0;
204 shm_id_ = 0; 204 shm_id_ = 0;
205 shm_offset_ = 0; 205 shm_offset_ = 0;
206 206
207 if (flush_after_release_) 207 if (flush_after_release_)
208 helper_->CommandBufferHelper::Flush(); 208 helper_->CommandBufferHelper::Flush();
209 } 209 }
210 } 210 }
211 211
212 void ScopedMappedMemoryPtr::Reset(uint32_t new_size) { 212 void ScopedMappedMemoryPtr::Reset(uint32_t new_size) {
213 Release(); 213 Release();
214 214
215 if (new_size) { 215 if (new_size) {
216 buffer_ = mapped_memory_manager_->Alloc(new_size, &shm_id_, &shm_offset_); 216 buffer_ = mapped_memory_manager_->Alloc(new_size, &shm_id_, &shm_offset_);
217 size_ = buffer_ ? new_size : 0; 217 size_ = buffer_ ? new_size : 0;
218 } 218 }
219 } 219 }
220 220
221 } // namespace gpu 221 } // namespace gpu
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698