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

Side by Side Diff: cc/raster/staging_buffer_pool.cc

Issue 2382573002: Add BACKGROUND dump mode to various GPU/CC MemoryDumpProviders (Closed)
Patch Set: rebase Created 4 years, 2 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 | « no previous file | cc/resources/resource_pool.cc » ('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 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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/raster/staging_buffer_pool.h" 5 #include "cc/raster/staging_buffer_pool.h"
6 6
7 #include <memory> 7 #include <memory>
8 8
9 #include "base/memory/memory_coordinator_client_registry.h" 9 #include "base/memory/memory_coordinator_client_registry.h"
10 #include "base/memory/ptr_util.h" 10 #include "base/memory/ptr_util.h"
11 #include "base/strings/stringprintf.h" 11 #include "base/strings/stringprintf.h"
12 #include "base/threading/thread_task_runner_handle.h" 12 #include "base/threading/thread_task_runner_handle.h"
13 #include "base/trace_event/memory_dump_manager.h" 13 #include "base/trace_event/memory_dump_manager.h"
14 #include "cc/base/container_util.h" 14 #include "cc/base/container_util.h"
15 #include "cc/debug/traced_value.h" 15 #include "cc/debug/traced_value.h"
16 #include "cc/resources/scoped_resource.h" 16 #include "cc/resources/scoped_resource.h"
17 #include "gpu/command_buffer/client/gles2_interface.h" 17 #include "gpu/command_buffer/client/gles2_interface.h"
18 #include "ui/gfx/gpu_memory_buffer_tracing.h" 18 #include "ui/gfx/gpu_memory_buffer_tracing.h"
19 19
20 using base::trace_event::MemoryAllocatorDump;
21 using base::trace_event::MemoryAllocatorDumpGuid;
22 using base::trace_event::MemoryDumpLevelOfDetail;
23
20 namespace cc { 24 namespace cc {
21 namespace { 25 namespace {
22 26
23 // Delay between checking for query result to be available. 27 // Delay between checking for query result to be available.
24 const int kCheckForQueryResultAvailableTickRateMs = 1; 28 const int kCheckForQueryResultAvailableTickRateMs = 1;
25 29
26 // Number of attempts to allow before we perform a check that will wait for 30 // Number of attempts to allow before we perform a check that will wait for
27 // query to complete. 31 // query to complete.
28 const int kMaxCheckForQueryResultAvailableAttempts = 256; 32 const int kMaxCheckForQueryResultAvailableAttempts = 256;
29 33
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
89 93
90 void StagingBuffer::OnMemoryDump(base::trace_event::ProcessMemoryDump* pmd, 94 void StagingBuffer::OnMemoryDump(base::trace_event::ProcessMemoryDump* pmd,
91 ResourceFormat format, 95 ResourceFormat format,
92 bool in_free_list) const { 96 bool in_free_list) const {
93 if (!gpu_memory_buffer) 97 if (!gpu_memory_buffer)
94 return; 98 return;
95 99
96 gfx::GpuMemoryBufferId buffer_id = gpu_memory_buffer->GetId(); 100 gfx::GpuMemoryBufferId buffer_id = gpu_memory_buffer->GetId();
97 std::string buffer_dump_name = 101 std::string buffer_dump_name =
98 base::StringPrintf("cc/one_copy/staging_memory/buffer_%d", buffer_id.id); 102 base::StringPrintf("cc/one_copy/staging_memory/buffer_%d", buffer_id.id);
99 base::trace_event::MemoryAllocatorDump* buffer_dump = 103 MemoryAllocatorDump* buffer_dump = pmd->CreateAllocatorDump(buffer_dump_name);
100 pmd->CreateAllocatorDump(buffer_dump_name);
101 104
102 uint64_t buffer_size_in_bytes = 105 uint64_t buffer_size_in_bytes =
103 ResourceUtil::UncheckedSizeInBytes<uint64_t>(size, format); 106 ResourceUtil::UncheckedSizeInBytes<uint64_t>(size, format);
104 buffer_dump->AddScalar(base::trace_event::MemoryAllocatorDump::kNameSize, 107 buffer_dump->AddScalar(MemoryAllocatorDump::kNameSize,
105 base::trace_event::MemoryAllocatorDump::kUnitsBytes, 108 MemoryAllocatorDump::kUnitsBytes,
106 buffer_size_in_bytes); 109 buffer_size_in_bytes);
107 buffer_dump->AddScalar("free_size", 110 buffer_dump->AddScalar("free_size", MemoryAllocatorDump::kUnitsBytes,
108 base::trace_event::MemoryAllocatorDump::kUnitsBytes,
109 in_free_list ? buffer_size_in_bytes : 0); 111 in_free_list ? buffer_size_in_bytes : 0);
110 112
111 // Emit an ownership edge towards a global allocator dump node. 113 // Emit an ownership edge towards a global allocator dump node.
112 const uint64_t tracing_process_id = 114 const uint64_t tracing_process_id =
113 base::trace_event::MemoryDumpManager::GetInstance() 115 base::trace_event::MemoryDumpManager::GetInstance()
114 ->GetTracingProcessId(); 116 ->GetTracingProcessId();
115 base::trace_event::MemoryAllocatorDumpGuid shared_buffer_guid = 117 MemoryAllocatorDumpGuid shared_buffer_guid =
116 gfx::GetGpuMemoryBufferGUIDForTracing(tracing_process_id, buffer_id); 118 gfx::GetGpuMemoryBufferGUIDForTracing(tracing_process_id, buffer_id);
117 pmd->CreateSharedGlobalAllocatorDump(shared_buffer_guid); 119 pmd->CreateSharedGlobalAllocatorDump(shared_buffer_guid);
118 120
119 // By creating an edge with a higher |importance| (w.r.t. browser-side dumps) 121 // By creating an edge with a higher |importance| (w.r.t. browser-side dumps)
120 // the tracing UI will account the effective size of the buffer to the child. 122 // the tracing UI will account the effective size of the buffer to the child.
121 const int kImportance = 2; 123 const int kImportance = 2;
122 pmd->AddOwnershipEdge(buffer_dump->guid(), shared_buffer_guid, kImportance); 124 pmd->AddOwnershipEdge(buffer_dump->guid(), shared_buffer_guid, kImportance);
123 } 125 }
124 126
125 StagingBufferPool::StagingBufferPool(base::SequencedTaskRunner* task_runner, 127 StagingBufferPool::StagingBufferPool(base::SequencedTaskRunner* task_runner,
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
180 busy_buffers_.push_back(std::move(staging_buffer)); 182 busy_buffers_.push_back(std::move(staging_buffer));
181 183
182 ScheduleReduceMemoryUsage(); 184 ScheduleReduceMemoryUsage();
183 } 185 }
184 186
185 bool StagingBufferPool::OnMemoryDump( 187 bool StagingBufferPool::OnMemoryDump(
186 const base::trace_event::MemoryDumpArgs& args, 188 const base::trace_event::MemoryDumpArgs& args,
187 base::trace_event::ProcessMemoryDump* pmd) { 189 base::trace_event::ProcessMemoryDump* pmd) {
188 base::AutoLock lock(lock_); 190 base::AutoLock lock(lock_);
189 191
190 for (const auto* buffer : buffers_) { 192 if (args.level_of_detail == MemoryDumpLevelOfDetail::BACKGROUND) {
191 auto in_free_buffers = 193 std::string dump_name("cc/one_copy/staging_memory");
192 std::find_if(free_buffers_.begin(), free_buffers_.end(), 194 MemoryAllocatorDump* dump = pmd->CreateAllocatorDump(dump_name);
193 [buffer](const std::unique_ptr<StagingBuffer>& b) { 195 dump->AddScalar(MemoryAllocatorDump::kNameSize,
194 return b.get() == buffer; 196 MemoryAllocatorDump::kUnitsBytes,
195 }); 197 staging_buffer_usage_in_bytes_);
196 buffer->OnMemoryDump(pmd, buffer->format, 198 } else {
197 in_free_buffers != free_buffers_.end()); 199 for (const auto* buffer : buffers_) {
200 auto in_free_buffers =
201 std::find_if(free_buffers_.begin(), free_buffers_.end(),
202 [buffer](const std::unique_ptr<StagingBuffer>& b) {
203 return b.get() == buffer;
204 });
205 buffer->OnMemoryDump(pmd, buffer->format,
206 in_free_buffers != free_buffers_.end());
207 }
198 } 208 }
199
200 return true; 209 return true;
201 } 210 }
202 211
203 void StagingBufferPool::AddStagingBuffer(const StagingBuffer* staging_buffer, 212 void StagingBufferPool::AddStagingBuffer(const StagingBuffer* staging_buffer,
204 ResourceFormat format) { 213 ResourceFormat format) {
205 lock_.AssertAcquired(); 214 lock_.AssertAcquired();
206 215
207 DCHECK(buffers_.find(staging_buffer) == buffers_.end()); 216 DCHECK(buffers_.find(staging_buffer) == buffers_.end());
208 buffers_.insert(staging_buffer); 217 buffers_.insert(staging_buffer);
209 int buffer_usage_in_bytes = 218 int buffer_usage_in_bytes =
(...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after
437 // Release all buffers, regardless of how recently they were used. 446 // Release all buffers, regardless of how recently they were used.
438 ReleaseBuffersNotUsedSince(base::TimeTicks() + base::TimeDelta::Max()); 447 ReleaseBuffersNotUsedSince(base::TimeTicks() + base::TimeDelta::Max());
439 } break; 448 } break;
440 case base::MemoryState::UNKNOWN: 449 case base::MemoryState::UNKNOWN:
441 // NOT_REACHED. 450 // NOT_REACHED.
442 break; 451 break;
443 } 452 }
444 } 453 }
445 454
446 } // namespace cc 455 } // namespace cc
OLDNEW
« no previous file with comments | « no previous file | cc/resources/resource_pool.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698