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

Side by Side Diff: content/common/gpu/gpu_memory_manager.cc

Issue 10854076: Add GPU memory tab to the task manager. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Incorporate taskman feedback Created 8 years, 4 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 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 "content/common/gpu/gpu_memory_manager.h" 5 #include "content/common/gpu/gpu_memory_manager.h"
6 6
7 #if defined(ENABLE_GPU) 7 #if defined(ENABLE_GPU)
8 8
9 #include <algorithm> 9 #include <algorithm>
10 10
11 #include "base/bind.h" 11 #include "base/bind.h"
12 #include "base/command_line.h" 12 #include "base/command_line.h"
13 #include "base/debug/trace_event.h" 13 #include "base/debug/trace_event.h"
14 #include "base/message_loop.h" 14 #include "base/message_loop.h"
15 #include "base/process_util.h"
15 #include "base/string_number_conversions.h" 16 #include "base/string_number_conversions.h"
16 #include "content/common/gpu/gpu_command_buffer_stub.h" 17 #include "content/common/gpu/gpu_command_buffer_stub.h"
17 #include "content/common/gpu/gpu_memory_allocation.h" 18 #include "content/common/gpu/gpu_memory_allocation.h"
18 #include "gpu/command_buffer/service/gpu_switches.h" 19 #include "gpu/command_buffer/service/gpu_switches.h"
19 20
20 namespace { 21 namespace {
21 22
22 const int kDelayedScheduleManageTimeoutMs = 67; 23 const int kDelayedScheduleManageTimeoutMs = 67;
23 24
24 bool IsInSameContextShareGroupAsAnyOf( 25 bool IsInSameContextShareGroupAsAnyOf(
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
85 } else { 86 } else {
86 #if defined(OS_ANDROID) 87 #if defined(OS_ANDROID)
87 bytes_available_gpu_memory_ = 64 * 1024 * 1024; 88 bytes_available_gpu_memory_ = 64 * 1024 * 1024;
88 #else 89 #else
89 bytes_available_gpu_memory_ = 448 * 1024 * 1024; 90 bytes_available_gpu_memory_ = 448 * 1024 * 1024;
90 #endif 91 #endif
91 } 92 }
92 } 93 }
93 94
94 GpuMemoryManager::~GpuMemoryManager() { 95 GpuMemoryManager::~GpuMemoryManager() {
96 DCHECK(tracking_groups_.empty());
95 } 97 }
96 98
97 bool GpuMemoryManager::StubWithSurfaceComparator::operator()( 99 bool GpuMemoryManager::StubWithSurfaceComparator::operator()(
98 GpuCommandBufferStubBase* lhs, 100 GpuCommandBufferStubBase* lhs,
99 GpuCommandBufferStubBase* rhs) { 101 GpuCommandBufferStubBase* rhs) {
100 DCHECK(lhs->has_surface_state() && rhs->has_surface_state()); 102 DCHECK(lhs->has_surface_state() && rhs->has_surface_state());
101 const GpuCommandBufferStubBase::SurfaceState& lhs_ss = lhs->surface_state(); 103 const GpuCommandBufferStubBase::SurfaceState& lhs_ss = lhs->surface_state();
102 const GpuCommandBufferStubBase::SurfaceState& rhs_ss = rhs->surface_state(); 104 const GpuCommandBufferStubBase::SurfaceState& rhs_ss = rhs->surface_state();
103 if (lhs_ss.visible) 105 if (lhs_ss.visible)
104 return !rhs_ss.visible || (lhs_ss.last_used_time > rhs_ss.last_used_time); 106 return !rhs_ss.visible || (lhs_ss.last_used_time > rhs_ss.last_used_time);
(...skipping 17 matching lines...) Expand all
122 delayed_manage_callback_.Reset(base::Bind(&GpuMemoryManager::Manage, 124 delayed_manage_callback_.Reset(base::Bind(&GpuMemoryManager::Manage,
123 AsWeakPtr())); 125 AsWeakPtr()));
124 MessageLoop::current()->PostDelayedTask( 126 MessageLoop::current()->PostDelayedTask(
125 FROM_HERE, 127 FROM_HERE,
126 delayed_manage_callback_.callback(), 128 delayed_manage_callback_.callback(),
127 base::TimeDelta::FromMilliseconds(kDelayedScheduleManageTimeoutMs)); 129 base::TimeDelta::FromMilliseconds(kDelayedScheduleManageTimeoutMs));
128 } 130 }
129 } 131 }
130 132
131 void GpuMemoryManager::TrackMemoryAllocatedChange(size_t old_size, 133 void GpuMemoryManager::TrackMemoryAllocatedChange(size_t old_size,
132 size_t new_size) 134 size_t new_size) {
133 {
134 if (new_size < old_size) { 135 if (new_size < old_size) {
135 size_t delta = old_size - new_size; 136 size_t delta = old_size - new_size;
136 DCHECK(bytes_allocated_current_ >= delta); 137 DCHECK(bytes_allocated_current_ >= delta);
137 bytes_allocated_current_ -= delta; 138 bytes_allocated_current_ -= delta;
138 } else { 139 } else {
139 size_t delta = new_size - old_size; 140 size_t delta = new_size - old_size;
140 bytes_allocated_current_ += delta; 141 bytes_allocated_current_ += delta;
141 if (bytes_allocated_current_ > bytes_allocated_historical_max_) { 142 if (bytes_allocated_current_ > bytes_allocated_historical_max_) {
142 bytes_allocated_historical_max_ = bytes_allocated_current_; 143 bytes_allocated_historical_max_ = bytes_allocated_current_;
143 } 144 }
144 } 145 }
145 if (new_size != old_size) { 146 if (new_size != old_size) {
146 TRACE_COUNTER_ID1("GpuMemoryManager", 147 TRACE_COUNTER_ID1("GpuMemoryManager",
147 "GpuMemoryUsage", 148 "GpuMemoryUsage",
148 this, 149 this,
149 bytes_allocated_current_); 150 bytes_allocated_current_);
150 } 151 }
151 } 152 }
152 153
154 void GpuMemoryManager::AddTrackingGroup(
155 GpuMemoryTrackingGroup* tracking_group) {
156 tracking_groups_.insert(tracking_group);
157 }
158
159 void GpuMemoryManager::RemoveTrackingGroup(
160 GpuMemoryTrackingGroup* tracking_group) {
161 tracking_groups_.erase(tracking_group);
162 }
163
164 void GpuMemoryManager::GetVidmemUsageStats(
165 content::GPUVidmemUsageStats& vidmem_usage_stats) const {
166 // For each context group, assign its memory usage to its PID
167 vidmem_usage_stats.process_map.clear();
168 for (std::set<GpuMemoryTrackingGroup*>::const_iterator i =
169 tracking_groups_.begin(); i != tracking_groups_.end(); ++i) {
170 const GpuMemoryTrackingGroup* tracking_group = (*i);
171 vidmem_usage_stats.process_map[tracking_group->GetPid()].vidmem +=
172 tracking_group->GetSize();
173 }
174
175 // Assign the total across all processes in the GPU process
176 vidmem_usage_stats.process_map[base::GetCurrentProcId()].vidmem =
177 bytes_allocated_current_;
178 vidmem_usage_stats.process_map[base::GetCurrentProcId()].has_duplicates =
179 true;
180 }
181
153 // The current Manage algorithm simply classifies contexts (stubs) into 182 // The current Manage algorithm simply classifies contexts (stubs) into
154 // "foreground", "background", or "hibernated" categories. 183 // "foreground", "background", or "hibernated" categories.
155 // For each of these three categories, there are predefined memory allocation 184 // For each of these three categories, there are predefined memory allocation
156 // limits and front/backbuffer states. 185 // limits and front/backbuffer states.
157 // 186 //
158 // Stubs may or may not have a surfaces, and the rules are different for each. 187 // Stubs may or may not have a surfaces, and the rules are different for each.
159 // 188 //
160 // The rules for categorizing contexts with a surface are: 189 // The rules for categorizing contexts with a surface are:
161 // 1. Foreground: All visible surfaces. 190 // 1. Foreground: All visible surfaces.
162 // * Must have both front and back buffer. 191 // * Must have both front and back buffer.
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after
301 false); 330 false);
302 331
303 AssignMemoryAllocations( 332 AssignMemoryAllocations(
304 &stub_memory_stats_for_last_manage_, 333 &stub_memory_stats_for_last_manage_,
305 stubs_without_surface_hibernated, 334 stubs_without_surface_hibernated,
306 GpuMemoryAllocation(0, GpuMemoryAllocation::kHasNoBuffers), 335 GpuMemoryAllocation(0, GpuMemoryAllocation::kHasNoBuffers),
307 false); 336 false);
308 } 337 }
309 338
310 #endif 339 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698