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 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
101 #if !defined(DISABLE_NACL) | 101 #if !defined(DISABLE_NACL) |
102 nacl_debug_stub_port_(nacl::kGdbDebugStubPortUnknown), | 102 nacl_debug_stub_port_(nacl::kGdbDebugStubPortUnknown), |
103 #endif // !defined(DISABLE_NACL) | 103 #endif // !defined(DISABLE_NACL) |
104 idle_wakeups_per_second_(-1), | 104 idle_wakeups_per_second_(-1), |
105 #if defined(OS_LINUX) | 105 #if defined(OS_LINUX) |
106 open_fd_count_(-1), | 106 open_fd_count_(-1), |
107 #endif // defined(OS_LINUX) | 107 #endif // defined(OS_LINUX) |
108 gpu_memory_has_duplicates_(false), | 108 gpu_memory_has_duplicates_(false), |
109 is_backgrounded_(false), | 109 is_backgrounded_(false), |
110 weak_ptr_factory_(this) { | 110 weak_ptr_factory_(this) { |
111 scoped_refptr<TaskGroupSampler> sampler( | 111 if (process_id_ != base::kNullProcessId) { |
112 new TaskGroupSampler(base::Process::Open(proc_id), | 112 worker_thread_sampler_ = base::MakeRefCounted<TaskGroupSampler>( |
113 blocking_pool_runner, | 113 base::Process::Open(process_id_), blocking_pool_runner, |
114 base::Bind(&TaskGroup::OnCpuRefreshDone, | 114 base::Bind(&TaskGroup::OnCpuRefreshDone, |
115 weak_ptr_factory_.GetWeakPtr()), | 115 weak_ptr_factory_.GetWeakPtr()), |
116 base::Bind(&TaskGroup::OnMemoryUsageRefreshDone, | 116 base::Bind(&TaskGroup::OnMemoryUsageRefreshDone, |
117 weak_ptr_factory_.GetWeakPtr()), | 117 weak_ptr_factory_.GetWeakPtr()), |
118 base::Bind(&TaskGroup::OnIdleWakeupsRefreshDone, | 118 base::Bind(&TaskGroup::OnIdleWakeupsRefreshDone, |
119 weak_ptr_factory_.GetWeakPtr()), | 119 weak_ptr_factory_.GetWeakPtr()), |
120 #if defined(OS_LINUX) | 120 #if defined(OS_LINUX) |
121 base::Bind(&TaskGroup::OnOpenFdCountRefreshDone, | 121 base::Bind(&TaskGroup::OnOpenFdCountRefreshDone, |
122 weak_ptr_factory_.GetWeakPtr()), | 122 weak_ptr_factory_.GetWeakPtr()), |
123 #endif // defined(OS_LINUX) | 123 #endif // defined(OS_LINUX) |
124 base::Bind(&TaskGroup::OnProcessPriorityDone, | 124 base::Bind(&TaskGroup::OnProcessPriorityDone, |
125 weak_ptr_factory_.GetWeakPtr()))); | 125 weak_ptr_factory_.GetWeakPtr())); |
126 worker_thread_sampler_.swap(sampler); | 126 } |
127 | |
128 shared_sampler_->RegisterCallbacks( | 127 shared_sampler_->RegisterCallbacks( |
129 process_id_, base::Bind(&TaskGroup::OnIdleWakeupsRefreshDone, | 128 process_id_, |
130 weak_ptr_factory_.GetWeakPtr()), | 129 base::Bind(&TaskGroup::OnIdleWakeupsRefreshDone, |
130 weak_ptr_factory_.GetWeakPtr()), | |
131 base::Bind(&TaskGroup::OnPhysicalMemoryUsageRefreshDone, | 131 base::Bind(&TaskGroup::OnPhysicalMemoryUsageRefreshDone, |
132 weak_ptr_factory_.GetWeakPtr()), | 132 weak_ptr_factory_.GetWeakPtr()), |
133 base::Bind(&TaskGroup::OnStartTimeRefreshDone, | 133 base::Bind(&TaskGroup::OnStartTimeRefreshDone, |
134 weak_ptr_factory_.GetWeakPtr()), | 134 weak_ptr_factory_.GetWeakPtr()), |
135 base::Bind(&TaskGroup::OnCpuTimeRefreshDone, | 135 base::Bind(&TaskGroup::OnCpuTimeRefreshDone, |
136 weak_ptr_factory_.GetWeakPtr())); | 136 weak_ptr_factory_.GetWeakPtr())); |
afakhry
2017/07/10 17:27:54
It seems we can also exclude the shared_sampler_ c
ncarter (slow)
2017/07/31 22:30:29
Done.
| |
137 } | 137 } |
138 | 138 |
139 TaskGroup::~TaskGroup() { | 139 TaskGroup::~TaskGroup() { |
140 shared_sampler_->UnregisterCallbacks(process_id_); | 140 shared_sampler_->UnregisterCallbacks(process_id_); |
141 } | 141 } |
142 | 142 |
143 void TaskGroup::AddTask(Task* task) { | 143 void TaskGroup::AddTask(Task* task) { |
144 DCHECK(task); | 144 DCHECK(task); |
145 tasks_.push_back(task); | 145 tasks_.push_back(task); |
146 } | 146 } |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
216 process_handle_); | 216 process_handle_); |
217 } | 217 } |
218 | 218 |
219 // The remaining resource refreshes are time consuming and cannot be done on | 219 // The remaining resource refreshes are time consuming and cannot be done on |
220 // the UI thread. Do them all on the worker thread using the TaskGroupSampler. | 220 // the UI thread. Do them all on the worker thread using the TaskGroupSampler. |
221 // 7- CPU usage. | 221 // 7- CPU usage. |
222 // 8- Memory usage. | 222 // 8- Memory usage. |
223 // 9- Idle Wakeups per second. | 223 // 9- Idle Wakeups per second. |
224 // 10- (Linux and ChromeOS only) The number of file descriptors current open. | 224 // 10- (Linux and ChromeOS only) The number of file descriptors current open. |
225 // 11- Process priority (foreground vs. background). | 225 // 11- Process priority (foreground vs. background). |
226 worker_thread_sampler_->Refresh(refresh_flags); | 226 if (worker_thread_sampler_) |
227 worker_thread_sampler_->Refresh(refresh_flags); | |
227 } | 228 } |
228 | 229 |
229 Task* TaskGroup::GetTaskById(TaskId task_id) const { | 230 Task* TaskGroup::GetTaskById(TaskId task_id) const { |
230 for (Task* task : tasks_) { | 231 for (Task* task : tasks_) { |
231 if (task->task_id() == task_id) | 232 if (task->task_id() == task_id) |
232 return task; | 233 return task; |
233 } | 234 } |
234 NOTREACHED(); | 235 NOTREACHED(); |
235 return nullptr; | 236 return nullptr; |
236 } | 237 } |
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
351 | 352 |
352 void TaskGroup::OnBackgroundRefreshTypeFinished(int64_t finished_refresh_type) { | 353 void TaskGroup::OnBackgroundRefreshTypeFinished(int64_t finished_refresh_type) { |
353 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 354 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
354 | 355 |
355 current_on_bg_done_flags_ |= finished_refresh_type; | 356 current_on_bg_done_flags_ |= finished_refresh_type; |
356 if (AreBackgroundCalculationsDone()) | 357 if (AreBackgroundCalculationsDone()) |
357 on_background_calculations_done_.Run(); | 358 on_background_calculations_done_.Run(); |
358 } | 359 } |
359 | 360 |
360 } // namespace task_manager | 361 } // namespace task_manager |
OLD | NEW |