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 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
84 : process_handle_(proc_handle), | 84 : process_handle_(proc_handle), |
85 process_id_(proc_id), | 85 process_id_(proc_id), |
86 on_background_calculations_done_(on_background_calculations_done), | 86 on_background_calculations_done_(on_background_calculations_done), |
87 worker_thread_sampler_(nullptr), | 87 worker_thread_sampler_(nullptr), |
88 shared_sampler_(shared_sampler), | 88 shared_sampler_(shared_sampler), |
89 expected_on_bg_done_flags_(kBackgroundRefreshTypesMask), | 89 expected_on_bg_done_flags_(kBackgroundRefreshTypesMask), |
90 current_on_bg_done_flags_(0), | 90 current_on_bg_done_flags_(0), |
91 cpu_usage_(0.0), | 91 cpu_usage_(0.0), |
92 gpu_memory_(-1), | 92 gpu_memory_(-1), |
93 memory_state_(base::MemoryState::UNKNOWN), | 93 memory_state_(base::MemoryState::UNKNOWN), |
94 per_process_network_usage_(-1), | 94 per_process_network_usage_rate_(-1), |
| 95 cumulative_per_process_network_usage_(0), |
95 #if defined(OS_WIN) | 96 #if defined(OS_WIN) |
96 gdi_current_handles_(-1), | 97 gdi_current_handles_(-1), |
97 gdi_peak_handles_(-1), | 98 gdi_peak_handles_(-1), |
98 user_current_handles_(-1), | 99 user_current_handles_(-1), |
99 user_peak_handles_(-1), | 100 user_peak_handles_(-1), |
100 #endif // defined(OS_WIN) | 101 #endif // defined(OS_WIN) |
101 #if !defined(DISABLE_NACL) | 102 #if !defined(DISABLE_NACL) |
102 nacl_debug_stub_port_(nacl::kGdbDebugStubPortUnknown), | 103 nacl_debug_stub_port_(nacl::kGdbDebugStubPortUnknown), |
103 #endif // !defined(DISABLE_NACL) | 104 #endif // !defined(DISABLE_NACL) |
104 idle_wakeups_per_second_(-1), | 105 idle_wakeups_per_second_(-1), |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
148 void TaskGroup::RemoveTask(Task* task) { | 149 void TaskGroup::RemoveTask(Task* task) { |
149 DCHECK(task); | 150 DCHECK(task); |
150 tasks_.erase(std::remove(tasks_.begin(), tasks_.end(), task), tasks_.end()); | 151 tasks_.erase(std::remove(tasks_.begin(), tasks_.end(), task), tasks_.end()); |
151 } | 152 } |
152 | 153 |
153 void TaskGroup::Refresh(const gpu::VideoMemoryUsageStats& gpu_memory_stats, | 154 void TaskGroup::Refresh(const gpu::VideoMemoryUsageStats& gpu_memory_stats, |
154 base::TimeDelta update_interval, | 155 base::TimeDelta update_interval, |
155 int64_t refresh_flags) { | 156 int64_t refresh_flags) { |
156 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 157 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
157 DCHECK(!empty()); | 158 DCHECK(!empty()); |
158 | |
159 expected_on_bg_done_flags_ = refresh_flags & kBackgroundRefreshTypesMask; | 159 expected_on_bg_done_flags_ = refresh_flags & kBackgroundRefreshTypesMask; |
160 // If a refresh type was recently disabled, we need to account for that too. | 160 // If a refresh type was recently disabled, we need to account for that too. |
161 current_on_bg_done_flags_ &= expected_on_bg_done_flags_; | 161 current_on_bg_done_flags_ &= expected_on_bg_done_flags_; |
162 | 162 |
163 // First refresh the enabled non-expensive resources usages on the UI thread. | 163 // First refresh the enabled non-expensive resources usages on the UI thread. |
164 // 1- Refresh all the tasks as well as the total network usage (if enabled). | 164 // 1- Refresh all the tasks as well as the total network usage (if enabled). |
165 const bool network_usage_refresh_enabled = | 165 const bool network_usage_refresh_enabled = |
166 TaskManagerObserver::IsResourceRefreshEnabled(REFRESH_TYPE_NETWORK_USAGE, | 166 TaskManagerObserver::IsResourceRefreshEnabled(REFRESH_TYPE_NETWORK_USAGE, |
167 refresh_flags); | 167 refresh_flags); |
168 per_process_network_usage_ = network_usage_refresh_enabled ? 0 : -1; | 168 |
| 169 per_process_network_usage_rate_ = network_usage_refresh_enabled ? 0 : -1; |
| 170 cumulative_per_process_network_usage_ = 0; |
169 for (Task* task : tasks_) { | 171 for (Task* task : tasks_) { |
170 task->Refresh(update_interval, refresh_flags); | 172 task->Refresh(update_interval, refresh_flags); |
171 | 173 if (network_usage_refresh_enabled) { |
172 if (network_usage_refresh_enabled && task->ReportsNetworkUsage()) | 174 per_process_network_usage_rate_ += task->network_usage_rate(); |
173 per_process_network_usage_ += task->network_usage(); | 175 cumulative_per_process_network_usage_ += task->cumulative_network_usage(); |
| 176 } |
174 } | 177 } |
175 | 178 |
176 // 2- Refresh GPU memory (if enabled). | 179 // 2- Refresh GPU memory (if enabled). |
177 if (TaskManagerObserver::IsResourceRefreshEnabled(REFRESH_TYPE_GPU_MEMORY, | 180 if (TaskManagerObserver::IsResourceRefreshEnabled(REFRESH_TYPE_GPU_MEMORY, |
178 refresh_flags)) { | 181 refresh_flags)) { |
179 RefreshGpuMemory(gpu_memory_stats); | 182 RefreshGpuMemory(gpu_memory_stats); |
180 } | 183 } |
181 | 184 |
182 // 3- Refresh Windows handles (if enabled). | 185 // 3- Refresh Windows handles (if enabled). |
183 #if defined(OS_WIN) | 186 #if defined(OS_WIN) |
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
351 | 354 |
352 void TaskGroup::OnBackgroundRefreshTypeFinished(int64_t finished_refresh_type) { | 355 void TaskGroup::OnBackgroundRefreshTypeFinished(int64_t finished_refresh_type) { |
353 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 356 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
354 | 357 |
355 current_on_bg_done_flags_ |= finished_refresh_type; | 358 current_on_bg_done_flags_ |= finished_refresh_type; |
356 if (AreBackgroundCalculationsDone()) | 359 if (AreBackgroundCalculationsDone()) |
357 on_background_calculations_done_.Run(); | 360 on_background_calculations_done_.Run(); |
358 } | 361 } |
359 | 362 |
360 } // namespace task_manager | 363 } // namespace task_manager |
OLD | NEW |