Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 Loading... | |
| 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; |
|
Wez
2017/01/23 21:49:10
IIUC getting these wrong should mean that we never
afakhry
2017/02/09 01:26:59
Your understanding is correct.
That's why you mu
| |
| 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 Loading... | |
| 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 Loading... | |
| 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 !tasks_.empty()) { |
| 184 RefreshNaClDebugStubPort(tasks_[0]->GetChildProcessUniqueID()); | 185 RefreshNaClDebugStubPort(tasks_[0]->GetChildProcessUniqueID()); |
| 185 } | 186 } |
| 186 #endif // !defined(DISABLE_NACL) | 187 #endif // !defined(DISABLE_NACL) |
| 187 | 188 |
| 188 int64_t shared_refresh_flags = | 189 int64_t shared_refresh_flags = |
| 189 refresh_flags & shared_sampler_->GetSupportedFlags(); | 190 refresh_flags & shared_sampler_->GetSupportedFlags(); |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 248 void TaskGroup::RefreshWindowsHandles() { | 249 void TaskGroup::RefreshWindowsHandles() { |
| 249 #if defined(OS_WIN) | 250 #if defined(OS_WIN) |
| 250 GetWindowsHandles(process_handle_, | 251 GetWindowsHandles(process_handle_, |
| 251 &gdi_current_handles_, | 252 &gdi_current_handles_, |
| 252 &gdi_peak_handles_, | 253 &gdi_peak_handles_, |
| 253 &user_current_handles_, | 254 &user_current_handles_, |
| 254 &user_peak_handles_); | 255 &user_peak_handles_); |
| 255 #endif // defined(OS_WIN) | 256 #endif // defined(OS_WIN) |
| 256 } | 257 } |
| 257 | 258 |
| 259 #if !defined(DISABLE_NACL) | |
| 260 static int GetNaClDebugStubPortOnIoThread(int process_id) { | |
| 261 return nacl::NaClBrowser::GetInstance()->GetProcessGdbDebugStubPort( | |
| 262 process_id); | |
| 263 } | |
|
afakhry
2017/02/09 01:26:59
Nit: To keep the organization of the current code
| |
| 264 | |
| 258 void TaskGroup::RefreshNaClDebugStubPort(int child_process_unique_id) { | 265 void TaskGroup::RefreshNaClDebugStubPort(int child_process_unique_id) { |
| 259 #if !defined(DISABLE_NACL) | 266 content::BrowserThread::PostTaskAndReplyWithResult( |
| 260 nacl::NaClBrowser* nacl_browser = nacl::NaClBrowser::GetInstance(); | 267 content::BrowserThread::IO, FROM_HERE, |
| 261 nacl_debug_stub_port_ = | 268 base::Bind(&GetNaClDebugStubPortOnIoThread, child_process_unique_id), |
| 262 nacl_browser->GetProcessGdbDebugStubPort(child_process_unique_id); | 269 base::Bind(&TaskGroup::OnRefreshNaClDebugStubPortDone, |
| 270 weak_ptr_factory_.GetWeakPtr())); | |
| 271 } | |
| 272 | |
| 273 void TaskGroup::OnRefreshNaClDebugStubPortDone(int nacl_debug_stub_port) { | |
| 274 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | |
| 275 | |
| 276 nacl_debug_stub_port_ = nacl_debug_stub_port; | |
| 277 OnBackgroundRefreshTypeFinished(REFRESH_TYPE_NACL); | |
| 278 } | |
| 263 #endif // !defined(DISABLE_NACL) | 279 #endif // !defined(DISABLE_NACL) |
| 264 } | |
| 265 | 280 |
| 266 void TaskGroup::OnCpuRefreshDone(double cpu_usage) { | 281 void TaskGroup::OnCpuRefreshDone(double cpu_usage) { |
| 267 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 282 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 268 | 283 |
| 269 cpu_usage_ = cpu_usage; | 284 cpu_usage_ = cpu_usage; |
| 270 OnBackgroundRefreshTypeFinished(REFRESH_TYPE_CPU); | 285 OnBackgroundRefreshTypeFinished(REFRESH_TYPE_CPU); |
| 271 } | 286 } |
| 272 | 287 |
| 273 void TaskGroup::OnStartTimeRefreshDone(base::Time start_time) { | 288 void TaskGroup::OnStartTimeRefreshDone(base::Time start_time) { |
| 274 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 289 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 331 | 346 |
| 332 void TaskGroup::OnBackgroundRefreshTypeFinished(int64_t finished_refresh_type) { | 347 void TaskGroup::OnBackgroundRefreshTypeFinished(int64_t finished_refresh_type) { |
| 333 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 348 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 334 | 349 |
| 335 current_on_bg_done_flags_ |= finished_refresh_type; | 350 current_on_bg_done_flags_ |= finished_refresh_type; |
| 336 if (AreBackgroundCalculationsDone()) | 351 if (AreBackgroundCalculationsDone()) |
| 337 on_background_calculations_done_.Run(); | 352 on_background_calculations_done_.Run(); |
| 338 } | 353 } |
| 339 | 354 |
| 340 } // namespace task_manager | 355 } // namespace task_manager |
| OLD | NEW |