Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(941)

Side by Side Diff: chrome/browser/task_manager/sampling/task_group.cc

Issue 2961423002: [TaskManager] Allow a Task to mutate its PID after creation (Closed)
Patch Set: Rework comment. Created 3 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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);
127 126
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,
131 base::Bind(&TaskGroup::OnPhysicalMemoryUsageRefreshDone, 130 weak_ptr_factory_.GetWeakPtr()),
132 weak_ptr_factory_.GetWeakPtr()), 131 base::Bind(&TaskGroup::OnPhysicalMemoryUsageRefreshDone,
133 base::Bind(&TaskGroup::OnStartTimeRefreshDone, 132 weak_ptr_factory_.GetWeakPtr()),
134 weak_ptr_factory_.GetWeakPtr()), 133 base::Bind(&TaskGroup::OnStartTimeRefreshDone,
135 base::Bind(&TaskGroup::OnCpuTimeRefreshDone, 134 weak_ptr_factory_.GetWeakPtr()),
136 weak_ptr_factory_.GetWeakPtr())); 135 base::Bind(&TaskGroup::OnCpuTimeRefreshDone,
136 weak_ptr_factory_.GetWeakPtr()));
137 }
137 } 138 }
138 139
139 TaskGroup::~TaskGroup() { 140 TaskGroup::~TaskGroup() {
140 shared_sampler_->UnregisterCallbacks(process_id_); 141 shared_sampler_->UnregisterCallbacks(process_id_);
141 } 142 }
142 143
143 void TaskGroup::AddTask(Task* task) { 144 void TaskGroup::AddTask(Task* task) {
144 DCHECK(task); 145 DCHECK(task);
145 tasks_.push_back(task); 146 tasks_.push_back(task);
146 } 147 }
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
216 process_handle_); 217 process_handle_);
217 } 218 }
218 219
219 // The remaining resource refreshes are time consuming and cannot be done on 220 // 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. 221 // the UI thread. Do them all on the worker thread using the TaskGroupSampler.
221 // 7- CPU usage. 222 // 7- CPU usage.
222 // 8- Memory usage. 223 // 8- Memory usage.
223 // 9- Idle Wakeups per second. 224 // 9- Idle Wakeups per second.
224 // 10- (Linux and ChromeOS only) The number of file descriptors current open. 225 // 10- (Linux and ChromeOS only) The number of file descriptors current open.
225 // 11- Process priority (foreground vs. background). 226 // 11- Process priority (foreground vs. background).
226 worker_thread_sampler_->Refresh(refresh_flags); 227 if (worker_thread_sampler_)
228 worker_thread_sampler_->Refresh(refresh_flags);
227 } 229 }
228 230
229 Task* TaskGroup::GetTaskById(TaskId task_id) const { 231 Task* TaskGroup::GetTaskById(TaskId task_id) const {
230 for (Task* task : tasks_) { 232 for (Task* task : tasks_) {
231 if (task->task_id() == task_id) 233 if (task->task_id() == task_id)
232 return task; 234 return task;
233 } 235 }
234 NOTREACHED(); 236 NOTREACHED();
235 return nullptr; 237 return nullptr;
236 } 238 }
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
351 353
352 void TaskGroup::OnBackgroundRefreshTypeFinished(int64_t finished_refresh_type) { 354 void TaskGroup::OnBackgroundRefreshTypeFinished(int64_t finished_refresh_type) {
353 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 355 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
354 356
355 current_on_bg_done_flags_ |= finished_refresh_type; 357 current_on_bg_done_flags_ |= finished_refresh_type;
356 if (AreBackgroundCalculationsDone()) 358 if (AreBackgroundCalculationsDone())
357 on_background_calculations_done_.Run(); 359 on_background_calculations_done_.Run();
358 } 360 }
359 361
360 } // namespace task_manager 362 } // namespace task_manager
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698