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 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
67 gdi_current_handles_(-1), | 67 gdi_current_handles_(-1), |
68 gdi_peak_handles_(-1), | 68 gdi_peak_handles_(-1), |
69 user_current_handles_(-1), | 69 user_current_handles_(-1), |
70 user_peak_handles_(-1), | 70 user_peak_handles_(-1), |
71 #endif // defined(OS_WIN) | 71 #endif // defined(OS_WIN) |
72 #if !defined(DISABLE_NACL) | 72 #if !defined(DISABLE_NACL) |
73 nacl_debug_stub_port_(-1), | 73 nacl_debug_stub_port_(-1), |
74 #endif // !defined(DISABLE_NACL) | 74 #endif // !defined(DISABLE_NACL) |
75 idle_wakeups_per_second_(-1), | 75 idle_wakeups_per_second_(-1), |
76 gpu_memory_has_duplicates_(false), | 76 gpu_memory_has_duplicates_(false), |
| 77 is_backgrounded_(false), |
77 weak_ptr_factory_(this) { | 78 weak_ptr_factory_(this) { |
78 scoped_refptr<TaskGroupSampler> sampler( | 79 scoped_refptr<TaskGroupSampler> sampler( |
79 new TaskGroupSampler(proc_handle, | 80 new TaskGroupSampler(proc_id, |
| 81 proc_handle, |
80 blocking_pool_runner, | 82 blocking_pool_runner, |
81 base::Bind(&TaskGroup::OnCpuRefreshDone, | 83 base::Bind(&TaskGroup::OnCpuRefreshDone, |
82 weak_ptr_factory_.GetWeakPtr()), | 84 weak_ptr_factory_.GetWeakPtr()), |
83 base::Bind(&TaskGroup::OnMemoryUsageRefreshDone, | 85 base::Bind(&TaskGroup::OnMemoryUsageRefreshDone, |
84 weak_ptr_factory_.GetWeakPtr()), | 86 weak_ptr_factory_.GetWeakPtr()), |
85 base::Bind(&TaskGroup::OnIdleWakeupsRefreshDone, | 87 base::Bind(&TaskGroup::OnIdleWakeupsRefreshDone, |
| 88 weak_ptr_factory_.GetWeakPtr()), |
| 89 base::Bind(&TaskGroup::OnProcessPriorityDone, |
86 weak_ptr_factory_.GetWeakPtr()))); | 90 weak_ptr_factory_.GetWeakPtr()))); |
87 worker_thread_sampler_.swap(sampler); | 91 worker_thread_sampler_.swap(sampler); |
88 } | 92 } |
89 | 93 |
90 TaskGroup::~TaskGroup() { | 94 TaskGroup::~TaskGroup() { |
91 } | 95 } |
92 | 96 |
93 void TaskGroup::AddTask(Task* task) { | 97 void TaskGroup::AddTask(Task* task) { |
94 DCHECK(task); | 98 DCHECK(task); |
95 DCHECK(task->process_id() == process_id_); | 99 DCHECK(task->process_id() == process_id_); |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
132 !tasks_.empty()) { | 136 !tasks_.empty()) { |
133 RefreshNaClDebugStubPort(tasks_.begin()->second->GetChildProcessUniqueID()); | 137 RefreshNaClDebugStubPort(tasks_.begin()->second->GetChildProcessUniqueID()); |
134 } | 138 } |
135 #endif // !defined(DISABLE_NACL) | 139 #endif // !defined(DISABLE_NACL) |
136 | 140 |
137 // The remaining resource refreshes are time consuming and cannot be done on | 141 // The remaining resource refreshes are time consuming and cannot be done on |
138 // the UI thread. Do them all on the worker thread using the TaskGroupSampler. | 142 // the UI thread. Do them all on the worker thread using the TaskGroupSampler. |
139 // 5- CPU usage. | 143 // 5- CPU usage. |
140 // 6- Memory usage. | 144 // 6- Memory usage. |
141 // 7- Idle Wakeups per second. | 145 // 7- Idle Wakeups per second. |
| 146 // 8- Process priority (foreground vs. background). |
142 worker_thread_sampler_->Refresh(refresh_flags); | 147 worker_thread_sampler_->Refresh(refresh_flags); |
143 } | 148 } |
144 | 149 |
145 void TaskGroup::AppendSortedTaskIds(TaskIdList* out_list) const { | 150 void TaskGroup::AppendSortedTaskIds(TaskIdList* out_list) const { |
146 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 151 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
147 DCHECK(out_list); | 152 DCHECK(out_list); |
148 | 153 |
149 for (const auto& task_pair : tasks_) | 154 for (const auto& task_pair : tasks_) |
150 out_list->push_back(task_pair.first); | 155 out_list->push_back(task_pair.first); |
151 } | 156 } |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
198 | 203 |
199 memory_usage_ = memory_usage; | 204 memory_usage_ = memory_usage; |
200 } | 205 } |
201 | 206 |
202 void TaskGroup::OnIdleWakeupsRefreshDone(int idle_wakeups_per_second) { | 207 void TaskGroup::OnIdleWakeupsRefreshDone(int idle_wakeups_per_second) { |
203 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 208 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
204 | 209 |
205 idle_wakeups_per_second_ = idle_wakeups_per_second; | 210 idle_wakeups_per_second_ = idle_wakeups_per_second; |
206 } | 211 } |
207 | 212 |
| 213 void TaskGroup::OnProcessPriorityDone(bool is_backgrounded) { |
| 214 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 215 |
| 216 is_backgrounded_ = is_backgrounded; |
| 217 } |
| 218 |
208 } // namespace task_management | 219 } // namespace task_management |
OLD | NEW |