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 "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/callback.h" | 8 #include "base/callback.h" |
9 #include "base/stl_util.h" | 9 #include "base/stl_util.h" |
10 #include "chrome/browser/task_management/task_manager_observer.h" | 10 #include "chrome/browser/task_management/task_manager_observer.h" |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
68 gdi_current_handles_(-1), | 68 gdi_current_handles_(-1), |
69 gdi_peak_handles_(-1), | 69 gdi_peak_handles_(-1), |
70 user_current_handles_(-1), | 70 user_current_handles_(-1), |
71 user_peak_handles_(-1), | 71 user_peak_handles_(-1), |
72 #endif // defined(OS_WIN) | 72 #endif // defined(OS_WIN) |
73 #if !defined(DISABLE_NACL) | 73 #if !defined(DISABLE_NACL) |
74 nacl_debug_stub_port_(-1), | 74 nacl_debug_stub_port_(-1), |
75 #endif // !defined(DISABLE_NACL) | 75 #endif // !defined(DISABLE_NACL) |
76 idle_wakeups_per_second_(-1), | 76 idle_wakeups_per_second_(-1), |
77 gpu_memory_has_duplicates_(false), | 77 gpu_memory_has_duplicates_(false), |
| 78 is_backgrounded_(false), |
78 weak_ptr_factory_(this) { | 79 weak_ptr_factory_(this) { |
79 scoped_refptr<TaskGroupSampler> sampler( | 80 scoped_refptr<TaskGroupSampler> sampler( |
80 new TaskGroupSampler(proc_handle, | 81 new TaskGroupSampler(base::Process::Open(proc_id), |
81 blocking_pool_runner, | 82 blocking_pool_runner, |
82 base::Bind(&TaskGroup::OnCpuRefreshDone, | 83 base::Bind(&TaskGroup::OnCpuRefreshDone, |
83 weak_ptr_factory_.GetWeakPtr()), | 84 weak_ptr_factory_.GetWeakPtr()), |
84 base::Bind(&TaskGroup::OnMemoryUsageRefreshDone, | 85 base::Bind(&TaskGroup::OnMemoryUsageRefreshDone, |
85 weak_ptr_factory_.GetWeakPtr()), | 86 weak_ptr_factory_.GetWeakPtr()), |
86 base::Bind(&TaskGroup::OnIdleWakeupsRefreshDone, | 87 base::Bind(&TaskGroup::OnIdleWakeupsRefreshDone, |
| 88 weak_ptr_factory_.GetWeakPtr()), |
| 89 base::Bind(&TaskGroup::OnProcessPriorityDone, |
87 weak_ptr_factory_.GetWeakPtr()))); | 90 weak_ptr_factory_.GetWeakPtr()))); |
88 worker_thread_sampler_.swap(sampler); | 91 worker_thread_sampler_.swap(sampler); |
89 } | 92 } |
90 | 93 |
91 TaskGroup::~TaskGroup() { | 94 TaskGroup::~TaskGroup() { |
92 } | 95 } |
93 | 96 |
94 void TaskGroup::AddTask(Task* task) { | 97 void TaskGroup::AddTask(Task* task) { |
95 DCHECK(task); | 98 DCHECK(task); |
96 DCHECK(task->process_id() == process_id_); | 99 DCHECK(task->process_id() == process_id_); |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
142 !tasks_.empty()) { | 145 !tasks_.empty()) { |
143 RefreshNaClDebugStubPort(tasks_.begin()->second->GetChildProcessUniqueID()); | 146 RefreshNaClDebugStubPort(tasks_.begin()->second->GetChildProcessUniqueID()); |
144 } | 147 } |
145 #endif // !defined(DISABLE_NACL) | 148 #endif // !defined(DISABLE_NACL) |
146 | 149 |
147 // The remaining resource refreshes are time consuming and cannot be done on | 150 // The remaining resource refreshes are time consuming and cannot be done on |
148 // the UI thread. Do them all on the worker thread using the TaskGroupSampler. | 151 // the UI thread. Do them all on the worker thread using the TaskGroupSampler. |
149 // 5- CPU usage. | 152 // 5- CPU usage. |
150 // 6- Memory usage. | 153 // 6- Memory usage. |
151 // 7- Idle Wakeups per second. | 154 // 7- Idle Wakeups per second. |
| 155 // 8- Process priority (foreground vs. background). |
152 worker_thread_sampler_->Refresh(refresh_flags); | 156 worker_thread_sampler_->Refresh(refresh_flags); |
153 } | 157 } |
154 | 158 |
155 void TaskGroup::AppendSortedTaskIds(TaskIdList* out_list) const { | 159 void TaskGroup::AppendSortedTaskIds(TaskIdList* out_list) const { |
156 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 160 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
157 DCHECK(out_list); | 161 DCHECK(out_list); |
158 | 162 |
159 for (const auto& task_pair : tasks_) | 163 for (const auto& task_pair : tasks_) |
160 out_list->push_back(task_pair.first); | 164 out_list->push_back(task_pair.first); |
161 } | 165 } |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
208 | 212 |
209 memory_usage_ = memory_usage; | 213 memory_usage_ = memory_usage; |
210 } | 214 } |
211 | 215 |
212 void TaskGroup::OnIdleWakeupsRefreshDone(int idle_wakeups_per_second) { | 216 void TaskGroup::OnIdleWakeupsRefreshDone(int idle_wakeups_per_second) { |
213 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 217 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
214 | 218 |
215 idle_wakeups_per_second_ = idle_wakeups_per_second; | 219 idle_wakeups_per_second_ = idle_wakeups_per_second; |
216 } | 220 } |
217 | 221 |
| 222 void TaskGroup::OnProcessPriorityDone(bool is_backgrounded) { |
| 223 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 224 |
| 225 is_backgrounded_ = is_backgrounded; |
| 226 } |
| 227 |
218 } // namespace task_management | 228 } // namespace task_management |
OLD | NEW |