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