| 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 <algorithm> | 7 #include <algorithm> |
| 8 #include <string> | 8 #include <string> |
| 9 #include <unordered_map> | 9 #include <unordered_map> |
| 10 #include <unordered_set> | 10 #include <unordered_set> |
| 11 #include <vector> | 11 #include <vector> |
| 12 | 12 |
| 13 #include "base/command_line.h" | 13 #include "base/command_line.h" |
| 14 #include "base/containers/adapters.h" | 14 #include "base/containers/adapters.h" |
| 15 #include "base/stl_util.h" | |
| 16 #include "build/build_config.h" | 15 #include "build/build_config.h" |
| 17 #include "chrome/browser/task_management/providers/browser_process_task_provider
.h" | 16 #include "chrome/browser/task_management/providers/browser_process_task_provider
.h" |
| 18 #include "chrome/browser/task_management/providers/child_process_task_provider.h
" | 17 #include "chrome/browser/task_management/providers/child_process_task_provider.h
" |
| 19 #include "chrome/browser/task_management/providers/web_contents/web_contents_tas
k_provider.h" | 18 #include "chrome/browser/task_management/providers/web_contents/web_contents_tas
k_provider.h" |
| 20 #include "content/public/browser/browser_thread.h" | 19 #include "content/public/browser/browser_thread.h" |
| 21 #include "content/public/browser/gpu_data_manager.h" | 20 #include "content/public/browser/gpu_data_manager.h" |
| 22 #include "content/public/browser/render_frame_host.h" | 21 #include "content/public/browser/render_frame_host.h" |
| 23 #include "content/public/browser/render_process_host.h" | 22 #include "content/public/browser/render_process_host.h" |
| 24 #include "content/public/browser/web_contents.h" | 23 #include "content/public/browser/web_contents.h" |
| 25 | 24 |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 60 base::CommandLine::ForCurrentProcess())) { | 59 base::CommandLine::ForCurrentProcess())) { |
| 61 task_providers_.emplace_back(new ArcProcessTaskProvider()); | 60 task_providers_.emplace_back(new ArcProcessTaskProvider()); |
| 62 } | 61 } |
| 63 #endif // defined(OS_CHROMEOS) | 62 #endif // defined(OS_CHROMEOS) |
| 64 | 63 |
| 65 content::GpuDataManager::GetInstance()->AddObserver(this); | 64 content::GpuDataManager::GetInstance()->AddObserver(this); |
| 66 } | 65 } |
| 67 | 66 |
| 68 TaskManagerImpl::~TaskManagerImpl() { | 67 TaskManagerImpl::~TaskManagerImpl() { |
| 69 content::GpuDataManager::GetInstance()->RemoveObserver(this); | 68 content::GpuDataManager::GetInstance()->RemoveObserver(this); |
| 70 | |
| 71 STLDeleteValues(&task_groups_by_proc_id_); | |
| 72 } | 69 } |
| 73 | 70 |
| 74 // static | 71 // static |
| 75 TaskManagerImpl* TaskManagerImpl::GetInstance() { | 72 TaskManagerImpl* TaskManagerImpl::GetInstance() { |
| 76 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 73 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 77 | 74 |
| 78 return lazy_task_manager_instance.Pointer(); | 75 return lazy_task_manager_instance.Pointer(); |
| 79 } | 76 } |
| 80 | 77 |
| 81 void TaskManagerImpl::ActivateTask(TaskId task_id) { | 78 void TaskManagerImpl::ActivateTask(TaskId task_id) { |
| (...skipping 291 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 373 Task* task = | 370 Task* task = |
| 374 GetTaskByPidOrRoute(0, rfh->GetProcess()->GetID(), rfh->GetRoutingID()); | 371 GetTaskByPidOrRoute(0, rfh->GetProcess()->GetID(), rfh->GetRoutingID()); |
| 375 if (!task) | 372 if (!task) |
| 376 return -1; | 373 return -1; |
| 377 return task->task_id(); | 374 return task->task_id(); |
| 378 } | 375 } |
| 379 | 376 |
| 380 void TaskManagerImpl::TaskAdded(Task* task) { | 377 void TaskManagerImpl::TaskAdded(Task* task) { |
| 381 DCHECK(task); | 378 DCHECK(task); |
| 382 | 379 |
| 383 TaskGroup* task_group = nullptr; | |
| 384 const base::ProcessId proc_id = task->process_id(); | 380 const base::ProcessId proc_id = task->process_id(); |
| 385 const TaskId task_id = task->task_id(); | 381 const TaskId task_id = task->task_id(); |
| 386 | 382 |
| 387 auto itr = task_groups_by_proc_id_.find(proc_id); | 383 std::unique_ptr<TaskGroup>& task_group = task_groups_by_proc_id_[proc_id]; |
| 388 if (itr == task_groups_by_proc_id_.end()) { | 384 if (!task_group) |
| 389 task_group = new TaskGroup(task->process_handle(), | 385 task_group.reset(new TaskGroup(task->process_handle(), proc_id, |
| 390 proc_id, | 386 on_background_data_ready_callback_, |
| 391 on_background_data_ready_callback_, | 387 blocking_pool_runner_)); |
| 392 blocking_pool_runner_); | |
| 393 task_groups_by_proc_id_[proc_id] = task_group; | |
| 394 } else { | |
| 395 task_group = itr->second; | |
| 396 } | |
| 397 | 388 |
| 398 task_group->AddTask(task); | 389 task_group->AddTask(task); |
| 399 | 390 |
| 400 task_groups_by_task_id_[task_id] = task_group; | 391 task_groups_by_task_id_[task_id] = task_group.get(); |
| 401 | 392 |
| 402 // Invalidate the cached sorted IDs by clearing the list. | 393 // Invalidate the cached sorted IDs by clearing the list. |
| 403 sorted_task_ids_.clear(); | 394 sorted_task_ids_.clear(); |
| 404 | 395 |
| 405 NotifyObserversOnTaskAdded(task_id); | 396 NotifyObserversOnTaskAdded(task_id); |
| 406 } | 397 } |
| 407 | 398 |
| 408 void TaskManagerImpl::TaskRemoved(Task* task) { | 399 void TaskManagerImpl::TaskRemoved(Task* task) { |
| 409 DCHECK(task); | 400 DCHECK(task); |
| 410 | 401 |
| 411 const base::ProcessId proc_id = task->process_id(); | 402 const base::ProcessId proc_id = task->process_id(); |
| 412 const TaskId task_id = task->task_id(); | 403 const TaskId task_id = task->task_id(); |
| 413 | 404 |
| 414 DCHECK(ContainsKey(task_groups_by_proc_id_, proc_id)); | 405 DCHECK(task_groups_by_proc_id_.count(proc_id)); |
| 415 DCHECK(ContainsKey(task_groups_by_task_id_, task_id)); | |
| 416 | 406 |
| 417 NotifyObserversOnTaskToBeRemoved(task_id); | 407 NotifyObserversOnTaskToBeRemoved(task_id); |
| 418 | 408 |
| 419 TaskGroup* task_group = task_groups_by_proc_id_[proc_id]; | 409 TaskGroup* task_group = GetTaskGroupByTaskId(task_id); |
| 420 task_group->RemoveTask(task); | 410 task_group->RemoveTask(task); |
| 411 task_groups_by_task_id_.erase(task_id); |
| 421 | 412 |
| 422 task_groups_by_task_id_.erase(task_id); | 413 if (task_group->empty()) |
| 414 task_groups_by_proc_id_.erase(proc_id); // Deletes |task_group|. |
| 423 | 415 |
| 424 // Invalidate the cached sorted IDs by clearing the list. | 416 // Invalidate the cached sorted IDs by clearing the list. |
| 425 sorted_task_ids_.clear(); | 417 sorted_task_ids_.clear(); |
| 426 | |
| 427 if (task_group->empty()) { | |
| 428 task_groups_by_proc_id_.erase(proc_id); | |
| 429 delete task_group; | |
| 430 } | |
| 431 } | 418 } |
| 432 | 419 |
| 433 void TaskManagerImpl::TaskUnresponsive(Task* task) { | 420 void TaskManagerImpl::TaskUnresponsive(Task* task) { |
| 434 DCHECK(task); | 421 DCHECK(task); |
| 435 NotifyObserversOnTaskUnresponsive(task->task_id()); | 422 NotifyObserversOnTaskUnresponsive(task->task_id()); |
| 436 } | 423 } |
| 437 | 424 |
| 438 void TaskManagerImpl::OnVideoMemoryUsageStatsUpdate( | 425 void TaskManagerImpl::OnVideoMemoryUsageStatsUpdate( |
| 439 const gpu::VideoMemoryUsageStats& gpu_memory_stats) { | 426 const gpu::VideoMemoryUsageStats& gpu_memory_stats) { |
| 440 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 427 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 495 if (!is_running_) | 482 if (!is_running_) |
| 496 return; | 483 return; |
| 497 | 484 |
| 498 is_running_ = false; | 485 is_running_ = false; |
| 499 | 486 |
| 500 io_thread_helper_manager_.reset(); | 487 io_thread_helper_manager_.reset(); |
| 501 | 488 |
| 502 for (const auto& provider : task_providers_) | 489 for (const auto& provider : task_providers_) |
| 503 provider->ClearObserver(); | 490 provider->ClearObserver(); |
| 504 | 491 |
| 505 STLDeleteValues(&task_groups_by_proc_id_); | 492 task_groups_by_proc_id_.clear(); |
| 506 task_groups_by_task_id_.clear(); | 493 task_groups_by_task_id_.clear(); |
| 507 sorted_task_ids_.clear(); | 494 sorted_task_ids_.clear(); |
| 508 } | 495 } |
| 509 | 496 |
| 510 Task* TaskManagerImpl::GetTaskByPidOrRoute(int origin_pid, | 497 Task* TaskManagerImpl::GetTaskByPidOrRoute(int origin_pid, |
| 511 int child_id, | 498 int child_id, |
| 512 int route_id) const { | 499 int route_id) const { |
| 513 for (const auto& task_provider : task_providers_) { | 500 for (const auto& task_provider : task_providers_) { |
| 514 Task* task = | 501 Task* task = |
| 515 task_provider->GetTaskOfUrlRequest(origin_pid, child_id, route_id); | 502 task_provider->GetTaskOfUrlRequest(origin_pid, child_id, route_id); |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 551 groups_itr.second->AreBackgroundCalculationsDone(); | 538 groups_itr.second->AreBackgroundCalculationsDone(); |
| 552 } | 539 } |
| 553 if (are_all_processes_data_ready) { | 540 if (are_all_processes_data_ready) { |
| 554 NotifyObserversOnRefreshWithBackgroundCalculations(GetTaskIdsList()); | 541 NotifyObserversOnRefreshWithBackgroundCalculations(GetTaskIdsList()); |
| 555 for (const auto& groups_itr : task_groups_by_proc_id_) | 542 for (const auto& groups_itr : task_groups_by_proc_id_) |
| 556 groups_itr.second->ClearCurrentBackgroundCalculationsFlags(); | 543 groups_itr.second->ClearCurrentBackgroundCalculationsFlags(); |
| 557 } | 544 } |
| 558 } | 545 } |
| 559 | 546 |
| 560 } // namespace task_management | 547 } // namespace task_management |
| OLD | NEW |