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

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

Issue 2646623004: Query NaCl processes' GDB debug port on the correct thread. (Closed)
Patch Set: Add TaskGroup unit-tests Created 3 years, 10 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_manager/sampling/task_group.h" 5 #include "chrome/browser/task_manager/sampling/task_group.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <limits> 8 #include <limits>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 13 matching lines...) Expand all
24 24
25 // A mask for the refresh types that are done in the background thread. 25 // A mask for the refresh types that are done in the background thread.
26 const int kBackgroundRefreshTypesMask = 26 const int kBackgroundRefreshTypesMask =
27 REFRESH_TYPE_CPU | REFRESH_TYPE_MEMORY | REFRESH_TYPE_IDLE_WAKEUPS | 27 REFRESH_TYPE_CPU | REFRESH_TYPE_MEMORY | REFRESH_TYPE_IDLE_WAKEUPS |
28 #if defined(OS_WIN) 28 #if defined(OS_WIN)
29 REFRESH_TYPE_START_TIME | REFRESH_TYPE_CPU_TIME | 29 REFRESH_TYPE_START_TIME | REFRESH_TYPE_CPU_TIME |
30 #endif // defined(OS_WIN) 30 #endif // defined(OS_WIN)
31 #if defined(OS_LINUX) 31 #if defined(OS_LINUX)
32 REFRESH_TYPE_FD_COUNT | 32 REFRESH_TYPE_FD_COUNT |
33 #endif // defined(OS_LINUX) 33 #endif // defined(OS_LINUX)
34 REFRESH_TYPE_PRIORITY; 34 REFRESH_TYPE_NACL | REFRESH_TYPE_PRIORITY;
afakhry 2017/02/10 20:08:52 You still need to wrap REFRESH_TYPE_NACL inside:
Wez 2017/02/13 01:22:19 Done.
35 35
36 #if defined(OS_WIN) 36 #if defined(OS_WIN)
37 // Gets the GDI and USER Handles on Windows at one shot. 37 // Gets the GDI and USER Handles on Windows at one shot.
38 void GetWindowsHandles(base::ProcessHandle handle, 38 void GetWindowsHandles(base::ProcessHandle handle,
39 int64_t* out_gdi_current, 39 int64_t* out_gdi_current,
40 int64_t* out_gdi_peak, 40 int64_t* out_gdi_peak,
41 int64_t* out_user_current, 41 int64_t* out_user_current,
42 int64_t* out_user_peak) { 42 int64_t* out_user_peak) {
43 *out_gdi_current = 0; 43 *out_gdi_current = 0;
44 *out_gdi_peak = 0; 44 *out_gdi_peak = 0;
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
82 gpu_memory_(-1), 82 gpu_memory_(-1),
83 memory_state_(base::MemoryState::UNKNOWN), 83 memory_state_(base::MemoryState::UNKNOWN),
84 per_process_network_usage_(-1), 84 per_process_network_usage_(-1),
85 #if defined(OS_WIN) 85 #if defined(OS_WIN)
86 gdi_current_handles_(-1), 86 gdi_current_handles_(-1),
87 gdi_peak_handles_(-1), 87 gdi_peak_handles_(-1),
88 user_current_handles_(-1), 88 user_current_handles_(-1),
89 user_peak_handles_(-1), 89 user_peak_handles_(-1),
90 #endif // defined(OS_WIN) 90 #endif // defined(OS_WIN)
91 #if !defined(DISABLE_NACL) 91 #if !defined(DISABLE_NACL)
92 nacl_debug_stub_port_(-1), 92 nacl_debug_stub_port_(nacl::kGdbDebugStubPortUnknown),
93 #endif // !defined(DISABLE_NACL) 93 #endif // !defined(DISABLE_NACL)
94 idle_wakeups_per_second_(-1), 94 idle_wakeups_per_second_(-1),
95 #if defined(OS_LINUX) 95 #if defined(OS_LINUX)
96 open_fd_count_(-1), 96 open_fd_count_(-1),
97 #endif // defined(OS_LINUX) 97 #endif // defined(OS_LINUX)
98 gpu_memory_has_duplicates_(false), 98 gpu_memory_has_duplicates_(false),
99 is_backgrounded_(false), 99 is_backgrounded_(false),
100 weak_ptr_factory_(this) { 100 weak_ptr_factory_(this) {
101 scoped_refptr<TaskGroupSampler> sampler( 101 scoped_refptr<TaskGroupSampler> sampler(
102 new TaskGroupSampler(base::Process::Open(proc_id), 102 new TaskGroupSampler(base::Process::Open(proc_id),
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
169 } 169 }
170 170
171 // 3- Refresh Windows handles (if enabled). 171 // 3- Refresh Windows handles (if enabled).
172 #if defined(OS_WIN) 172 #if defined(OS_WIN)
173 if (TaskManagerObserver::IsResourceRefreshEnabled(REFRESH_TYPE_HANDLES, 173 if (TaskManagerObserver::IsResourceRefreshEnabled(REFRESH_TYPE_HANDLES,
174 refresh_flags)) { 174 refresh_flags)) {
175 RefreshWindowsHandles(); 175 RefreshWindowsHandles();
176 } 176 }
177 #endif // defined(OS_WIN) 177 #endif // defined(OS_WIN)
178 178
179 // 4- Refresh the NACL debug stub port (if enabled). 179 // 4- Refresh the NACL debug stub port (if enabled). This calls out to
180 // NaClBrowser on the browser's IO thread, completing asynchronously.
180 #if !defined(DISABLE_NACL) 181 #if !defined(DISABLE_NACL)
181 if (TaskManagerObserver::IsResourceRefreshEnabled(REFRESH_TYPE_NACL, 182 if (TaskManagerObserver::IsResourceRefreshEnabled(REFRESH_TYPE_NACL,
182 refresh_flags) && 183 refresh_flags)) {
183 !tasks_.empty()) { 184 if (!tasks_.empty()) {
184 RefreshNaClDebugStubPort(tasks_[0]->GetChildProcessUniqueID()); 185 RefreshNaClDebugStubPort(tasks_[0]->GetChildProcessUniqueID());
186 } else {
187 expected_on_bg_done_flags_ &= ~REFRESH_TYPE_NACL;
afakhry 2017/02/10 20:08:52 Thanks for adding this! Nit: Can you please remov
Wez 2017/02/13 01:22:19 I thought there was a general preference for inclu
afakhry 2017/02/15 02:58:19 That shouldn't happen (See my comment on the unitt
Wez 2017/02/16 22:44:19 Looking at TaskManagerImpl, it's clear that TaskGr
188 }
185 } 189 }
186 #endif // !defined(DISABLE_NACL) 190 #endif // !defined(DISABLE_NACL)
187 191
188 int64_t shared_refresh_flags = 192 int64_t shared_refresh_flags =
189 refresh_flags & shared_sampler_->GetSupportedFlags(); 193 refresh_flags & shared_sampler_->GetSupportedFlags();
190 194
191 // 5- Refresh resources via SharedSampler if the current platform 195 // 5- Refresh resources via SharedSampler if the current platform
192 // implementation supports that. The actual work is done on the worker thread. 196 // implementation supports that. The actual work is done on the worker thread.
193 // At the moment this is supported only on OS_WIN. 197 // At the moment this is supported only on OS_WIN.
194 if (shared_refresh_flags != 0) { 198 if (shared_refresh_flags != 0) {
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
248 void TaskGroup::RefreshWindowsHandles() { 252 void TaskGroup::RefreshWindowsHandles() {
249 #if defined(OS_WIN) 253 #if defined(OS_WIN)
250 GetWindowsHandles(process_handle_, 254 GetWindowsHandles(process_handle_,
251 &gdi_current_handles_, 255 &gdi_current_handles_,
252 &gdi_peak_handles_, 256 &gdi_peak_handles_,
253 &user_current_handles_, 257 &user_current_handles_,
254 &user_peak_handles_); 258 &user_peak_handles_);
255 #endif // defined(OS_WIN) 259 #endif // defined(OS_WIN)
256 } 260 }
257 261
262 #if !defined(DISABLE_NACL)
263 static int GetNaClDebugStubPortOnIoThread(int process_id) {
afakhry 2017/02/10 20:08:52 No DCHECK for IO? Ideally the DCHECK should be pl
Wez 2017/02/13 01:22:19 Yes, that's the change that prompted this patch, i
afakhry 2017/02/15 02:58:19 Acknowledged.
264 return nacl::NaClBrowser::GetInstance()->GetProcessGdbDebugStubPort(
265 process_id);
266 }
267
258 void TaskGroup::RefreshNaClDebugStubPort(int child_process_unique_id) { 268 void TaskGroup::RefreshNaClDebugStubPort(int child_process_unique_id) {
259 #if !defined(DISABLE_NACL) 269 content::BrowserThread::PostTaskAndReplyWithResult(
260 nacl::NaClBrowser* nacl_browser = nacl::NaClBrowser::GetInstance(); 270 content::BrowserThread::IO, FROM_HERE,
261 nacl_debug_stub_port_ = 271 base::Bind(&GetNaClDebugStubPortOnIoThread, child_process_unique_id),
262 nacl_browser->GetProcessGdbDebugStubPort(child_process_unique_id); 272 base::Bind(&TaskGroup::OnRefreshNaClDebugStubPortDone,
273 weak_ptr_factory_.GetWeakPtr()));
274 }
275
276 void TaskGroup::OnRefreshNaClDebugStubPortDone(int nacl_debug_stub_port) {
277 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
278
279 nacl_debug_stub_port_ = nacl_debug_stub_port;
280 OnBackgroundRefreshTypeFinished(REFRESH_TYPE_NACL);
281 }
263 #endif // !defined(DISABLE_NACL) 282 #endif // !defined(DISABLE_NACL)
264 }
265 283
266 void TaskGroup::OnCpuRefreshDone(double cpu_usage) { 284 void TaskGroup::OnCpuRefreshDone(double cpu_usage) {
267 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 285 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
268 286
269 cpu_usage_ = cpu_usage; 287 cpu_usage_ = cpu_usage;
270 OnBackgroundRefreshTypeFinished(REFRESH_TYPE_CPU); 288 OnBackgroundRefreshTypeFinished(REFRESH_TYPE_CPU);
271 } 289 }
272 290
273 void TaskGroup::OnStartTimeRefreshDone(base::Time start_time) { 291 void TaskGroup::OnStartTimeRefreshDone(base::Time start_time) {
274 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 292 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
331 349
332 void TaskGroup::OnBackgroundRefreshTypeFinished(int64_t finished_refresh_type) { 350 void TaskGroup::OnBackgroundRefreshTypeFinished(int64_t finished_refresh_type) {
333 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 351 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
334 352
335 current_on_bg_done_flags_ |= finished_refresh_type; 353 current_on_bg_done_flags_ |= finished_refresh_type;
336 if (AreBackgroundCalculationsDone()) 354 if (AreBackgroundCalculationsDone())
337 on_background_calculations_done_.Run(); 355 on_background_calculations_done_.Run();
338 } 356 }
339 357
340 } // namespace task_manager 358 } // namespace task_manager
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698