Chromium Code Reviews| 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_manager_impl.h" | 5 #include "chrome/browser/task_management/sampling/task_manager_impl.h" |
| 6 | 6 |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/stl_util.h" | 8 #include "base/stl_util.h" |
| 9 #include "build/build_config.h" | 9 #include "build/build_config.h" |
| 10 #include "chrome/browser/task_management/providers/browser_process_task_provider .h" | 10 #include "chrome/browser/task_management/providers/browser_process_task_provider .h" |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 31 | 31 |
| 32 return blocking_pool->GetSequencedTaskRunner(token); | 32 return blocking_pool->GetSequencedTaskRunner(token); |
| 33 } | 33 } |
| 34 | 34 |
| 35 base::LazyInstance<TaskManagerImpl> lazy_task_manager_instance = | 35 base::LazyInstance<TaskManagerImpl> lazy_task_manager_instance = |
| 36 LAZY_INSTANCE_INITIALIZER; | 36 LAZY_INSTANCE_INITIALIZER; |
| 37 | 37 |
| 38 } // namespace | 38 } // namespace |
| 39 | 39 |
| 40 TaskManagerImpl::TaskManagerImpl() | 40 TaskManagerImpl::TaskManagerImpl() |
| 41 : blocking_pool_runner_(GetBlockingPoolRunner()), | 41 : on_background_data_ready_callback_(base::Bind( |
| 42 &TaskManagerImpl::OnTaskGroupBackgroundCalculationsDone, | |
| 43 base::Unretained(this))), | |
| 44 blocking_pool_runner_(GetBlockingPoolRunner()), | |
| 42 is_running_(false) { | 45 is_running_(false) { |
| 43 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 46 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 44 | 47 |
| 45 task_providers_.push_back(new BrowserProcessTaskProvider()); | 48 task_providers_.push_back(new BrowserProcessTaskProvider()); |
| 46 task_providers_.push_back(new ChildProcessTaskProvider()); | 49 task_providers_.push_back(new ChildProcessTaskProvider()); |
| 47 task_providers_.push_back(new WebContentsTaskProvider()); | 50 task_providers_.push_back(new WebContentsTaskProvider()); |
| 48 #if defined(OS_CHROMEOS) | 51 #if defined(OS_CHROMEOS) |
| 49 if (arc::ArcBridgeService::GetEnabled( | 52 if (arc::ArcBridgeService::GetEnabled( |
| 50 base::CommandLine::ForCurrentProcess())) { | 53 base::CommandLine::ForCurrentProcess())) { |
| 51 task_providers_.push_back(new ArcProcessTaskProvider()); | 54 task_providers_.push_back(new ArcProcessTaskProvider()); |
| (...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 172 } | 175 } |
| 173 | 176 |
| 174 const base::ProcessId& TaskManagerImpl::GetProcessId(TaskId task_id) const { | 177 const base::ProcessId& TaskManagerImpl::GetProcessId(TaskId task_id) const { |
| 175 return GetTaskGroupByTaskId(task_id)->process_id(); | 178 return GetTaskGroupByTaskId(task_id)->process_id(); |
| 176 } | 179 } |
| 177 | 180 |
| 178 Task::Type TaskManagerImpl::GetType(TaskId task_id) const { | 181 Task::Type TaskManagerImpl::GetType(TaskId task_id) const { |
| 179 return GetTaskByTaskId(task_id)->GetType(); | 182 return GetTaskByTaskId(task_id)->GetType(); |
| 180 } | 183 } |
| 181 | 184 |
| 185 int TaskManagerImpl::GetTabId(TaskId task_id) const { | |
| 186 return GetTaskByTaskId(task_id)->GetTabId(); | |
| 187 } | |
| 188 | |
| 189 int TaskManagerImpl::GetChildProcessUniqueId(TaskId task_id) const { | |
| 190 return GetTaskByTaskId(task_id)->GetChildProcessUniqueID(); | |
| 191 } | |
| 192 | |
| 193 void TaskManagerImpl::GetTerminationStatus(TaskId task_id, | |
| 194 base::TerminationStatus* out_status, | |
| 195 int* out_error_code) const { | |
| 196 GetTaskByTaskId(task_id)->GetTerminationStatus(out_status, out_error_code); | |
| 197 } | |
| 198 | |
| 182 int64_t TaskManagerImpl::GetNetworkUsage(TaskId task_id) const { | 199 int64_t TaskManagerImpl::GetNetworkUsage(TaskId task_id) const { |
| 183 return GetTaskByTaskId(task_id)->network_usage(); | 200 return GetTaskByTaskId(task_id)->network_usage(); |
| 184 } | 201 } |
| 185 | 202 |
| 186 int64_t TaskManagerImpl::GetProcessTotalNetworkUsage(TaskId task_id) const { | 203 int64_t TaskManagerImpl::GetProcessTotalNetworkUsage(TaskId task_id) const { |
| 187 return GetTaskGroupByTaskId(task_id)->per_process_network_usage(); | 204 return GetTaskGroupByTaskId(task_id)->per_process_network_usage(); |
| 188 } | 205 } |
| 189 | 206 |
| 190 int64_t TaskManagerImpl::GetSqliteMemoryUsed(TaskId task_id) const { | 207 int64_t TaskManagerImpl::GetSqliteMemoryUsed(TaskId task_id) const { |
| 191 return GetTaskByTaskId(task_id)->GetSqliteMemoryUsed(); | 208 return GetTaskByTaskId(task_id)->GetSqliteMemoryUsed(); |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 233 if (groups_pair.second == browser_group) | 250 if (groups_pair.second == browser_group) |
| 234 continue; | 251 continue; |
| 235 | 252 |
| 236 groups_pair.second->AppendSortedTaskIds(&sorted_task_ids_); | 253 groups_pair.second->AppendSortedTaskIds(&sorted_task_ids_); |
| 237 } | 254 } |
| 238 } | 255 } |
| 239 | 256 |
| 240 return sorted_task_ids_; | 257 return sorted_task_ids_; |
| 241 } | 258 } |
| 242 | 259 |
| 260 TaskIdList TaskManagerImpl::GetIdsOfTasksSharingSameProcess( | |
| 261 TaskId task_id) const { | |
| 262 DCHECK(is_running_) << "Task manager is not running. You must observe the " | |
| 263 "task manager for it to start running"; | |
| 264 | |
| 265 TaskIdList result; | |
| 266 GetTaskGroupByTaskId(task_id)->AppendSortedTaskIds(&result); | |
| 267 return result; | |
| 268 } | |
| 269 | |
| 243 size_t TaskManagerImpl::GetNumberOfTasksOnSameProcess(TaskId task_id) const { | 270 size_t TaskManagerImpl::GetNumberOfTasksOnSameProcess(TaskId task_id) const { |
| 244 return GetTaskGroupByTaskId(task_id)->num_tasks(); | 271 return GetTaskGroupByTaskId(task_id)->num_tasks(); |
| 245 } | 272 } |
| 246 | 273 |
| 247 void TaskManagerImpl::TaskAdded(Task* task) { | 274 void TaskManagerImpl::TaskAdded(Task* task) { |
| 248 DCHECK(task); | 275 DCHECK(task); |
| 249 | 276 |
| 250 TaskGroup* task_group = nullptr; | 277 TaskGroup* task_group = nullptr; |
| 251 const base::ProcessId proc_id = task->process_id(); | 278 const base::ProcessId proc_id = task->process_id(); |
| 252 const TaskId task_id = task->task_id(); | 279 const TaskId task_id = task->task_id(); |
| 253 | 280 |
| 254 auto itr = task_groups_by_proc_id_.find(proc_id); | 281 auto itr = task_groups_by_proc_id_.find(proc_id); |
| 255 if (itr == task_groups_by_proc_id_.end()) { | 282 if (itr == task_groups_by_proc_id_.end()) { |
| 256 task_group = new TaskGroup(task->process_handle(), | 283 task_group = new TaskGroup(task->process_handle(), |
| 257 proc_id, | 284 proc_id, |
| 285 on_background_data_ready_callback_, | |
| 258 blocking_pool_runner_); | 286 blocking_pool_runner_); |
| 259 task_groups_by_proc_id_[proc_id] = task_group; | 287 task_groups_by_proc_id_[proc_id] = task_group; |
| 260 } else { | 288 } else { |
| 261 task_group = itr->second; | 289 task_group = itr->second; |
| 262 } | 290 } |
| 263 | 291 |
| 264 task_group->AddTask(task); | 292 task_group->AddTask(task); |
| 265 | 293 |
| 266 task_groups_by_task_id_[task_id] = task_group; | 294 task_groups_by_task_id_[task_id] = task_group; |
| 267 | 295 |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 289 | 317 |
| 290 // Invalidate the cached sorted IDs by clearing the list. | 318 // Invalidate the cached sorted IDs by clearing the list. |
| 291 sorted_task_ids_.clear(); | 319 sorted_task_ids_.clear(); |
| 292 | 320 |
| 293 if (task_group->empty()) { | 321 if (task_group->empty()) { |
| 294 task_groups_by_proc_id_.erase(proc_id); | 322 task_groups_by_proc_id_.erase(proc_id); |
| 295 delete task_group; | 323 delete task_group; |
| 296 } | 324 } |
| 297 } | 325 } |
| 298 | 326 |
| 327 void TaskManagerImpl::TaskUnresponsive(Task* task) { | |
| 328 DCHECK(task); | |
| 329 NotifyObserversOnTaskUnresponsive(task->task_id()); | |
| 330 } | |
| 331 | |
| 299 void TaskManagerImpl::OnVideoMemoryUsageStatsUpdate( | 332 void TaskManagerImpl::OnVideoMemoryUsageStatsUpdate( |
| 300 const content::GPUVideoMemoryUsageStats& gpu_memory_stats) { | 333 const content::GPUVideoMemoryUsageStats& gpu_memory_stats) { |
| 301 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 334 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 302 | 335 |
| 303 gpu_memory_stats_ = gpu_memory_stats; | 336 gpu_memory_stats_ = gpu_memory_stats; |
| 304 } | 337 } |
| 305 | 338 |
| 306 // static | 339 // static |
| 307 void TaskManagerImpl::OnMultipleBytesReadUI( | 340 void TaskManagerImpl::OnMultipleBytesReadUI( |
| 308 std::vector<BytesReadParam>* params) { | 341 std::vector<BytesReadParam>* params) { |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 388 TaskGroup* TaskManagerImpl::GetTaskGroupByTaskId(TaskId task_id) const { | 421 TaskGroup* TaskManagerImpl::GetTaskGroupByTaskId(TaskId task_id) const { |
| 389 DCHECK(ContainsKey(task_groups_by_task_id_, task_id)); | 422 DCHECK(ContainsKey(task_groups_by_task_id_, task_id)); |
| 390 | 423 |
| 391 return task_groups_by_task_id_.at(task_id); | 424 return task_groups_by_task_id_.at(task_id); |
| 392 } | 425 } |
| 393 | 426 |
| 394 Task* TaskManagerImpl::GetTaskByTaskId(TaskId task_id) const { | 427 Task* TaskManagerImpl::GetTaskByTaskId(TaskId task_id) const { |
| 395 return GetTaskGroupByTaskId(task_id)->GetTaskById(task_id); | 428 return GetTaskGroupByTaskId(task_id)->GetTaskById(task_id); |
| 396 } | 429 } |
| 397 | 430 |
| 431 void TaskManagerImpl::OnTaskGroupBackgroundCalculationsDone() { | |
| 432 // TODO(afakhry): There should be a better way for doing this! | |
| 433 bool are_all_processes_data_ready = true; | |
| 434 for (auto& groups_itr : task_groups_by_proc_id_) { | |
| 435 are_all_processes_data_ready &= | |
| 436 groups_itr.second->AreBackgroundCalculationsDone(); | |
| 437 } | |
| 438 if (are_all_processes_data_ready) { | |
| 439 NotifyObserversOnRefreshWithBackgroundCalculations(GetTaskIdsList()); | |
| 440 for (auto& groups_itr : task_groups_by_proc_id_) | |
| 441 groups_itr.second->ClearCurrentBackgroundCalculationsFlags(); | |
|
ncarter (slow)
2016/02/19 18:19:03
Ah okay, this was the part I missed. I think this
| |
| 442 } | |
| 443 } | |
| 444 | |
| 398 } // namespace task_management | 445 } // namespace task_management |
| OLD | NEW |