| 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" |
| 11 #include "base/callback.h" | 11 #include "base/callback.h" |
| 12 #include "build/build_config.h" | 12 #include "build/build_config.h" |
| 13 #include "chrome/browser/task_manager/sampling/shared_sampler.h" | 13 #include "chrome/browser/task_manager/sampling/shared_sampler.h" |
| 14 #include "chrome/browser/task_manager/task_manager_observer.h" | 14 #include "chrome/browser/task_manager/task_manager_observer.h" |
| 15 #include "components/nacl/browser/nacl_browser.h" | 15 #include "components/nacl/browser/nacl_browser.h" |
| 16 #include "content/public/browser/browser_thread.h" | 16 #include "content/public/browser/browser_thread.h" |
| 17 #include "content/public/browser/memory_coordinator.h" |
| 18 #include "content/public/common/content_features.h" |
| 17 #include "gpu/ipc/common/memory_stats.h" | 19 #include "gpu/ipc/common/memory_stats.h" |
| 18 | 20 |
| 19 namespace task_manager { | 21 namespace task_manager { |
| 20 | 22 |
| 21 namespace { | 23 namespace { |
| 22 | 24 |
| 23 // 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. |
| 24 const int kBackgroundRefreshTypesMask = | 26 const int kBackgroundRefreshTypesMask = |
| 25 REFRESH_TYPE_CPU | | 27 REFRESH_TYPE_CPU | |
| 26 REFRESH_TYPE_MEMORY | | 28 REFRESH_TYPE_MEMORY | |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 70 const scoped_refptr<base::SequencedTaskRunner>& blocking_pool_runner) | 72 const scoped_refptr<base::SequencedTaskRunner>& blocking_pool_runner) |
| 71 : process_handle_(proc_handle), | 73 : process_handle_(proc_handle), |
| 72 process_id_(proc_id), | 74 process_id_(proc_id), |
| 73 on_background_calculations_done_(on_background_calculations_done), | 75 on_background_calculations_done_(on_background_calculations_done), |
| 74 worker_thread_sampler_(nullptr), | 76 worker_thread_sampler_(nullptr), |
| 75 shared_sampler_(shared_sampler), | 77 shared_sampler_(shared_sampler), |
| 76 expected_on_bg_done_flags_(kBackgroundRefreshTypesMask), | 78 expected_on_bg_done_flags_(kBackgroundRefreshTypesMask), |
| 77 current_on_bg_done_flags_(0), | 79 current_on_bg_done_flags_(0), |
| 78 cpu_usage_(0.0), | 80 cpu_usage_(0.0), |
| 79 gpu_memory_(-1), | 81 gpu_memory_(-1), |
| 82 memory_state_(base::MemoryState::UNKNOWN), |
| 80 per_process_network_usage_(-1), | 83 per_process_network_usage_(-1), |
| 81 #if defined(OS_WIN) | 84 #if defined(OS_WIN) |
| 82 gdi_current_handles_(-1), | 85 gdi_current_handles_(-1), |
| 83 gdi_peak_handles_(-1), | 86 gdi_peak_handles_(-1), |
| 84 user_current_handles_(-1), | 87 user_current_handles_(-1), |
| 85 user_peak_handles_(-1), | 88 user_peak_handles_(-1), |
| 86 #endif // defined(OS_WIN) | 89 #endif // defined(OS_WIN) |
| 87 #if !defined(DISABLE_NACL) | 90 #if !defined(DISABLE_NACL) |
| 88 nacl_debug_stub_port_(-1), | 91 nacl_debug_stub_port_(-1), |
| 89 #endif // !defined(DISABLE_NACL) | 92 #endif // !defined(DISABLE_NACL) |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 181 refresh_flags & shared_sampler_->GetSupportedFlags(); | 184 refresh_flags & shared_sampler_->GetSupportedFlags(); |
| 182 | 185 |
| 183 // 5- Refresh resources via SharedSampler if the current platform | 186 // 5- Refresh resources via SharedSampler if the current platform |
| 184 // implementation supports that. The actual work is done on the worker thread. | 187 // implementation supports that. The actual work is done on the worker thread. |
| 185 // At the moment this is supported only on OS_WIN. | 188 // At the moment this is supported only on OS_WIN. |
| 186 if (shared_refresh_flags != 0) { | 189 if (shared_refresh_flags != 0) { |
| 187 shared_sampler_->Refresh(process_id_, shared_refresh_flags); | 190 shared_sampler_->Refresh(process_id_, shared_refresh_flags); |
| 188 refresh_flags &= ~shared_refresh_flags; | 191 refresh_flags &= ~shared_refresh_flags; |
| 189 } | 192 } |
| 190 | 193 |
| 194 // 6- Refresh memory state when memory coordinator is enabled. |
| 195 if (TaskManagerObserver::IsResourceRefreshEnabled(REFRESH_TYPE_MEMORY_STATE, |
| 196 refresh_flags) && |
| 197 base::FeatureList::IsEnabled(features::kMemoryCoordinator)) { |
| 198 memory_state_ = |
| 199 content::MemoryCoordinator::GetInstance()->GetStateForProcess( |
| 200 process_handle_); |
| 201 } |
| 202 |
| 191 // The remaining resource refreshes are time consuming and cannot be done on | 203 // The remaining resource refreshes are time consuming and cannot be done on |
| 192 // the UI thread. Do them all on the worker thread using the TaskGroupSampler. | 204 // the UI thread. Do them all on the worker thread using the TaskGroupSampler. |
| 193 // 6- CPU usage. | 205 // 7- CPU usage. |
| 194 // 7- Memory usage. | 206 // 8- Memory usage. |
| 195 // 8- Idle Wakeups per second. | 207 // 9- Idle Wakeups per second. |
| 196 // 9- (Linux and ChromeOS only) The number of file descriptors current open. | 208 // 10- (Linux and ChromeOS only) The number of file descriptors current open. |
| 197 // 10- Process priority (foreground vs. background). | 209 // 11- Process priority (foreground vs. background). |
| 198 worker_thread_sampler_->Refresh(refresh_flags); | 210 worker_thread_sampler_->Refresh(refresh_flags); |
| 199 } | 211 } |
| 200 | 212 |
| 201 Task* TaskGroup::GetTaskById(TaskId task_id) const { | 213 Task* TaskGroup::GetTaskById(TaskId task_id) const { |
| 202 for (Task* task : tasks_) { | 214 for (Task* task : tasks_) { |
| 203 if (task->task_id() == task_id) | 215 if (task->task_id() == task_id) |
| 204 return task; | 216 return task; |
| 205 } | 217 } |
| 206 NOTREACHED(); | 218 NOTREACHED(); |
| 207 return nullptr; | 219 return nullptr; |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 300 | 312 |
| 301 void TaskGroup::OnBackgroundRefreshTypeFinished(int64_t finished_refresh_type) { | 313 void TaskGroup::OnBackgroundRefreshTypeFinished(int64_t finished_refresh_type) { |
| 302 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 314 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 303 | 315 |
| 304 current_on_bg_done_flags_ |= finished_refresh_type; | 316 current_on_bg_done_flags_ |= finished_refresh_type; |
| 305 if (AreBackgroundCalculationsDone()) | 317 if (AreBackgroundCalculationsDone()) |
| 306 on_background_calculations_done_.Run(); | 318 on_background_calculations_done_.Run(); |
| 307 } | 319 } |
| 308 | 320 |
| 309 } // namespace task_manager | 321 } // namespace task_manager |
| OLD | NEW |