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_manager/sampling/task_manager_impl.h" | 5 #include "chrome/browser/task_manager/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> |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 43 lazy_task_manager_instance = LAZY_INSTANCE_INITIALIZER; | 43 lazy_task_manager_instance = LAZY_INSTANCE_INITIALIZER; |
| 44 | 44 |
| 45 } // namespace | 45 } // namespace |
| 46 | 46 |
| 47 TaskManagerImpl::TaskManagerImpl() | 47 TaskManagerImpl::TaskManagerImpl() |
| 48 : on_background_data_ready_callback_( | 48 : on_background_data_ready_callback_( |
| 49 base::Bind(&TaskManagerImpl::OnTaskGroupBackgroundCalculationsDone, | 49 base::Bind(&TaskManagerImpl::OnTaskGroupBackgroundCalculationsDone, |
| 50 base::Unretained(this))), | 50 base::Unretained(this))), |
| 51 blocking_pool_runner_(GetBlockingPoolRunner()), | 51 blocking_pool_runner_(GetBlockingPoolRunner()), |
| 52 shared_sampler_(new SharedSampler(blocking_pool_runner_)), | 52 shared_sampler_(new SharedSampler(blocking_pool_runner_)), |
| 53 is_running_(false) { | 53 is_running_(false), |
| 54 weak_ptr_factory_(this) { | |
| 54 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 55 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 55 | 56 |
| 56 task_providers_.emplace_back(new BrowserProcessTaskProvider()); | 57 task_providers_.emplace_back(new BrowserProcessTaskProvider()); |
| 57 task_providers_.emplace_back(new ChildProcessTaskProvider()); | 58 task_providers_.emplace_back(new ChildProcessTaskProvider()); |
| 58 task_providers_.emplace_back(new WebContentsTaskProvider()); | 59 task_providers_.emplace_back(new WebContentsTaskProvider()); |
| 59 #if defined(OS_CHROMEOS) | 60 #if defined(OS_CHROMEOS) |
| 60 if (arc::IsArcAvailable()) | 61 if (arc::IsArcAvailable()) |
| 61 task_providers_.emplace_back(new ArcProcessTaskProvider()); | 62 task_providers_.emplace_back(new ArcProcessTaskProvider()); |
| 62 #endif // defined(OS_CHROMEOS) | 63 #endif // defined(OS_CHROMEOS) |
| 63 | |
| 64 content::GpuDataManager::GetInstance()->AddObserver(this); | |
| 65 } | 64 } |
| 66 | 65 |
| 67 TaskManagerImpl::~TaskManagerImpl() { | 66 TaskManagerImpl::~TaskManagerImpl() { |
| 68 content::GpuDataManager::GetInstance()->RemoveObserver(this); | |
| 69 } | 67 } |
| 70 | 68 |
| 71 // static | 69 // static |
| 72 TaskManagerImpl* TaskManagerImpl::GetInstance() { | 70 TaskManagerImpl* TaskManagerImpl::GetInstance() { |
| 73 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 71 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 74 | 72 |
| 75 return lazy_task_manager_instance.Pointer(); | 73 return lazy_task_manager_instance.Pointer(); |
| 76 } | 74 } |
| 77 | 75 |
| 78 void TaskManagerImpl::ActivateTask(TaskId task_id) { | 76 void TaskManagerImpl::ActivateTask(TaskId task_id) { |
| (...skipping 366 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 445 | 443 |
| 446 // Invalidate the cached sorted IDs by clearing the list. | 444 // Invalidate the cached sorted IDs by clearing the list. |
| 447 sorted_task_ids_.clear(); | 445 sorted_task_ids_.clear(); |
| 448 } | 446 } |
| 449 | 447 |
| 450 void TaskManagerImpl::TaskUnresponsive(Task* task) { | 448 void TaskManagerImpl::TaskUnresponsive(Task* task) { |
| 451 DCHECK(task); | 449 DCHECK(task); |
| 452 NotifyObserversOnTaskUnresponsive(task->task_id()); | 450 NotifyObserversOnTaskUnresponsive(task->task_id()); |
| 453 } | 451 } |
| 454 | 452 |
| 455 void TaskManagerImpl::OnVideoMemoryUsageStatsUpdate( | |
| 456 const gpu::VideoMemoryUsageStats& gpu_memory_stats) { | |
| 457 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | |
| 458 | |
| 459 gpu_memory_stats_ = gpu_memory_stats; | |
| 460 } | |
| 461 | |
| 462 // static | 453 // static |
| 463 void TaskManagerImpl::OnMultipleBytesReadUI( | 454 void TaskManagerImpl::OnMultipleBytesReadUI( |
| 464 std::vector<BytesReadParam>* params) { | 455 std::vector<BytesReadParam>* params) { |
| 465 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 456 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 466 DCHECK(params); | 457 DCHECK(params); |
| 467 | 458 |
| 468 for (BytesReadParam& param : *params) { | 459 for (BytesReadParam& param : *params) { |
| 469 if (!GetInstance()->UpdateTasksWithBytesRead(param)) { | 460 if (!GetInstance()->UpdateTasksWithBytesRead(param)) { |
| 470 // We can't match a task to the notification. That might mean the | 461 // We can't match a task to the notification. That might mean the |
| 471 // tab that started a download was closed, or the request may have had | 462 // tab that started a download was closed, or the request may have had |
| 472 // no originating task associated with it in the first place. | 463 // no originating task associated with it in the first place. |
| 473 // We attribute orphaned/unaccounted activity to the Browser process. | 464 // We attribute orphaned/unaccounted activity to the Browser process. |
| 474 DCHECK(param.origin_pid || (param.child_id != -1)); | 465 DCHECK(param.origin_pid || (param.child_id != -1)); |
| 475 | 466 |
| 476 param.origin_pid = 0; | 467 param.origin_pid = 0; |
| 477 param.child_id = param.route_id = -1; | 468 param.child_id = param.route_id = -1; |
| 478 | 469 |
| 479 GetInstance()->UpdateTasksWithBytesRead(param); | 470 GetInstance()->UpdateTasksWithBytesRead(param); |
| 480 } | 471 } |
| 481 } | 472 } |
| 482 } | 473 } |
| 483 | 474 |
| 475 void TaskManagerImpl::OnVideoMemoryUsageStatsUpdate( | |
| 476 const gpu::VideoMemoryUsageStats& gpu_memory_stats) { | |
| 477 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | |
|
jbauman
2017/04/20 21:35:02
Won't this be called on the IO thread if it's run
sadrul
2017/04/21 03:41:01
Very nice. Good catch! Yes, you are right. I misse
| |
| 478 | |
| 479 gpu_memory_stats_ = gpu_memory_stats; | |
| 480 } | |
| 481 | |
| 484 void TaskManagerImpl::Refresh() { | 482 void TaskManagerImpl::Refresh() { |
| 485 if (IsResourceRefreshEnabled(REFRESH_TYPE_GPU_MEMORY)) { | 483 if (IsResourceRefreshEnabled(REFRESH_TYPE_GPU_MEMORY)) { |
| 486 content::GpuDataManager::GetInstance()-> | 484 content::GpuDataManager::GetInstance()->RequestVideoMemoryUsageStatsUpdate( |
| 487 RequestVideoMemoryUsageStatsUpdate(); | 485 base::Bind(&TaskManagerImpl::OnVideoMemoryUsageStatsUpdate, |
| 486 weak_ptr_factory_.GetWeakPtr())); | |
| 488 } | 487 } |
| 489 | 488 |
| 490 for (auto& groups_itr : task_groups_by_proc_id_) { | 489 for (auto& groups_itr : task_groups_by_proc_id_) { |
| 491 groups_itr.second->Refresh(gpu_memory_stats_, | 490 groups_itr.second->Refresh(gpu_memory_stats_, |
| 492 GetCurrentRefreshTime(), | 491 GetCurrentRefreshTime(), |
| 493 enabled_resources_flags()); | 492 enabled_resources_flags()); |
| 494 } | 493 } |
| 495 | 494 |
| 496 NotifyObserversOnRefresh(GetTaskIdsList()); | 495 NotifyObserversOnRefresh(GetTaskIdsList()); |
| 497 } | 496 } |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 568 groups_itr.second->AreBackgroundCalculationsDone(); | 567 groups_itr.second->AreBackgroundCalculationsDone(); |
| 569 } | 568 } |
| 570 if (are_all_processes_data_ready) { | 569 if (are_all_processes_data_ready) { |
| 571 NotifyObserversOnRefreshWithBackgroundCalculations(GetTaskIdsList()); | 570 NotifyObserversOnRefreshWithBackgroundCalculations(GetTaskIdsList()); |
| 572 for (const auto& groups_itr : task_groups_by_proc_id_) | 571 for (const auto& groups_itr : task_groups_by_proc_id_) |
| 573 groups_itr.second->ClearCurrentBackgroundCalculationsFlags(); | 572 groups_itr.second->ClearCurrentBackgroundCalculationsFlags(); |
| 574 } | 573 } |
| 575 } | 574 } |
| 576 | 575 |
| 577 } // namespace task_manager | 576 } // namespace task_manager |
| OLD | NEW |