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_management/sampling/task_group.h" | 5 #include "chrome/browser/task_management/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 "base/stl_util.h" | 12 #include "base/stl_util.h" |
| 13 #include "build/build_config.h" | 13 #include "build/build_config.h" |
| 14 #include "chrome/browser/task_management/sampling/shared_sampler.h" | |
| 14 #include "chrome/browser/task_management/task_manager_observer.h" | 15 #include "chrome/browser/task_management/task_manager_observer.h" |
| 15 #include "components/nacl/browser/nacl_browser.h" | 16 #include "components/nacl/browser/nacl_browser.h" |
| 16 #include "content/public/browser/browser_thread.h" | 17 #include "content/public/browser/browser_thread.h" |
| 17 #include "gpu/ipc/common/memory_stats.h" | 18 #include "gpu/ipc/common/memory_stats.h" |
| 18 | 19 |
| 19 namespace task_management { | 20 namespace task_management { |
| 20 | 21 |
| 21 namespace { | 22 namespace { |
| 22 | 23 |
| 23 // A mask for the refresh types that are done in the background thread. | 24 // A mask for the refresh types that are done in the background thread. |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 59 } | 60 } |
| 60 } | 61 } |
| 61 #endif // defined(OS_WIN) | 62 #endif // defined(OS_WIN) |
| 62 | 63 |
| 63 } // namespace | 64 } // namespace |
| 64 | 65 |
| 65 TaskGroup::TaskGroup( | 66 TaskGroup::TaskGroup( |
| 66 base::ProcessHandle proc_handle, | 67 base::ProcessHandle proc_handle, |
| 67 base::ProcessId proc_id, | 68 base::ProcessId proc_id, |
| 68 const base::Closure& on_background_calculations_done, | 69 const base::Closure& on_background_calculations_done, |
| 70 const scoped_refptr<SharedSampler> shared_sampler, | |
|
ncarter (slow)
2016/07/28 21:37:27
Passing like this will cause an extra increment/de
stanisc
2016/07/28 22:38:44
Yeah, I meant a const ref here, but omitted '&' by
stanisc
2016/08/01 22:34:27
Done.
| |
| 69 const scoped_refptr<base::SequencedTaskRunner>& blocking_pool_runner) | 71 const scoped_refptr<base::SequencedTaskRunner>& blocking_pool_runner) |
| 70 : process_handle_(proc_handle), | 72 : process_handle_(proc_handle), |
| 71 process_id_(proc_id), | 73 process_id_(proc_id), |
| 72 on_background_calculations_done_(on_background_calculations_done), | 74 on_background_calculations_done_(on_background_calculations_done), |
| 73 worker_thread_sampler_(nullptr), | 75 worker_thread_sampler_(nullptr), |
| 76 shared_sampler_(shared_sampler), | |
| 74 expected_on_bg_done_flags_(kBackgroundRefreshTypesMask), | 77 expected_on_bg_done_flags_(kBackgroundRefreshTypesMask), |
| 75 current_on_bg_done_flags_(0), | 78 current_on_bg_done_flags_(0), |
| 76 cpu_usage_(0.0), | 79 cpu_usage_(0.0), |
| 77 gpu_memory_(-1), | 80 gpu_memory_(-1), |
| 78 per_process_network_usage_(-1), | 81 per_process_network_usage_(-1), |
| 79 #if defined(OS_WIN) | 82 #if defined(OS_WIN) |
| 80 gdi_current_handles_(-1), | 83 gdi_current_handles_(-1), |
| 81 gdi_peak_handles_(-1), | 84 gdi_peak_handles_(-1), |
| 82 user_current_handles_(-1), | 85 user_current_handles_(-1), |
| 83 user_peak_handles_(-1), | 86 user_peak_handles_(-1), |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 101 weak_ptr_factory_.GetWeakPtr()), | 104 weak_ptr_factory_.GetWeakPtr()), |
| 102 base::Bind(&TaskGroup::OnIdleWakeupsRefreshDone, | 105 base::Bind(&TaskGroup::OnIdleWakeupsRefreshDone, |
| 103 weak_ptr_factory_.GetWeakPtr()), | 106 weak_ptr_factory_.GetWeakPtr()), |
| 104 #if defined(OS_LINUX) | 107 #if defined(OS_LINUX) |
| 105 base::Bind(&TaskGroup::OnOpenFdCountRefreshDone, | 108 base::Bind(&TaskGroup::OnOpenFdCountRefreshDone, |
| 106 weak_ptr_factory_.GetWeakPtr()), | 109 weak_ptr_factory_.GetWeakPtr()), |
| 107 #endif // defined(OS_LINUX) | 110 #endif // defined(OS_LINUX) |
| 108 base::Bind(&TaskGroup::OnProcessPriorityDone, | 111 base::Bind(&TaskGroup::OnProcessPriorityDone, |
| 109 weak_ptr_factory_.GetWeakPtr()))); | 112 weak_ptr_factory_.GetWeakPtr()))); |
| 110 worker_thread_sampler_.swap(sampler); | 113 worker_thread_sampler_.swap(sampler); |
| 114 | |
| 115 shared_sampler_->RegisterCallbacks( | |
| 116 process_id_, base::Bind(&TaskGroup::OnIdleWakeupsRefreshDone, | |
| 117 weak_ptr_factory_.GetWeakPtr())); | |
| 111 } | 118 } |
| 112 | 119 |
| 113 TaskGroup::~TaskGroup() { | 120 TaskGroup::~TaskGroup() { |
| 121 shared_sampler_->UnregisterCallbacks(process_id_); | |
| 114 } | 122 } |
| 115 | 123 |
| 116 void TaskGroup::AddTask(Task* task) { | 124 void TaskGroup::AddTask(Task* task) { |
| 117 DCHECK(task); | 125 DCHECK(task); |
| 118 tasks_.push_back(task); | 126 tasks_.push_back(task); |
| 119 } | 127 } |
| 120 | 128 |
| 121 void TaskGroup::RemoveTask(Task* task) { | 129 void TaskGroup::RemoveTask(Task* task) { |
| 122 DCHECK(task); | 130 DCHECK(task); |
| 123 tasks_.erase(std::remove(tasks_.begin(), tasks_.end(), task), tasks_.end()); | 131 tasks_.erase(std::remove(tasks_.begin(), tasks_.end(), task), tasks_.end()); |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 161 | 169 |
| 162 // 4- Refresh the NACL debug stub port (if enabled). | 170 // 4- Refresh the NACL debug stub port (if enabled). |
| 163 #if !defined(DISABLE_NACL) | 171 #if !defined(DISABLE_NACL) |
| 164 if (TaskManagerObserver::IsResourceRefreshEnabled(REFRESH_TYPE_NACL, | 172 if (TaskManagerObserver::IsResourceRefreshEnabled(REFRESH_TYPE_NACL, |
| 165 refresh_flags) && | 173 refresh_flags) && |
| 166 !tasks_.empty()) { | 174 !tasks_.empty()) { |
| 167 RefreshNaClDebugStubPort(tasks_[0]->GetChildProcessUniqueID()); | 175 RefreshNaClDebugStubPort(tasks_[0]->GetChildProcessUniqueID()); |
| 168 } | 176 } |
| 169 #endif // !defined(DISABLE_NACL) | 177 #endif // !defined(DISABLE_NACL) |
| 170 | 178 |
| 179 int64_t shared_refresh_flags = | |
| 180 refresh_flags & shared_sampler_->SupportsFlags(); | |
| 181 | |
| 182 // 5- Refresh resources via SharedSampler if the current platform | |
| 183 // implementation supports that. The actual work is done on the worker thread. | |
| 184 // At the moment this is supported only on OS_WIN. | |
| 185 if (shared_refresh_flags != 0) { | |
| 186 shared_sampler_->Refresh(process_id_, shared_refresh_flags); | |
| 187 refresh_flags &= ~shared_refresh_flags; | |
| 188 } | |
| 189 | |
| 171 // The remaining resource refreshes are time consuming and cannot be done on | 190 // The remaining resource refreshes are time consuming and cannot be done on |
| 172 // the UI thread. Do them all on the worker thread using the TaskGroupSampler. | 191 // the UI thread. Do them all on the worker thread using the TaskGroupSampler. |
| 173 // 5- CPU usage. | 192 // 6- CPU usage. |
| 174 // 6- Memory usage. | 193 // 7- Memory usage. |
| 175 // 7- Idle Wakeups per second. | 194 // 8- Idle Wakeups per second. |
| 176 // 8- (Linux and ChromeOS only) The number of file descriptors current open. | 195 // 9- (Linux and ChromeOS only) The number of file descriptors current open. |
| 177 // 9- Process priority (foreground vs. background). | 196 // 10- Process priority (foreground vs. background). |
| 178 worker_thread_sampler_->Refresh(refresh_flags); | 197 worker_thread_sampler_->Refresh(refresh_flags); |
| 179 } | 198 } |
| 180 | 199 |
| 181 Task* TaskGroup::GetTaskById(TaskId task_id) const { | 200 Task* TaskGroup::GetTaskById(TaskId task_id) const { |
| 182 for (Task* task : tasks_) { | 201 for (Task* task : tasks_) { |
| 183 if (task->task_id() == task_id) | 202 if (task->task_id() == task_id) |
| 184 return task; | 203 return task; |
| 185 } | 204 } |
| 186 NOTREACHED(); | 205 NOTREACHED(); |
| 187 return nullptr; | 206 return nullptr; |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 265 | 284 |
| 266 void TaskGroup::OnBackgroundRefreshTypeFinished(int64_t finished_refresh_type) { | 285 void TaskGroup::OnBackgroundRefreshTypeFinished(int64_t finished_refresh_type) { |
| 267 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 286 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 268 | 287 |
| 269 current_on_bg_done_flags_ |= finished_refresh_type; | 288 current_on_bg_done_flags_ |= finished_refresh_type; |
| 270 if (AreBackgroundCalculationsDone()) | 289 if (AreBackgroundCalculationsDone()) |
| 271 on_background_calculations_done_.Run(); | 290 on_background_calculations_done_.Run(); |
| 272 } | 291 } |
| 273 | 292 |
| 274 } // namespace task_management | 293 } // namespace task_management |
| OLD | NEW |