OLD | NEW |
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 "gpu/ipc/service/gpu_memory_manager.h" | 5 #include "gpu/ipc/service/gpu_memory_manager.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
11 #include "base/message_loop/message_loop.h" | 11 #include "base/message_loop/message_loop.h" |
12 #include "base/process/process_handle.h" | 12 #include "base/process/process_handle.h" |
13 #include "base/strings/string_number_conversions.h" | 13 #include "base/strings/string_number_conversions.h" |
14 #include "base/trace_event/trace_event.h" | 14 #include "base/trace_event/trace_event.h" |
15 #include "gpu/command_buffer/common/gpu_memory_allocation.h" | 15 #include "gpu/command_buffer/common/gpu_memory_allocation.h" |
16 #include "gpu/command_buffer/service/gpu_switches.h" | 16 #include "gpu/command_buffer/service/gpu_switches.h" |
17 #include "gpu/ipc/common/gpu_memory_uma_stats.h" | |
18 #include "gpu/ipc/common/memory_stats.h" | 17 #include "gpu/ipc/common/memory_stats.h" |
19 #include "gpu/ipc/service/gpu_channel_manager.h" | 18 #include "gpu/ipc/service/gpu_channel_manager.h" |
20 #include "gpu/ipc/service/gpu_channel_manager_delegate.h" | 19 #include "gpu/ipc/service/gpu_channel_manager_delegate.h" |
21 #include "gpu/ipc/service/gpu_memory_tracking.h" | 20 #include "gpu/ipc/service/gpu_memory_tracking.h" |
22 | 21 |
23 namespace gpu { | 22 namespace gpu { |
24 namespace { | 23 namespace { |
25 | 24 |
26 const uint64_t kBytesAllocatedStep = 16 * 1024 * 1024; | |
27 | |
28 void TrackValueChanged(uint64_t old_size, | 25 void TrackValueChanged(uint64_t old_size, |
29 uint64_t new_size, | 26 uint64_t new_size, |
30 uint64_t* total_size) { | 27 uint64_t* total_size) { |
31 DCHECK(new_size > old_size || *total_size >= (old_size - new_size)); | 28 DCHECK(new_size > old_size || *total_size >= (old_size - new_size)); |
32 *total_size += (new_size - old_size); | 29 *total_size += (new_size - old_size); |
33 } | 30 } |
34 | 31 |
35 } | 32 } |
36 | 33 |
37 GpuMemoryManager::GpuMemoryManager(GpuChannelManager* channel_manager) | 34 GpuMemoryManager::GpuMemoryManager(GpuChannelManager* channel_manager) |
38 : channel_manager_(channel_manager), | 35 : channel_manager_(channel_manager), |
39 bytes_allocated_current_(0), | 36 bytes_allocated_current_(0) {} |
40 bytes_allocated_historical_max_(0) {} | |
41 | 37 |
42 GpuMemoryManager::~GpuMemoryManager() { | 38 GpuMemoryManager::~GpuMemoryManager() { |
43 DCHECK(tracking_groups_.empty()); | 39 DCHECK(tracking_groups_.empty()); |
44 DCHECK(!bytes_allocated_current_); | 40 DCHECK(!bytes_allocated_current_); |
45 } | 41 } |
46 | 42 |
47 void GpuMemoryManager::TrackMemoryAllocatedChange( | 43 void GpuMemoryManager::TrackMemoryAllocatedChange( |
48 GpuMemoryTrackingGroup* tracking_group, | 44 GpuMemoryTrackingGroup* tracking_group, |
49 uint64_t old_size, | 45 uint64_t old_size, |
50 uint64_t new_size) { | 46 uint64_t new_size) { |
51 TrackValueChanged(old_size, new_size, &tracking_group->size_); | 47 TrackValueChanged(old_size, new_size, &tracking_group->size_); |
52 TrackValueChanged(old_size, new_size, &bytes_allocated_current_); | 48 TrackValueChanged(old_size, new_size, &bytes_allocated_current_); |
53 | |
54 if (GetCurrentUsage() > bytes_allocated_historical_max_ + | |
55 kBytesAllocatedStep) { | |
56 bytes_allocated_historical_max_ = GetCurrentUsage(); | |
57 // If we're blowing into new memory usage territory, spam the browser | |
58 // process with the most up-to-date information about our memory usage. | |
59 SendUmaStatsToHost(); | |
60 } | |
61 } | 49 } |
62 | 50 |
63 bool GpuMemoryManager::EnsureGPUMemoryAvailable(uint64_t /* size_needed */) { | 51 bool GpuMemoryManager::EnsureGPUMemoryAvailable(uint64_t /* size_needed */) { |
64 // TODO: Check if there is enough space. Lose contexts until there is. | 52 // TODO: Check if there is enough space. Lose contexts until there is. |
65 return true; | 53 return true; |
66 } | 54 } |
67 | 55 |
68 uint64_t GpuMemoryManager::GetTrackerMemoryUsage( | 56 uint64_t GpuMemoryManager::GetTrackerMemoryUsage( |
69 gles2::MemoryTracker* tracker) const { | 57 gles2::MemoryTracker* tracker) const { |
70 TrackingGroupMap::const_iterator tracking_group_it = | 58 TrackingGroupMap::const_iterator tracking_group_it = |
(...skipping 29 matching lines...) Expand all Loading... |
100 tracking_group->GetPid()].video_memory += tracking_group->GetSize(); | 88 tracking_group->GetPid()].video_memory += tracking_group->GetSize(); |
101 } | 89 } |
102 | 90 |
103 // Assign the total across all processes in the GPU process | 91 // Assign the total across all processes in the GPU process |
104 video_memory_usage_stats->process_map[ | 92 video_memory_usage_stats->process_map[ |
105 base::GetCurrentProcId()].video_memory = GetCurrentUsage(); | 93 base::GetCurrentProcId()].video_memory = GetCurrentUsage(); |
106 video_memory_usage_stats->process_map[ | 94 video_memory_usage_stats->process_map[ |
107 base::GetCurrentProcId()].has_duplicates = true; | 95 base::GetCurrentProcId()].has_duplicates = true; |
108 | 96 |
109 video_memory_usage_stats->bytes_allocated = GetCurrentUsage(); | 97 video_memory_usage_stats->bytes_allocated = GetCurrentUsage(); |
110 video_memory_usage_stats->bytes_allocated_historical_max = | |
111 bytes_allocated_historical_max_; | |
112 } | 98 } |
113 | 99 |
114 void GpuMemoryManager::SendUmaStatsToHost() { | |
115 if (!channel_manager_) | |
116 return; | |
117 GPUMemoryUmaStats params; | |
118 params.bytes_allocated_current = GetCurrentUsage(); | |
119 params.bytes_allocated_max = bytes_allocated_historical_max_; | |
120 params.context_group_count = static_cast<uint32_t>(tracking_groups_.size()); | |
121 channel_manager_->delegate()->GpuMemoryUmaStats(params); | |
122 } | |
123 } // namespace gpu | 100 } // namespace gpu |
OLD | NEW |