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

Side by Side Diff: chrome/browser/task_management/sampling/task_group.cc

Issue 1584473004: Migrate ProcessesEventRouter to the new task manager (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix nit. Created 4 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 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 "chrome/browser/task_management/sampling/task_group.h" 5 #include "chrome/browser/task_management/sampling/task_group.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/callback.h" 8 #include "base/callback.h"
9 #include "base/stl_util.h" 9 #include "base/stl_util.h"
10 #include "build/build_config.h" 10 #include "build/build_config.h"
11 #include "chrome/browser/task_management/task_manager_observer.h" 11 #include "chrome/browser/task_management/task_manager_observer.h"
12 #include "components/nacl/browser/nacl_browser.h" 12 #include "components/nacl/browser/nacl_browser.h"
13 #include "content/public/browser/browser_thread.h" 13 #include "content/public/browser/browser_thread.h"
14 #include "gpu/ipc/common/memory_stats.h" 14 #include "gpu/ipc/common/memory_stats.h"
15 15
16 namespace task_management { 16 namespace task_management {
17 17
18 namespace { 18 namespace {
19 19
20 // A mask for the refresh types that are done in the background thread.
21 const int kBackgroundRefreshTypesMask =
22 REFRESH_TYPE_CPU |
23 REFRESH_TYPE_MEMORY |
24 REFRESH_TYPE_IDLE_WAKEUPS |
25 #if defined(OS_LINUX)
26 REFRESH_TYPE_FD_COUNT |
27 #endif // defined(OS_LINUX)
28 REFRESH_TYPE_PRIORITY;
29
20 inline bool IsResourceRefreshEnabled(RefreshType refresh_type, 30 inline bool IsResourceRefreshEnabled(RefreshType refresh_type,
21 int refresh_flags) { 31 int refresh_flags) {
22 return (refresh_flags & refresh_type) != 0; 32 return (refresh_flags & refresh_type) != 0;
23 } 33 }
24 34
25 #if defined(OS_WIN) 35 #if defined(OS_WIN)
26 // Gets the GDI and USER Handles on Windows at one shot. 36 // Gets the GDI and USER Handles on Windows at one shot.
27 void GetWindowsHandles(base::ProcessHandle handle, 37 void GetWindowsHandles(base::ProcessHandle handle,
28 int64_t* out_gdi_current, 38 int64_t* out_gdi_current,
29 int64_t* out_gdi_peak, 39 int64_t* out_gdi_peak,
(...skipping 20 matching lines...) Expand all
50 CloseHandle(process_with_query_rights); 60 CloseHandle(process_with_query_rights);
51 } 61 }
52 } 62 }
53 #endif // defined(OS_WIN) 63 #endif // defined(OS_WIN)
54 64
55 } // namespace 65 } // namespace
56 66
57 TaskGroup::TaskGroup( 67 TaskGroup::TaskGroup(
58 base::ProcessHandle proc_handle, 68 base::ProcessHandle proc_handle,
59 base::ProcessId proc_id, 69 base::ProcessId proc_id,
70 const base::Closure& on_background_calculations_done,
60 const scoped_refptr<base::SequencedTaskRunner>& blocking_pool_runner) 71 const scoped_refptr<base::SequencedTaskRunner>& blocking_pool_runner)
61 : process_handle_(proc_handle), 72 : process_handle_(proc_handle),
62 process_id_(proc_id), 73 process_id_(proc_id),
74 on_background_calculations_done_(on_background_calculations_done),
63 worker_thread_sampler_(nullptr), 75 worker_thread_sampler_(nullptr),
64 tasks_(), 76 expected_on_bg_done_flags_(kBackgroundRefreshTypesMask),
77 current_on_bg_done_flags_(0),
65 cpu_usage_(0.0), 78 cpu_usage_(0.0),
66 memory_usage_(), 79 memory_usage_(),
67 gpu_memory_(-1), 80 gpu_memory_(-1),
68 per_process_network_usage_(-1), 81 per_process_network_usage_(-1),
69 #if defined(OS_WIN) 82 #if defined(OS_WIN)
70 gdi_current_handles_(-1), 83 gdi_current_handles_(-1),
71 gdi_peak_handles_(-1), 84 gdi_peak_handles_(-1),
72 user_current_handles_(-1), 85 user_current_handles_(-1),
73 user_peak_handles_(-1), 86 user_peak_handles_(-1),
74 #endif // defined(OS_WIN) 87 #endif // defined(OS_WIN)
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
116 DCHECK(ContainsKey(tasks_, task->task_id())); 129 DCHECK(ContainsKey(tasks_, task->task_id()));
117 130
118 tasks_.erase(task->task_id()); 131 tasks_.erase(task->task_id());
119 } 132 }
120 133
121 void TaskGroup::Refresh(const gpu::VideoMemoryUsageStats& gpu_memory_stats, 134 void TaskGroup::Refresh(const gpu::VideoMemoryUsageStats& gpu_memory_stats,
122 base::TimeDelta update_interval, 135 base::TimeDelta update_interval,
123 int64_t refresh_flags) { 136 int64_t refresh_flags) {
124 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 137 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
125 138
139 expected_on_bg_done_flags_ = refresh_flags & kBackgroundRefreshTypesMask;
140 // If a refresh type was recently disabled, we need to account for that too.
141 current_on_bg_done_flags_ &= expected_on_bg_done_flags_;
142
126 // First refresh the enabled non-expensive resources usages on the UI thread. 143 // First refresh the enabled non-expensive resources usages on the UI thread.
127 // 1- Refresh all the tasks as well as the total network usage (if enabled). 144 // 1- Refresh all the tasks as well as the total network usage (if enabled).
128 const bool network_usage_refresh_enabled = 145 const bool network_usage_refresh_enabled =
129 IsResourceRefreshEnabled(REFRESH_TYPE_NETWORK_USAGE, refresh_flags); 146 IsResourceRefreshEnabled(REFRESH_TYPE_NETWORK_USAGE, refresh_flags);
130 per_process_network_usage_ = network_usage_refresh_enabled ? 0 : -1; 147 per_process_network_usage_ = network_usage_refresh_enabled ? 0 : -1;
131 for (auto& task_pair : tasks_) { 148 for (auto& task_pair : tasks_) {
132 Task* task = task_pair.second; 149 Task* task = task_pair.second;
133 task->Refresh(update_interval, refresh_flags); 150 task->Refresh(update_interval, refresh_flags);
134 151
135 if (network_usage_refresh_enabled && task->ReportsNetworkUsage()) { 152 if (network_usage_refresh_enabled && task->ReportsNetworkUsage())
136 per_process_network_usage_ += task->network_usage(); 153 per_process_network_usage_ += task->network_usage();
137 }
138 } 154 }
139 155
140 // 2- Refresh GPU memory (if enabled). 156 // 2- Refresh GPU memory (if enabled).
141 if (IsResourceRefreshEnabled(REFRESH_TYPE_GPU_MEMORY, refresh_flags)) 157 if (IsResourceRefreshEnabled(REFRESH_TYPE_GPU_MEMORY, refresh_flags))
142 RefreshGpuMemory(gpu_memory_stats); 158 RefreshGpuMemory(gpu_memory_stats);
143 159
144 // 3- Refresh Windows handles (if enabled). 160 // 3- Refresh Windows handles (if enabled).
145 #if defined(OS_WIN) 161 #if defined(OS_WIN)
146 if (IsResourceRefreshEnabled(REFRESH_TYPE_HANDLES, refresh_flags)) 162 if (IsResourceRefreshEnabled(REFRESH_TYPE_HANDLES, refresh_flags))
147 RefreshWindowsHandles(); 163 RefreshWindowsHandles();
(...skipping 24 matching lines...) Expand all
172 for (const auto& task_pair : tasks_) 188 for (const auto& task_pair : tasks_)
173 out_list->push_back(task_pair.first); 189 out_list->push_back(task_pair.first);
174 } 190 }
175 191
176 Task* TaskGroup::GetTaskById(TaskId task_id) const { 192 Task* TaskGroup::GetTaskById(TaskId task_id) const {
177 DCHECK(ContainsKey(tasks_, task_id)); 193 DCHECK(ContainsKey(tasks_, task_id));
178 194
179 return tasks_.at(task_id); 195 return tasks_.at(task_id);
180 } 196 }
181 197
198 void TaskGroup::ClearCurrentBackgroundCalculationsFlags() {
199 current_on_bg_done_flags_ = 0;
200 }
201
202 bool TaskGroup::AreBackgroundCalculationsDone() const {
203 return expected_on_bg_done_flags_ == current_on_bg_done_flags_;
204 }
205
182 void TaskGroup::RefreshGpuMemory( 206 void TaskGroup::RefreshGpuMemory(
183 const gpu::VideoMemoryUsageStats& gpu_memory_stats) { 207 const gpu::VideoMemoryUsageStats& gpu_memory_stats) {
184 auto itr = gpu_memory_stats.process_map.find(process_id_); 208 auto itr = gpu_memory_stats.process_map.find(process_id_);
185 if (itr == gpu_memory_stats.process_map.end()) { 209 if (itr == gpu_memory_stats.process_map.end()) {
186 gpu_memory_ = -1; 210 gpu_memory_ = -1;
187 gpu_memory_has_duplicates_ = false; 211 gpu_memory_has_duplicates_ = false;
188 return; 212 return;
189 } 213 }
190 214
191 gpu_memory_ = itr->second.video_memory; 215 gpu_memory_ = itr->second.video_memory;
(...skipping 15 matching lines...) Expand all
207 nacl::NaClBrowser* nacl_browser = nacl::NaClBrowser::GetInstance(); 231 nacl::NaClBrowser* nacl_browser = nacl::NaClBrowser::GetInstance();
208 nacl_debug_stub_port_ = 232 nacl_debug_stub_port_ =
209 nacl_browser->GetProcessGdbDebugStubPort(child_process_unique_id); 233 nacl_browser->GetProcessGdbDebugStubPort(child_process_unique_id);
210 #endif // !defined(DISABLE_NACL) 234 #endif // !defined(DISABLE_NACL)
211 } 235 }
212 236
213 void TaskGroup::OnCpuRefreshDone(double cpu_usage) { 237 void TaskGroup::OnCpuRefreshDone(double cpu_usage) {
214 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 238 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
215 239
216 cpu_usage_ = cpu_usage; 240 cpu_usage_ = cpu_usage;
241 OnBackgroundRefreshTypeFinished(REFRESH_TYPE_CPU);
217 } 242 }
218 243
219 void TaskGroup::OnMemoryUsageRefreshDone(MemoryUsageStats memory_usage) { 244 void TaskGroup::OnMemoryUsageRefreshDone(MemoryUsageStats memory_usage) {
220 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 245 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
221 246
222 memory_usage_ = memory_usage; 247 memory_usage_ = memory_usage;
248 OnBackgroundRefreshTypeFinished(REFRESH_TYPE_MEMORY);
223 } 249 }
224 250
225 void TaskGroup::OnIdleWakeupsRefreshDone(int idle_wakeups_per_second) { 251 void TaskGroup::OnIdleWakeupsRefreshDone(int idle_wakeups_per_second) {
226 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 252 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
227 253
228 idle_wakeups_per_second_ = idle_wakeups_per_second; 254 idle_wakeups_per_second_ = idle_wakeups_per_second;
255 OnBackgroundRefreshTypeFinished(REFRESH_TYPE_IDLE_WAKEUPS);
229 } 256 }
230 257
231 #if defined(OS_LINUX) 258 #if defined(OS_LINUX)
232 void TaskGroup::OnOpenFdCountRefreshDone(int open_fd_count) { 259 void TaskGroup::OnOpenFdCountRefreshDone(int open_fd_count) {
233 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 260 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
234 261
235 open_fd_count_ = open_fd_count; 262 open_fd_count_ = open_fd_count;
263 OnBackgroundRefreshTypeFinished(REFRESH_TYPE_FD_COUNT);
236 } 264 }
237 #endif // defined(OS_LINUX) 265 #endif // defined(OS_LINUX)
238 266
239 void TaskGroup::OnProcessPriorityDone(bool is_backgrounded) { 267 void TaskGroup::OnProcessPriorityDone(bool is_backgrounded) {
240 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 268 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
241 269
242 is_backgrounded_ = is_backgrounded; 270 is_backgrounded_ = is_backgrounded;
271 OnBackgroundRefreshTypeFinished(REFRESH_TYPE_PRIORITY);
272 }
273
274 void TaskGroup::OnBackgroundRefreshTypeFinished(int64_t finished_refresh_type) {
275 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
276
277 current_on_bg_done_flags_ |= finished_refresh_type;
278 if (AreBackgroundCalculationsDone())
279 on_background_calculations_done_.Run();
243 } 280 }
244 281
245 } // namespace task_management 282 } // namespace task_management
OLDNEW
« no previous file with comments | « chrome/browser/task_management/sampling/task_group.h ('k') | chrome/browser/task_management/sampling/task_manager_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698