| 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 #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 Loading... |
| 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 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 169 } | 179 } |
| 170 | 180 |
| 171 // 3- Refresh Windows handles (if enabled). | 181 // 3- Refresh Windows handles (if enabled). |
| 172 #if defined(OS_WIN) | 182 #if defined(OS_WIN) |
| 173 if (TaskManagerObserver::IsResourceRefreshEnabled(REFRESH_TYPE_HANDLES, | 183 if (TaskManagerObserver::IsResourceRefreshEnabled(REFRESH_TYPE_HANDLES, |
| 174 refresh_flags)) { | 184 refresh_flags)) { |
| 175 RefreshWindowsHandles(); | 185 RefreshWindowsHandles(); |
| 176 } | 186 } |
| 177 #endif // defined(OS_WIN) | 187 #endif // defined(OS_WIN) |
| 178 | 188 |
| 179 // 4- Refresh the NACL debug stub port (if enabled). | 189 // 4- Refresh the NACL debug stub port (if enabled). This calls out to |
| 190 // NaClBrowser on the browser's IO thread, completing asynchronously. |
| 180 #if !defined(DISABLE_NACL) | 191 #if !defined(DISABLE_NACL) |
| 181 if (TaskManagerObserver::IsResourceRefreshEnabled(REFRESH_TYPE_NACL, | 192 if (TaskManagerObserver::IsResourceRefreshEnabled(REFRESH_TYPE_NACL, |
| 182 refresh_flags) && | 193 refresh_flags)) { |
| 183 !tasks_.empty()) { | 194 if (!tasks_.empty()) |
| 184 RefreshNaClDebugStubPort(tasks_[0]->GetChildProcessUniqueID()); | 195 RefreshNaClDebugStubPort(tasks_[0]->GetChildProcessUniqueID()); |
| 196 else |
| 197 expected_on_bg_done_flags_ &= ~REFRESH_TYPE_NACL; |
| 185 } | 198 } |
| 186 #endif // !defined(DISABLE_NACL) | 199 #endif // !defined(DISABLE_NACL) |
| 187 | 200 |
| 188 int64_t shared_refresh_flags = | 201 int64_t shared_refresh_flags = |
| 189 refresh_flags & shared_sampler_->GetSupportedFlags(); | 202 refresh_flags & shared_sampler_->GetSupportedFlags(); |
| 190 | 203 |
| 191 // 5- Refresh resources via SharedSampler if the current platform | 204 // 5- Refresh resources via SharedSampler if the current platform |
| 192 // implementation supports that. The actual work is done on the worker thread. | 205 // implementation supports that. The actual work is done on the worker thread. |
| 193 // At the moment this is supported only on OS_WIN. | 206 // At the moment this is supported only on OS_WIN. |
| 194 if (shared_refresh_flags != 0) { | 207 if (shared_refresh_flags != 0) { |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 248 void TaskGroup::RefreshWindowsHandles() { | 261 void TaskGroup::RefreshWindowsHandles() { |
| 249 #if defined(OS_WIN) | 262 #if defined(OS_WIN) |
| 250 GetWindowsHandles(process_handle_, | 263 GetWindowsHandles(process_handle_, |
| 251 &gdi_current_handles_, | 264 &gdi_current_handles_, |
| 252 &gdi_peak_handles_, | 265 &gdi_peak_handles_, |
| 253 &user_current_handles_, | 266 &user_current_handles_, |
| 254 &user_peak_handles_); | 267 &user_peak_handles_); |
| 255 #endif // defined(OS_WIN) | 268 #endif // defined(OS_WIN) |
| 256 } | 269 } |
| 257 | 270 |
| 271 #if !defined(DISABLE_NACL) |
| 258 void TaskGroup::RefreshNaClDebugStubPort(int child_process_unique_id) { | 272 void TaskGroup::RefreshNaClDebugStubPort(int child_process_unique_id) { |
| 259 #if !defined(DISABLE_NACL) | 273 content::BrowserThread::PostTaskAndReplyWithResult( |
| 260 nacl::NaClBrowser* nacl_browser = nacl::NaClBrowser::GetInstance(); | 274 content::BrowserThread::IO, FROM_HERE, |
| 261 nacl_debug_stub_port_ = | 275 base::Bind(&GetNaClDebugStubPortOnIoThread, child_process_unique_id), |
| 262 nacl_browser->GetProcessGdbDebugStubPort(child_process_unique_id); | 276 base::Bind(&TaskGroup::OnRefreshNaClDebugStubPortDone, |
| 277 weak_ptr_factory_.GetWeakPtr())); |
| 278 } |
| 279 |
| 280 void TaskGroup::OnRefreshNaClDebugStubPortDone(int nacl_debug_stub_port) { |
| 281 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 282 |
| 283 nacl_debug_stub_port_ = nacl_debug_stub_port; |
| 284 OnBackgroundRefreshTypeFinished(REFRESH_TYPE_NACL); |
| 285 } |
| 263 #endif // !defined(DISABLE_NACL) | 286 #endif // !defined(DISABLE_NACL) |
| 264 } | |
| 265 | 287 |
| 266 void TaskGroup::OnCpuRefreshDone(double cpu_usage) { | 288 void TaskGroup::OnCpuRefreshDone(double cpu_usage) { |
| 267 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 289 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 268 | 290 |
| 269 cpu_usage_ = cpu_usage; | 291 cpu_usage_ = cpu_usage; |
| 270 OnBackgroundRefreshTypeFinished(REFRESH_TYPE_CPU); | 292 OnBackgroundRefreshTypeFinished(REFRESH_TYPE_CPU); |
| 271 } | 293 } |
| 272 | 294 |
| 273 void TaskGroup::OnStartTimeRefreshDone(base::Time start_time) { | 295 void TaskGroup::OnStartTimeRefreshDone(base::Time start_time) { |
| 274 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 296 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 331 | 353 |
| 332 void TaskGroup::OnBackgroundRefreshTypeFinished(int64_t finished_refresh_type) { | 354 void TaskGroup::OnBackgroundRefreshTypeFinished(int64_t finished_refresh_type) { |
| 333 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 355 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 334 | 356 |
| 335 current_on_bg_done_flags_ |= finished_refresh_type; | 357 current_on_bg_done_flags_ |= finished_refresh_type; |
| 336 if (AreBackgroundCalculationsDone()) | 358 if (AreBackgroundCalculationsDone()) |
| 337 on_background_calculations_done_.Run(); | 359 on_background_calculations_done_.Run(); |
| 338 } | 360 } |
| 339 | 361 |
| 340 } // namespace task_manager | 362 } // namespace task_manager |
| OLD | NEW |