| 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 437 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 448 // Invalidate the cached sorted IDs by clearing the list. | 448 // Invalidate the cached sorted IDs by clearing the list. |
| 449 sorted_task_ids_.clear(); | 449 sorted_task_ids_.clear(); |
| 450 } | 450 } |
| 451 | 451 |
| 452 void TaskManagerImpl::TaskUnresponsive(Task* task) { | 452 void TaskManagerImpl::TaskUnresponsive(Task* task) { |
| 453 DCHECK(task); | 453 DCHECK(task); |
| 454 NotifyObserversOnTaskUnresponsive(task->task_id()); | 454 NotifyObserversOnTaskUnresponsive(task->task_id()); |
| 455 } | 455 } |
| 456 | 456 |
| 457 // static | 457 // static |
| 458 void TaskManagerImpl::OnMultipleBytesTransferredUI( | 458 void TaskManagerImpl::OnMultipleBytesTransferredUI(BytesTransferredMap params) { |
| 459 std::vector<BytesTransferredParam>* params) { | |
| 460 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 459 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 461 DCHECK(params); | 460 for (auto it : params) { |
| 462 | 461 if (!GetInstance()->UpdateTasksWithBytesTransferred(it.first, it.second)) { |
| 463 for (BytesTransferredParam& param : *params) { | |
| 464 if (!GetInstance()->UpdateTasksWithBytesTransferred(param)) { | |
| 465 // We can't match a task to the notification. That might mean the | 462 // We can't match a task to the notification. That might mean the |
| 466 // tab that started a download was closed, or the request may have had | 463 // tab that started a download was closed, or the request may have had |
| 467 // no originating task associated with it in the first place. | 464 // no originating task associated with it in the first place. |
| 468 // We attribute orphaned/unaccounted activity to the Browser process. | 465 // We attribute orphaned/unaccounted activity to the Browser process. |
| 469 DCHECK(param.origin_pid || (param.child_id != -1)); | 466 DCHECK(it.first.origin_pid || (it.first.child_id != -1)); |
| 470 | 467 // Since the key is meant to be immutable we create a fake key for the |
| 471 param.origin_pid = 0; | 468 // purpose of attributing the orphaned/unaccounted activity to the Browser |
| 472 param.child_id = param.route_id = -1; | 469 // process. |
| 473 GetInstance()->UpdateTasksWithBytesTransferred(param); | 470 int dummy_origin_pid = 0; |
| 471 int dummy_child_id = -1; |
| 472 int dummy_route_id = -1; |
| 473 BytesTransferredKey dummy_key = |
| 474 BytesTransferredKey(dummy_origin_pid, dummy_child_id, dummy_route_id); |
| 475 GetInstance()->UpdateTasksWithBytesTransferred(dummy_key, it.second); |
| 474 } | 476 } |
| 475 } | 477 } |
| 476 } | 478 } |
| 477 | 479 |
| 478 void TaskManagerImpl::OnVideoMemoryUsageStatsUpdate( | 480 void TaskManagerImpl::OnVideoMemoryUsageStatsUpdate( |
| 479 const gpu::VideoMemoryUsageStats& gpu_memory_stats) { | 481 const gpu::VideoMemoryUsageStats& gpu_memory_stats) { |
| 480 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 482 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 481 | 483 |
| 482 gpu_memory_stats_ = gpu_memory_stats; | 484 gpu_memory_stats_ = gpu_memory_stats; |
| 483 } | 485 } |
| (...skipping 16 matching lines...) Expand all Loading... |
| 500 | 502 |
| 501 void TaskManagerImpl::StartUpdating() { | 503 void TaskManagerImpl::StartUpdating() { |
| 502 if (is_running_) | 504 if (is_running_) |
| 503 return; | 505 return; |
| 504 | 506 |
| 505 is_running_ = true; | 507 is_running_ = true; |
| 506 | 508 |
| 507 for (const auto& provider : task_providers_) | 509 for (const auto& provider : task_providers_) |
| 508 provider->SetObserver(this); | 510 provider->SetObserver(this); |
| 509 | 511 |
| 510 io_thread_helper_manager_.reset(new IoThreadHelperManager); | 512 io_thread_helper_manager_.reset(new IoThreadHelperManager( |
| 513 base::BindRepeating(&TaskManagerImpl::OnMultipleBytesTransferredUI))); |
| 511 } | 514 } |
| 512 | 515 |
| 513 void TaskManagerImpl::StopUpdating() { | 516 void TaskManagerImpl::StopUpdating() { |
| 514 if (!is_running_) | 517 if (!is_running_) |
| 515 return; | 518 return; |
| 516 | 519 |
| 517 is_running_ = false; | 520 is_running_ = false; |
| 518 | 521 |
| 519 io_thread_helper_manager_.reset(); | 522 io_thread_helper_manager_.reset(); |
| 520 | 523 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 532 for (const auto& task_provider : task_providers_) { | 535 for (const auto& task_provider : task_providers_) { |
| 533 Task* task = | 536 Task* task = |
| 534 task_provider->GetTaskOfUrlRequest(origin_pid, child_id, route_id); | 537 task_provider->GetTaskOfUrlRequest(origin_pid, child_id, route_id); |
| 535 if (task) | 538 if (task) |
| 536 return task; | 539 return task; |
| 537 } | 540 } |
| 538 return nullptr; | 541 return nullptr; |
| 539 } | 542 } |
| 540 | 543 |
| 541 bool TaskManagerImpl::UpdateTasksWithBytesTransferred( | 544 bool TaskManagerImpl::UpdateTasksWithBytesTransferred( |
| 545 const BytesTransferredKey& key, |
| 542 const BytesTransferredParam& param) { | 546 const BytesTransferredParam& param) { |
| 543 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 547 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 544 | 548 |
| 545 Task* task = | 549 Task* task = GetTaskByPidOrRoute(key.origin_pid, key.child_id, key.route_id); |
| 546 GetTaskByPidOrRoute(param.origin_pid, param.child_id, param.route_id); | |
| 547 if (task) { | 550 if (task) { |
| 548 task->OnNetworkBytesRead(param.byte_read_count); | 551 task->OnNetworkBytesRead(param.byte_read_count); |
| 549 task->OnNetworkBytesSent(param.byte_sent_count); | 552 task->OnNetworkBytesSent(param.byte_sent_count); |
| 550 return true; | 553 return true; |
| 551 } | 554 } |
| 552 | 555 |
| 553 // Couldn't match the bytes to any existing task. | 556 // Couldn't match the bytes to any existing task. |
| 554 return false; | 557 return false; |
| 555 } | 558 } |
| 556 | 559 |
| (...skipping 15 matching lines...) Expand all Loading... |
| 572 groups_itr.second->AreBackgroundCalculationsDone(); | 575 groups_itr.second->AreBackgroundCalculationsDone(); |
| 573 } | 576 } |
| 574 if (are_all_processes_data_ready) { | 577 if (are_all_processes_data_ready) { |
| 575 NotifyObserversOnRefreshWithBackgroundCalculations(GetTaskIdsList()); | 578 NotifyObserversOnRefreshWithBackgroundCalculations(GetTaskIdsList()); |
| 576 for (const auto& groups_itr : task_groups_by_proc_id_) | 579 for (const auto& groups_itr : task_groups_by_proc_id_) |
| 577 groups_itr.second->ClearCurrentBackgroundCalculationsFlags(); | 580 groups_itr.second->ClearCurrentBackgroundCalculationsFlags(); |
| 578 } | 581 } |
| 579 } | 582 } |
| 580 | 583 |
| 581 } // namespace task_manager | 584 } // namespace task_manager |
| OLD | NEW |