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

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: Address review comments 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 #if !defined(DISABLE_NACL)
35 REFRESH_TYPE_NACL |
36 #endif // !defined(DISABLE_NACL)
34 REFRESH_TYPE_PRIORITY; 37 REFRESH_TYPE_PRIORITY;
35 38
36 #if defined(OS_WIN) 39 #if defined(OS_WIN)
37 // Gets the GDI and USER Handles on Windows at one shot. 40 // Gets the GDI and USER Handles on Windows at one shot.
38 void GetWindowsHandles(base::ProcessHandle handle, 41 void GetWindowsHandles(base::ProcessHandle handle,
39 int64_t* out_gdi_current, 42 int64_t* out_gdi_current,
40 int64_t* out_gdi_peak, 43 int64_t* out_gdi_peak,
41 int64_t* out_user_current, 44 int64_t* out_user_current,
42 int64_t* out_user_peak) { 45 int64_t* out_user_peak) {
43 *out_gdi_current = 0; 46 *out_gdi_current = 0;
(...skipping 12 matching lines...) Expand all
56 GetGuiResources(process_with_query_rights, GR_GDIOBJECTS_PEAK)); 59 GetGuiResources(process_with_query_rights, GR_GDIOBJECTS_PEAK));
57 *out_user_current = static_cast<int64_t>( 60 *out_user_current = static_cast<int64_t>(
58 GetGuiResources(process_with_query_rights, GR_USEROBJECTS)); 61 GetGuiResources(process_with_query_rights, GR_USEROBJECTS));
59 *out_user_peak = static_cast<int64_t>( 62 *out_user_peak = static_cast<int64_t>(
60 GetGuiResources(process_with_query_rights, GR_USEROBJECTS_PEAK)); 63 GetGuiResources(process_with_query_rights, GR_USEROBJECTS_PEAK));
61 CloseHandle(process_with_query_rights); 64 CloseHandle(process_with_query_rights);
62 } 65 }
63 } 66 }
64 #endif // defined(OS_WIN) 67 #endif // defined(OS_WIN)
65 68
69 #if !defined(DISABLE_NACL)
70 int GetNaClDebugStubPortOnIoThread(int process_id) {
71 return nacl::NaClBrowser::GetInstance()->GetProcessGdbDebugStubPort(
72 process_id);
73 }
74 #endif // !defined(DISABLE_NACL)
75
66 } // namespace 76 } // namespace
67 77
68 TaskGroup::TaskGroup( 78 TaskGroup::TaskGroup(
69 base::ProcessHandle proc_handle, 79 base::ProcessHandle proc_handle,
70 base::ProcessId proc_id, 80 base::ProcessId proc_id,
71 const base::Closure& on_background_calculations_done, 81 const base::Closure& on_background_calculations_done,
72 const scoped_refptr<SharedSampler>& shared_sampler, 82 const scoped_refptr<SharedSampler>& shared_sampler,
73 const scoped_refptr<base::SequencedTaskRunner>& blocking_pool_runner) 83 const scoped_refptr<base::SequencedTaskRunner>& blocking_pool_runner)
74 : process_handle_(proc_handle), 84 : process_handle_(proc_handle),
75 process_id_(proc_id), 85 process_id_(proc_id),
76 on_background_calculations_done_(on_background_calculations_done), 86 on_background_calculations_done_(on_background_calculations_done),
77 worker_thread_sampler_(nullptr), 87 worker_thread_sampler_(nullptr),
78 shared_sampler_(shared_sampler), 88 shared_sampler_(shared_sampler),
79 expected_on_bg_done_flags_(kBackgroundRefreshTypesMask), 89 expected_on_bg_done_flags_(kBackgroundRefreshTypesMask),
80 current_on_bg_done_flags_(0), 90 current_on_bg_done_flags_(0),
81 cpu_usage_(0.0), 91 cpu_usage_(0.0),
82 gpu_memory_(-1), 92 gpu_memory_(-1),
83 memory_state_(base::MemoryState::UNKNOWN), 93 memory_state_(base::MemoryState::UNKNOWN),
84 per_process_network_usage_(-1), 94 per_process_network_usage_(-1),
85 #if defined(OS_WIN) 95 #if defined(OS_WIN)
86 gdi_current_handles_(-1), 96 gdi_current_handles_(-1),
87 gdi_peak_handles_(-1), 97 gdi_peak_handles_(-1),
88 user_current_handles_(-1), 98 user_current_handles_(-1),
89 user_peak_handles_(-1), 99 user_peak_handles_(-1),
90 #endif // defined(OS_WIN) 100 #endif // defined(OS_WIN)
91 #if !defined(DISABLE_NACL) 101 #if !defined(DISABLE_NACL)
92 nacl_debug_stub_port_(-1), 102 nacl_debug_stub_port_(nacl::kGdbDebugStubPortUnknown),
93 #endif // !defined(DISABLE_NACL) 103 #endif // !defined(DISABLE_NACL)
94 idle_wakeups_per_second_(-1), 104 idle_wakeups_per_second_(-1),
95 #if defined(OS_LINUX) 105 #if defined(OS_LINUX)
96 open_fd_count_(-1), 106 open_fd_count_(-1),
97 #endif // defined(OS_LINUX) 107 #endif // defined(OS_LINUX)
98 gpu_memory_has_duplicates_(false), 108 gpu_memory_has_duplicates_(false),
99 is_backgrounded_(false), 109 is_backgrounded_(false),
100 weak_ptr_factory_(this) { 110 weak_ptr_factory_(this) {
101 scoped_refptr<TaskGroupSampler> sampler( 111 scoped_refptr<TaskGroupSampler> sampler(
102 new TaskGroupSampler(base::Process::Open(proc_id), 112 new TaskGroupSampler(base::Process::Open(proc_id),
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
137 147
138 void TaskGroup::RemoveTask(Task* task) { 148 void TaskGroup::RemoveTask(Task* task) {
139 DCHECK(task); 149 DCHECK(task);
140 tasks_.erase(std::remove(tasks_.begin(), tasks_.end(), task), tasks_.end()); 150 tasks_.erase(std::remove(tasks_.begin(), tasks_.end(), task), tasks_.end());
141 } 151 }
142 152
143 void TaskGroup::Refresh(const gpu::VideoMemoryUsageStats& gpu_memory_stats, 153 void TaskGroup::Refresh(const gpu::VideoMemoryUsageStats& gpu_memory_stats,
144 base::TimeDelta update_interval, 154 base::TimeDelta update_interval,
145 int64_t refresh_flags) { 155 int64_t refresh_flags) {
146 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 156 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
157 DCHECK(!empty());
147 158
148 expected_on_bg_done_flags_ = refresh_flags & kBackgroundRefreshTypesMask; 159 expected_on_bg_done_flags_ = refresh_flags & kBackgroundRefreshTypesMask;
149 // If a refresh type was recently disabled, we need to account for that too. 160 // If a refresh type was recently disabled, we need to account for that too.
150 current_on_bg_done_flags_ &= expected_on_bg_done_flags_; 161 current_on_bg_done_flags_ &= expected_on_bg_done_flags_;
151 162
152 // First refresh the enabled non-expensive resources usages on the UI thread. 163 // First refresh the enabled non-expensive resources usages on the UI thread.
153 // 1- Refresh all the tasks as well as the total network usage (if enabled). 164 // 1- Refresh all the tasks as well as the total network usage (if enabled).
154 const bool network_usage_refresh_enabled = 165 const bool network_usage_refresh_enabled =
155 TaskManagerObserver::IsResourceRefreshEnabled(REFRESH_TYPE_NETWORK_USAGE, 166 TaskManagerObserver::IsResourceRefreshEnabled(REFRESH_TYPE_NETWORK_USAGE,
156 refresh_flags); 167 refresh_flags);
(...skipping 12 matching lines...) Expand all
169 } 180 }
170 181
171 // 3- Refresh Windows handles (if enabled). 182 // 3- Refresh Windows handles (if enabled).
172 #if defined(OS_WIN) 183 #if defined(OS_WIN)
173 if (TaskManagerObserver::IsResourceRefreshEnabled(REFRESH_TYPE_HANDLES, 184 if (TaskManagerObserver::IsResourceRefreshEnabled(REFRESH_TYPE_HANDLES,
174 refresh_flags)) { 185 refresh_flags)) {
175 RefreshWindowsHandles(); 186 RefreshWindowsHandles();
176 } 187 }
177 #endif // defined(OS_WIN) 188 #endif // defined(OS_WIN)
178 189
179 // 4- Refresh the NACL debug stub port (if enabled). 190 // 4- Refresh the NACL debug stub port (if enabled). This calls out to
191 // NaClBrowser on the browser's IO thread, completing asynchronously.
180 #if !defined(DISABLE_NACL) 192 #if !defined(DISABLE_NACL)
181 if (TaskManagerObserver::IsResourceRefreshEnabled(REFRESH_TYPE_NACL, 193 if (TaskManagerObserver::IsResourceRefreshEnabled(REFRESH_TYPE_NACL,
182 refresh_flags) && 194 refresh_flags)) {
183 !tasks_.empty()) {
184 RefreshNaClDebugStubPort(tasks_[0]->GetChildProcessUniqueID()); 195 RefreshNaClDebugStubPort(tasks_[0]->GetChildProcessUniqueID());
185 } 196 }
186 #endif // !defined(DISABLE_NACL) 197 #endif // !defined(DISABLE_NACL)
187 198
188 int64_t shared_refresh_flags = 199 int64_t shared_refresh_flags =
189 refresh_flags & shared_sampler_->GetSupportedFlags(); 200 refresh_flags & shared_sampler_->GetSupportedFlags();
190 201
191 // 5- Refresh resources via SharedSampler if the current platform 202 // 5- Refresh resources via SharedSampler if the current platform
192 // implementation supports that. The actual work is done on the worker thread. 203 // implementation supports that. The actual work is done on the worker thread.
193 // At the moment this is supported only on OS_WIN. 204 // At the moment this is supported only on OS_WIN.
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
248 void TaskGroup::RefreshWindowsHandles() { 259 void TaskGroup::RefreshWindowsHandles() {
249 #if defined(OS_WIN) 260 #if defined(OS_WIN)
250 GetWindowsHandles(process_handle_, 261 GetWindowsHandles(process_handle_,
251 &gdi_current_handles_, 262 &gdi_current_handles_,
252 &gdi_peak_handles_, 263 &gdi_peak_handles_,
253 &user_current_handles_, 264 &user_current_handles_,
254 &user_peak_handles_); 265 &user_peak_handles_);
255 #endif // defined(OS_WIN) 266 #endif // defined(OS_WIN)
256 } 267 }
257 268
269 #if !defined(DISABLE_NACL)
258 void TaskGroup::RefreshNaClDebugStubPort(int child_process_unique_id) { 270 void TaskGroup::RefreshNaClDebugStubPort(int child_process_unique_id) {
259 #if !defined(DISABLE_NACL) 271 content::BrowserThread::PostTaskAndReplyWithResult(
260 nacl::NaClBrowser* nacl_browser = nacl::NaClBrowser::GetInstance(); 272 content::BrowserThread::IO, FROM_HERE,
261 nacl_debug_stub_port_ = 273 base::Bind(&GetNaClDebugStubPortOnIoThread, child_process_unique_id),
262 nacl_browser->GetProcessGdbDebugStubPort(child_process_unique_id); 274 base::Bind(&TaskGroup::OnRefreshNaClDebugStubPortDone,
275 weak_ptr_factory_.GetWeakPtr()));
276 }
277
278 void TaskGroup::OnRefreshNaClDebugStubPortDone(int nacl_debug_stub_port) {
279 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
280
281 nacl_debug_stub_port_ = nacl_debug_stub_port;
282 OnBackgroundRefreshTypeFinished(REFRESH_TYPE_NACL);
283 }
263 #endif // !defined(DISABLE_NACL) 284 #endif // !defined(DISABLE_NACL)
264 }
265 285
266 void TaskGroup::OnCpuRefreshDone(double cpu_usage) { 286 void TaskGroup::OnCpuRefreshDone(double cpu_usage) {
267 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 287 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
268 288
269 cpu_usage_ = cpu_usage; 289 cpu_usage_ = cpu_usage;
270 OnBackgroundRefreshTypeFinished(REFRESH_TYPE_CPU); 290 OnBackgroundRefreshTypeFinished(REFRESH_TYPE_CPU);
271 } 291 }
272 292
273 void TaskGroup::OnStartTimeRefreshDone(base::Time start_time) { 293 void TaskGroup::OnStartTimeRefreshDone(base::Time start_time) {
274 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 294 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
331 351
332 void TaskGroup::OnBackgroundRefreshTypeFinished(int64_t finished_refresh_type) { 352 void TaskGroup::OnBackgroundRefreshTypeFinished(int64_t finished_refresh_type) {
333 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 353 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
334 354
335 current_on_bg_done_flags_ |= finished_refresh_type; 355 current_on_bg_done_flags_ |= finished_refresh_type;
336 if (AreBackgroundCalculationsDone()) 356 if (AreBackgroundCalculationsDone())
337 on_background_calculations_done_.Run(); 357 on_background_calculations_done_.Run();
338 } 358 }
339 359
340 } // namespace task_manager 360 } // namespace task_manager
OLDNEW
« no previous file with comments | « chrome/browser/task_manager/sampling/task_group.h ('k') | chrome/browser/task_manager/sampling/task_group_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698