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

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

Issue 2028753002: Make Task Manager sort more meaningful (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix unittest Created 4 years, 6 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_management/sampling/task_group.h" 5 #include "chrome/browser/task_management/sampling/task_group.h"
6 6
7 #include <algorithm>
8 #include <limits>
9
7 #include "base/bind.h" 10 #include "base/bind.h"
8 #include "base/callback.h" 11 #include "base/callback.h"
9 #include "base/stl_util.h" 12 #include "base/stl_util.h"
10 #include "build/build_config.h" 13 #include "build/build_config.h"
11 #include "chrome/browser/task_management/task_manager_observer.h" 14 #include "chrome/browser/task_management/task_manager_observer.h"
12 #include "components/nacl/browser/nacl_browser.h" 15 #include "components/nacl/browser/nacl_browser.h"
13 #include "content/public/browser/browser_thread.h" 16 #include "content/public/browser/browser_thread.h"
14 #include "gpu/ipc/common/memory_stats.h" 17 #include "gpu/ipc/common/memory_stats.h"
15 18
16 namespace task_management { 19 namespace task_management {
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
105 base::Bind(&TaskGroup::OnProcessPriorityDone, 108 base::Bind(&TaskGroup::OnProcessPriorityDone,
106 weak_ptr_factory_.GetWeakPtr()))); 109 weak_ptr_factory_.GetWeakPtr())));
107 worker_thread_sampler_.swap(sampler); 110 worker_thread_sampler_.swap(sampler);
108 } 111 }
109 112
110 TaskGroup::~TaskGroup() { 113 TaskGroup::~TaskGroup() {
111 } 114 }
112 115
113 void TaskGroup::AddTask(Task* task) { 116 void TaskGroup::AddTask(Task* task) {
114 DCHECK(task); 117 DCHECK(task);
115 DCHECK(task->process_id() == process_id_); 118 tasks_.push_back(task);
116 DCHECK(!ContainsKey(tasks_, task->task_id()));
117
118 tasks_[task->task_id()] = task;
119 } 119 }
120 120
121 void TaskGroup::RemoveTask(Task* task) { 121 void TaskGroup::RemoveTask(Task* task) {
122 DCHECK(task); 122 DCHECK(task);
123 DCHECK(ContainsKey(tasks_, task->task_id())); 123 tasks_.erase(std::remove(tasks_.begin(), tasks_.end(), task), tasks_.end());
124
125 tasks_.erase(task->task_id());
126 } 124 }
127 125
128 void TaskGroup::Refresh(const gpu::VideoMemoryUsageStats& gpu_memory_stats, 126 void TaskGroup::Refresh(const gpu::VideoMemoryUsageStats& gpu_memory_stats,
129 base::TimeDelta update_interval, 127 base::TimeDelta update_interval,
130 int64_t refresh_flags) { 128 int64_t refresh_flags) {
131 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 129 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
132 130
133 expected_on_bg_done_flags_ = refresh_flags & kBackgroundRefreshTypesMask; 131 expected_on_bg_done_flags_ = refresh_flags & kBackgroundRefreshTypesMask;
134 // If a refresh type was recently disabled, we need to account for that too. 132 // If a refresh type was recently disabled, we need to account for that too.
135 current_on_bg_done_flags_ &= expected_on_bg_done_flags_; 133 current_on_bg_done_flags_ &= expected_on_bg_done_flags_;
136 134
137 // First refresh the enabled non-expensive resources usages on the UI thread. 135 // First refresh the enabled non-expensive resources usages on the UI thread.
138 // 1- Refresh all the tasks as well as the total network usage (if enabled). 136 // 1- Refresh all the tasks as well as the total network usage (if enabled).
139 const bool network_usage_refresh_enabled = 137 const bool network_usage_refresh_enabled =
140 TaskManagerObserver::IsResourceRefreshEnabled(REFRESH_TYPE_NETWORK_USAGE, 138 TaskManagerObserver::IsResourceRefreshEnabled(REFRESH_TYPE_NETWORK_USAGE,
141 refresh_flags); 139 refresh_flags);
142 per_process_network_usage_ = network_usage_refresh_enabled ? 0 : -1; 140 per_process_network_usage_ = network_usage_refresh_enabled ? 0 : -1;
143 for (auto& task_pair : tasks_) { 141 for (Task* task : tasks_) {
144 Task* task = task_pair.second;
145 task->Refresh(update_interval, refresh_flags); 142 task->Refresh(update_interval, refresh_flags);
146 143
147 if (network_usage_refresh_enabled && task->ReportsNetworkUsage()) 144 if (network_usage_refresh_enabled && task->ReportsNetworkUsage())
148 per_process_network_usage_ += task->network_usage(); 145 per_process_network_usage_ += task->network_usage();
149 } 146 }
150 147
151 // 2- Refresh GPU memory (if enabled). 148 // 2- Refresh GPU memory (if enabled).
152 if (TaskManagerObserver::IsResourceRefreshEnabled(REFRESH_TYPE_GPU_MEMORY, 149 if (TaskManagerObserver::IsResourceRefreshEnabled(REFRESH_TYPE_GPU_MEMORY,
153 refresh_flags)) { 150 refresh_flags)) {
154 RefreshGpuMemory(gpu_memory_stats); 151 RefreshGpuMemory(gpu_memory_stats);
155 } 152 }
156 153
157 // 3- Refresh Windows handles (if enabled). 154 // 3- Refresh Windows handles (if enabled).
158 #if defined(OS_WIN) 155 #if defined(OS_WIN)
159 if (TaskManagerObserver::IsResourceRefreshEnabled(REFRESH_TYPE_HANDLES, 156 if (TaskManagerObserver::IsResourceRefreshEnabled(REFRESH_TYPE_HANDLES,
160 refresh_flags)) { 157 refresh_flags)) {
161 RefreshWindowsHandles(); 158 RefreshWindowsHandles();
162 } 159 }
163 #endif // defined(OS_WIN) 160 #endif // defined(OS_WIN)
164 161
165 // 4- Refresh the NACL debug stub port (if enabled). 162 // 4- Refresh the NACL debug stub port (if enabled).
166 #if !defined(DISABLE_NACL) 163 #if !defined(DISABLE_NACL)
167 if (TaskManagerObserver::IsResourceRefreshEnabled(REFRESH_TYPE_NACL, 164 if (TaskManagerObserver::IsResourceRefreshEnabled(REFRESH_TYPE_NACL,
168 refresh_flags) && 165 refresh_flags) &&
169 !tasks_.empty()) { 166 !tasks_.empty()) {
170 RefreshNaClDebugStubPort(tasks_.begin()->second->GetChildProcessUniqueID()); 167 RefreshNaClDebugStubPort(tasks_[0]->GetChildProcessUniqueID());
171 } 168 }
172 #endif // !defined(DISABLE_NACL) 169 #endif // !defined(DISABLE_NACL)
173 170
174 // The remaining resource refreshes are time consuming and cannot be done on 171 // The remaining resource refreshes are time consuming and cannot be done on
175 // the UI thread. Do them all on the worker thread using the TaskGroupSampler. 172 // the UI thread. Do them all on the worker thread using the TaskGroupSampler.
176 // 5- CPU usage. 173 // 5- CPU usage.
177 // 6- Memory usage. 174 // 6- Memory usage.
178 // 7- Idle Wakeups per second. 175 // 7- Idle Wakeups per second.
179 // 8- (Linux and ChromeOS only) The number of file descriptors current open. 176 // 8- (Linux and ChromeOS only) The number of file descriptors current open.
180 // 9- Process priority (foreground vs. background). 177 // 9- Process priority (foreground vs. background).
181 worker_thread_sampler_->Refresh(refresh_flags); 178 worker_thread_sampler_->Refresh(refresh_flags);
182 } 179 }
183 180
184 void TaskGroup::AppendSortedTaskIds(TaskIdList* out_list) const {
185 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
186 DCHECK(out_list);
187
188 for (const auto& task_pair : tasks_)
189 out_list->push_back(task_pair.first);
190 }
191
192 Task* TaskGroup::GetTaskById(TaskId task_id) const { 181 Task* TaskGroup::GetTaskById(TaskId task_id) const {
193 auto it = tasks_.find(task_id); 182 for (Task* task : tasks_) {
194 DCHECK(it != tasks_.end()); 183 if (task->task_id() == task_id)
195 return it->second; 184 return task;
185 }
186 NOTREACHED();
187 return nullptr;
196 } 188 }
197 189
198 void TaskGroup::ClearCurrentBackgroundCalculationsFlags() { 190 void TaskGroup::ClearCurrentBackgroundCalculationsFlags() {
199 current_on_bg_done_flags_ = 0; 191 current_on_bg_done_flags_ = 0;
200 } 192 }
201 193
202 bool TaskGroup::AreBackgroundCalculationsDone() const { 194 bool TaskGroup::AreBackgroundCalculationsDone() const {
203 return expected_on_bg_done_flags_ == current_on_bg_done_flags_; 195 return expected_on_bg_done_flags_ == current_on_bg_done_flags_;
204 } 196 }
205 197
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
273 265
274 void TaskGroup::OnBackgroundRefreshTypeFinished(int64_t finished_refresh_type) { 266 void TaskGroup::OnBackgroundRefreshTypeFinished(int64_t finished_refresh_type) {
275 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 267 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
276 268
277 current_on_bg_done_flags_ |= finished_refresh_type; 269 current_on_bg_done_flags_ |= finished_refresh_type;
278 if (AreBackgroundCalculationsDone()) 270 if (AreBackgroundCalculationsDone())
279 on_background_calculations_done_.Run(); 271 on_background_calculations_done_.Run();
280 } 272 }
281 273
282 } // namespace task_management 274 } // namespace task_management
OLDNEW
« no previous file with comments | « chrome/browser/task_management/sampling/task_group.h ('k') | chrome/browser/task_management/sampling/task_manager_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698