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" |
| 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 "gpu/ipc/common/memory_stats.h" | 17 #include "gpu/ipc/common/memory_stats.h" |
| 18 | 18 |
| 19 namespace task_manager { | 19 namespace task_manager { |
| 20 | 20 |
| 21 namespace { | 21 namespace { |
| 22 | 22 |
| 23 // A mask for the refresh types that are done in the background thread. | 23 // A mask for the refresh types that are done in the background thread. |
| 24 const int kBackgroundRefreshTypesMask = | 24 const int kBackgroundRefreshTypesMask = |
| 25 REFRESH_TYPE_CPU | | 25 REFRESH_TYPE_CPU | |
| 26 REFRESH_TYPE_MEMORY | | 26 REFRESH_TYPE_MEMORY | |
| 27 REFRESH_TYPE_IDLE_WAKEUPS | | 27 REFRESH_TYPE_IDLE_WAKEUPS | |
| 28 REFRESH_TYPE_START_TIME | | |
| 29 REFRESH_TYPE_CPU_TIME | | |
| 28 #if defined(OS_LINUX) | 30 #if defined(OS_LINUX) |
| 29 REFRESH_TYPE_FD_COUNT | | 31 REFRESH_TYPE_FD_COUNT | |
| 30 #endif // defined(OS_LINUX) | 32 #endif // defined(OS_LINUX) |
| 31 REFRESH_TYPE_PRIORITY; | 33 REFRESH_TYPE_PRIORITY; |
| 32 | 34 |
| 33 #if defined(OS_WIN) | 35 #if defined(OS_WIN) |
| 34 // Gets the GDI and USER Handles on Windows at one shot. | 36 // Gets the GDI and USER Handles on Windows at one shot. |
| 35 void GetWindowsHandles(base::ProcessHandle handle, | 37 void GetWindowsHandles(base::ProcessHandle handle, |
| 36 int64_t* out_gdi_current, | 38 int64_t* out_gdi_current, |
| 37 int64_t* out_gdi_peak, | 39 int64_t* out_gdi_peak, |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 69 const scoped_refptr<SharedSampler>& shared_sampler, | 71 const scoped_refptr<SharedSampler>& shared_sampler, |
| 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), |
| 81 start_time_(0), | |
| 82 cpu_time_(0), | |
| 79 gpu_memory_(-1), | 83 gpu_memory_(-1), |
| 80 per_process_network_usage_(-1), | 84 per_process_network_usage_(-1), |
| 81 #if defined(OS_WIN) | 85 #if defined(OS_WIN) |
| 82 gdi_current_handles_(-1), | 86 gdi_current_handles_(-1), |
| 83 gdi_peak_handles_(-1), | 87 gdi_peak_handles_(-1), |
| 84 user_current_handles_(-1), | 88 user_current_handles_(-1), |
| 85 user_peak_handles_(-1), | 89 user_peak_handles_(-1), |
| 86 #endif // defined(OS_WIN) | 90 #endif // defined(OS_WIN) |
| 87 #if !defined(DISABLE_NACL) | 91 #if !defined(DISABLE_NACL) |
| 88 nacl_debug_stub_port_(-1), | 92 nacl_debug_stub_port_(-1), |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 108 weak_ptr_factory_.GetWeakPtr()), | 112 weak_ptr_factory_.GetWeakPtr()), |
| 109 #endif // defined(OS_LINUX) | 113 #endif // defined(OS_LINUX) |
| 110 base::Bind(&TaskGroup::OnProcessPriorityDone, | 114 base::Bind(&TaskGroup::OnProcessPriorityDone, |
| 111 weak_ptr_factory_.GetWeakPtr()))); | 115 weak_ptr_factory_.GetWeakPtr()))); |
| 112 worker_thread_sampler_.swap(sampler); | 116 worker_thread_sampler_.swap(sampler); |
| 113 | 117 |
| 114 shared_sampler_->RegisterCallbacks( | 118 shared_sampler_->RegisterCallbacks( |
| 115 process_id_, base::Bind(&TaskGroup::OnIdleWakeupsRefreshDone, | 119 process_id_, base::Bind(&TaskGroup::OnIdleWakeupsRefreshDone, |
| 116 weak_ptr_factory_.GetWeakPtr()), | 120 weak_ptr_factory_.GetWeakPtr()), |
| 117 base::Bind(&TaskGroup::OnPhysicalMemoryUsageRefreshDone, | 121 base::Bind(&TaskGroup::OnPhysicalMemoryUsageRefreshDone, |
| 122 weak_ptr_factory_.GetWeakPtr()), | |
| 123 base::Bind(&TaskGroup::OnStartTimeRefreshDone, | |
| 124 weak_ptr_factory_.GetWeakPtr()), | |
| 125 base::Bind(&TaskGroup::OnCpuTimeRefreshDone, | |
| 118 weak_ptr_factory_.GetWeakPtr())); | 126 weak_ptr_factory_.GetWeakPtr())); |
| 119 } | 127 } |
| 120 | 128 |
| 121 TaskGroup::~TaskGroup() { | 129 TaskGroup::~TaskGroup() { |
| 122 shared_sampler_->UnregisterCallbacks(process_id_); | 130 shared_sampler_->UnregisterCallbacks(process_id_); |
| 123 } | 131 } |
| 124 | 132 |
| 125 void TaskGroup::AddTask(Task* task) { | 133 void TaskGroup::AddTask(Task* task) { |
| 126 DCHECK(task); | 134 DCHECK(task); |
| 127 tasks_.push_back(task); | 135 tasks_.push_back(task); |
| 128 } | 136 } |
| 129 | 137 |
| 130 void TaskGroup::RemoveTask(Task* task) { | 138 void TaskGroup::RemoveTask(Task* task) { |
| 131 DCHECK(task); | 139 DCHECK(task); |
| 132 tasks_.erase(std::remove(tasks_.begin(), tasks_.end(), task), tasks_.end()); | 140 tasks_.erase(std::remove(tasks_.begin(), tasks_.end(), task), tasks_.end()); |
| 133 } | 141 } |
| 134 | 142 |
| 135 void TaskGroup::Refresh(const gpu::VideoMemoryUsageStats& gpu_memory_stats, | 143 void TaskGroup::Refresh(const gpu::VideoMemoryUsageStats& gpu_memory_stats, |
| 136 base::TimeDelta update_interval, | 144 base::TimeDelta update_interval, |
| 137 int64_t refresh_flags) { | 145 int64_t refresh_flags) { |
| 138 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 146 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 139 | 147 |
| 140 expected_on_bg_done_flags_ = refresh_flags & kBackgroundRefreshTypesMask; | 148 expected_on_bg_done_flags_ = refresh_flags & kBackgroundRefreshTypesMask; |
|
afakhry
2016/12/21 18:34:34
Now that we have calculations done only by the |sh
chengx
2016/12/21 22:05:54
Thanks for the suggestion. I think adding an '#if
afakhry
2016/12/22 00:28:14
Yes, correct. If you go with my suggestion, we'll
| |
| 141 // If a refresh type was recently disabled, we need to account for that too. | 149 // If a refresh type was recently disabled, we need to account for that too. |
| 142 current_on_bg_done_flags_ &= expected_on_bg_done_flags_; | 150 current_on_bg_done_flags_ &= expected_on_bg_done_flags_; |
| 143 | 151 |
| 144 // First refresh the enabled non-expensive resources usages on the UI thread. | 152 // First refresh the enabled non-expensive resources usages on the UI thread. |
| 145 // 1- Refresh all the tasks as well as the total network usage (if enabled). | 153 // 1- Refresh all the tasks as well as the total network usage (if enabled). |
| 146 const bool network_usage_refresh_enabled = | 154 const bool network_usage_refresh_enabled = |
| 147 TaskManagerObserver::IsResourceRefreshEnabled(REFRESH_TYPE_NETWORK_USAGE, | 155 TaskManagerObserver::IsResourceRefreshEnabled(REFRESH_TYPE_NETWORK_USAGE, |
| 148 refresh_flags); | 156 refresh_flags); |
| 149 per_process_network_usage_ = network_usage_refresh_enabled ? 0 : -1; | 157 per_process_network_usage_ = network_usage_refresh_enabled ? 0 : -1; |
| 150 for (Task* task : tasks_) { | 158 for (Task* task : tasks_) { |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 246 #endif // !defined(DISABLE_NACL) | 254 #endif // !defined(DISABLE_NACL) |
| 247 } | 255 } |
| 248 | 256 |
| 249 void TaskGroup::OnCpuRefreshDone(double cpu_usage) { | 257 void TaskGroup::OnCpuRefreshDone(double cpu_usage) { |
| 250 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 258 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 251 | 259 |
| 252 cpu_usage_ = cpu_usage; | 260 cpu_usage_ = cpu_usage; |
| 253 OnBackgroundRefreshTypeFinished(REFRESH_TYPE_CPU); | 261 OnBackgroundRefreshTypeFinished(REFRESH_TYPE_CPU); |
| 254 } | 262 } |
| 255 | 263 |
| 264 void TaskGroup::OnStartTimeRefreshDone(uint64_t start_time) { | |
| 265 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | |
| 266 | |
| 267 start_time_ = start_time; | |
| 268 OnBackgroundRefreshTypeFinished(REFRESH_TYPE_START_TIME); | |
| 269 } | |
| 270 | |
| 271 void TaskGroup::OnCpuTimeRefreshDone(uint64_t cpu_time) { | |
| 272 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | |
| 273 | |
| 274 cpu_time_ = cpu_time; | |
| 275 OnBackgroundRefreshTypeFinished(REFRESH_TYPE_CPU_TIME); | |
| 276 } | |
| 277 | |
| 256 void TaskGroup::OnPhysicalMemoryUsageRefreshDone(int64_t physical_bytes) { | 278 void TaskGroup::OnPhysicalMemoryUsageRefreshDone(int64_t physical_bytes) { |
| 257 #if defined(OS_WIN) | 279 #if defined(OS_WIN) |
| 258 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 280 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 259 | 281 |
| 260 memory_usage_.physical_bytes = physical_bytes; | 282 memory_usage_.physical_bytes = physical_bytes; |
| 261 OnBackgroundRefreshTypeFinished(REFRESH_TYPE_PHYSICAL_MEMORY); | 283 OnBackgroundRefreshTypeFinished(REFRESH_TYPE_PHYSICAL_MEMORY); |
| 262 #endif // OS_WIN | 284 #endif // OS_WIN |
| 263 } | 285 } |
| 264 | 286 |
| 265 void TaskGroup::OnMemoryUsageRefreshDone(MemoryUsageStats memory_usage) { | 287 void TaskGroup::OnMemoryUsageRefreshDone(MemoryUsageStats memory_usage) { |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 300 | 322 |
| 301 void TaskGroup::OnBackgroundRefreshTypeFinished(int64_t finished_refresh_type) { | 323 void TaskGroup::OnBackgroundRefreshTypeFinished(int64_t finished_refresh_type) { |
| 302 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 324 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 303 | 325 |
| 304 current_on_bg_done_flags_ |= finished_refresh_type; | 326 current_on_bg_done_flags_ |= finished_refresh_type; |
| 305 if (AreBackgroundCalculationsDone()) | 327 if (AreBackgroundCalculationsDone()) |
| 306 on_background_calculations_done_.Run(); | 328 on_background_calculations_done_.Run(); |
| 307 } | 329 } |
| 308 | 330 |
| 309 } // namespace task_manager | 331 } // namespace task_manager |
| OLD | NEW |