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 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
229 void TaskManagerImpl::GetTerminationStatus(TaskId task_id, | 229 void TaskManagerImpl::GetTerminationStatus(TaskId task_id, |
230 base::TerminationStatus* out_status, | 230 base::TerminationStatus* out_status, |
231 int* out_error_code) const { | 231 int* out_error_code) const { |
232 GetTaskByTaskId(task_id)->GetTerminationStatus(out_status, out_error_code); | 232 GetTaskByTaskId(task_id)->GetTerminationStatus(out_status, out_error_code); |
233 } | 233 } |
234 | 234 |
235 int64_t TaskManagerImpl::GetNetworkUsage(TaskId task_id) const { | 235 int64_t TaskManagerImpl::GetNetworkUsage(TaskId task_id) const { |
236 return GetTaskByTaskId(task_id)->network_usage(); | 236 return GetTaskByTaskId(task_id)->network_usage(); |
237 } | 237 } |
238 | 238 |
239 int64_t TaskManagerImpl::GetTotalNetworkUsage(TaskId task_id) const { | |
240 return GetTaskByTaskId(task_id)->total_network_usage(); | |
241 } | |
242 | |
239 int64_t TaskManagerImpl::GetProcessTotalNetworkUsage(TaskId task_id) const { | 243 int64_t TaskManagerImpl::GetProcessTotalNetworkUsage(TaskId task_id) const { |
240 return GetTaskGroupByTaskId(task_id)->per_process_network_usage(); | 244 return GetTaskGroupByTaskId(task_id)->per_process_network_usage(); |
241 } | 245 } |
242 | 246 |
247 int64_t TaskManagerImpl::GetTotalProcessTotalNetworkUsage( | |
248 TaskId task_id) const { | |
249 return GetTaskGroupByTaskId(task_id)->total_per_process_network_usage(); | |
250 } | |
251 | |
243 int64_t TaskManagerImpl::GetSqliteMemoryUsed(TaskId task_id) const { | 252 int64_t TaskManagerImpl::GetSqliteMemoryUsed(TaskId task_id) const { |
244 return GetTaskByTaskId(task_id)->GetSqliteMemoryUsed(); | 253 return GetTaskByTaskId(task_id)->GetSqliteMemoryUsed(); |
245 } | 254 } |
246 | 255 |
247 bool TaskManagerImpl::GetV8Memory(TaskId task_id, | 256 bool TaskManagerImpl::GetV8Memory(TaskId task_id, |
248 int64_t* allocated, | 257 int64_t* allocated, |
249 int64_t* used) const { | 258 int64_t* used) const { |
250 const Task* task = GetTaskByTaskId(task_id); | 259 const Task* task = GetTaskByTaskId(task_id); |
251 if (!task->ReportsV8Memory()) | 260 if (!task->ReportsV8Memory()) |
252 return false; | 261 return false; |
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
445 sorted_task_ids_.clear(); | 454 sorted_task_ids_.clear(); |
446 } | 455 } |
447 | 456 |
448 void TaskManagerImpl::TaskUnresponsive(Task* task) { | 457 void TaskManagerImpl::TaskUnresponsive(Task* task) { |
449 DCHECK(task); | 458 DCHECK(task); |
450 NotifyObserversOnTaskUnresponsive(task->task_id()); | 459 NotifyObserversOnTaskUnresponsive(task->task_id()); |
451 } | 460 } |
452 | 461 |
453 // static | 462 // static |
454 void TaskManagerImpl::OnMultipleBytesReadUI( | 463 void TaskManagerImpl::OnMultipleBytesReadUI( |
455 std::vector<BytesReadParam>* params) { | 464 std::vector<BytesTransferedParam>* params) { |
456 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 465 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
457 DCHECK(params); | 466 DCHECK(params); |
458 | 467 |
459 for (BytesReadParam& param : *params) { | 468 for (BytesTransferedParam& param : *params) { |
460 if (!GetInstance()->UpdateTasksWithBytesRead(param)) { | 469 if (!GetInstance()->UpdateTasksWithBytesRead(param)) { |
461 // We can't match a task to the notification. That might mean the | 470 // We can't match a task to the notification. That might mean the |
462 // tab that started a download was closed, or the request may have had | 471 // tab that started a download was closed, or the request may have had |
463 // no originating task associated with it in the first place. | 472 // no originating task associated with it in the first place. |
464 // We attribute orphaned/unaccounted activity to the Browser process. | 473 // We attribute orphaned/unaccounted activity to the Browser process. |
465 DCHECK(param.origin_pid || (param.child_id != -1)); | 474 DCHECK(param.origin_pid || (param.child_id != -1)); |
466 | 475 |
467 param.origin_pid = 0; | 476 param.origin_pid = 0; |
468 param.child_id = param.route_id = -1; | 477 param.child_id = param.route_id = -1; |
469 | 478 |
470 GetInstance()->UpdateTasksWithBytesRead(param); | 479 GetInstance()->UpdateTasksWithBytesRead(param); |
471 } | 480 } |
472 } | 481 } |
473 } | 482 } |
474 | 483 |
484 // static | |
485 void TaskManagerImpl::OnMultipleBytesSentUI( | |
ncarter (slow)
2017/06/08 23:37:18
Once BytesTransferedParam holds both send and read
cburn
2017/06/14 18:04:37
Done. Named it OnMultipleBytesTransfered to try to
| |
486 std::vector<BytesTransferedParam>* params) { | |
487 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | |
488 DCHECK(params); | |
489 | |
490 for (BytesTransferedParam& param : *params) { | |
491 if (!GetInstance()->UpdateTasksWithBytesSent(param)) { | |
492 // We can't match a task to the notification. That might mean the | |
493 // tab that started a download was closed, or the request may have had | |
494 // no originating task associated with it in the first place. | |
495 // We attribute orphaned/unaccounted activity to the Browser process. | |
496 DCHECK(param.origin_pid || (param.child_id != -1)); | |
497 | |
498 param.origin_pid = 0; | |
499 param.child_id = param.route_id = -1; | |
500 | |
501 GetInstance()->UpdateTasksWithBytesSent(param); | |
502 } | |
503 } | |
504 } | |
505 | |
475 void TaskManagerImpl::OnVideoMemoryUsageStatsUpdate( | 506 void TaskManagerImpl::OnVideoMemoryUsageStatsUpdate( |
476 const gpu::VideoMemoryUsageStats& gpu_memory_stats) { | 507 const gpu::VideoMemoryUsageStats& gpu_memory_stats) { |
477 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 508 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
478 | 509 |
479 gpu_memory_stats_ = gpu_memory_stats; | 510 gpu_memory_stats_ = gpu_memory_stats; |
480 } | 511 } |
481 | 512 |
482 void TaskManagerImpl::Refresh() { | 513 void TaskManagerImpl::Refresh() { |
483 if (IsResourceRefreshEnabled(REFRESH_TYPE_GPU_MEMORY)) { | 514 if (IsResourceRefreshEnabled(REFRESH_TYPE_GPU_MEMORY)) { |
484 content::GpuDataManager::GetInstance()->RequestVideoMemoryUsageStatsUpdate( | 515 content::GpuDataManager::GetInstance()->RequestVideoMemoryUsageStatsUpdate( |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
528 int route_id) const { | 559 int route_id) const { |
529 for (const auto& task_provider : task_providers_) { | 560 for (const auto& task_provider : task_providers_) { |
530 Task* task = | 561 Task* task = |
531 task_provider->GetTaskOfUrlRequest(origin_pid, child_id, route_id); | 562 task_provider->GetTaskOfUrlRequest(origin_pid, child_id, route_id); |
532 if (task) | 563 if (task) |
533 return task; | 564 return task; |
534 } | 565 } |
535 return nullptr; | 566 return nullptr; |
536 } | 567 } |
537 | 568 |
538 bool TaskManagerImpl::UpdateTasksWithBytesRead(const BytesReadParam& param) { | 569 bool TaskManagerImpl::UpdateTasksWithBytesRead( |
ncarter (slow)
2017/06/08 23:37:18
Merge this function with TaskManagerImpl::UpdateTa
cburn
2017/06/14 18:04:38
Done. I went with UpdateTasksWithBytesTransfered t
| |
570 const BytesTransferedParam& param) { | |
539 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 571 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
540 | 572 |
541 Task* task = | 573 Task* task = |
542 GetTaskByPidOrRoute(param.origin_pid, param.child_id, param.route_id); | 574 GetTaskByPidOrRoute(param.origin_pid, param.child_id, param.route_id); |
543 if (task) { | 575 if (task) { |
544 task->OnNetworkBytesRead(param.byte_count); | 576 task->OnNetworkBytesRead(param.byte_count); |
ncarter (slow)
2017/06/08 23:37:18
This might be the natural spot to split off into s
cburn
2017/06/14 18:04:38
Done.
| |
545 return true; | 577 return true; |
546 } | 578 } |
547 | 579 |
548 // Couldn't match the bytes to any existing task. | 580 // Couldn't match the bytes to any existing task. |
549 return false; | 581 return false; |
550 } | 582 } |
551 | 583 |
584 bool TaskManagerImpl::UpdateTasksWithBytesSent( | |
585 const BytesTransferedParam& param) { | |
586 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | |
587 | |
588 Task* task = | |
589 GetTaskByPidOrRoute(param.origin_pid, param.child_id, param.route_id); | |
590 if (task) { | |
591 task->OnNetworkBytesSent(param.byte_count); | |
592 return true; | |
593 } | |
594 | |
595 // Couldn't match the bytes to any existing task. | |
596 return false; | |
597 } | |
598 | |
552 TaskGroup* TaskManagerImpl::GetTaskGroupByTaskId(TaskId task_id) const { | 599 TaskGroup* TaskManagerImpl::GetTaskGroupByTaskId(TaskId task_id) const { |
553 auto it = task_groups_by_task_id_.find(task_id); | 600 auto it = task_groups_by_task_id_.find(task_id); |
554 DCHECK(it != task_groups_by_task_id_.end()); | 601 DCHECK(it != task_groups_by_task_id_.end()); |
555 return it->second; | 602 return it->second; |
556 } | 603 } |
557 | 604 |
558 Task* TaskManagerImpl::GetTaskByTaskId(TaskId task_id) const { | 605 Task* TaskManagerImpl::GetTaskByTaskId(TaskId task_id) const { |
559 return GetTaskGroupByTaskId(task_id)->GetTaskById(task_id); | 606 return GetTaskGroupByTaskId(task_id)->GetTaskById(task_id); |
560 } | 607 } |
561 | 608 |
562 void TaskManagerImpl::OnTaskGroupBackgroundCalculationsDone() { | 609 void TaskManagerImpl::OnTaskGroupBackgroundCalculationsDone() { |
563 // TODO(afakhry): There should be a better way for doing this! | 610 // TODO(afakhry): There should be a better way for doing this! |
564 bool are_all_processes_data_ready = true; | 611 bool are_all_processes_data_ready = true; |
565 for (const auto& groups_itr : task_groups_by_proc_id_) { | 612 for (const auto& groups_itr : task_groups_by_proc_id_) { |
566 are_all_processes_data_ready &= | 613 are_all_processes_data_ready &= |
567 groups_itr.second->AreBackgroundCalculationsDone(); | 614 groups_itr.second->AreBackgroundCalculationsDone(); |
568 } | 615 } |
569 if (are_all_processes_data_ready) { | 616 if (are_all_processes_data_ready) { |
570 NotifyObserversOnRefreshWithBackgroundCalculations(GetTaskIdsList()); | 617 NotifyObserversOnRefreshWithBackgroundCalculations(GetTaskIdsList()); |
571 for (const auto& groups_itr : task_groups_by_proc_id_) | 618 for (const auto& groups_itr : task_groups_by_proc_id_) |
572 groups_itr.second->ClearCurrentBackgroundCalculationsFlags(); | 619 groups_itr.second->ClearCurrentBackgroundCalculationsFlags(); |
573 } | 620 } |
574 } | 621 } |
575 | 622 |
576 } // namespace task_manager | 623 } // namespace task_manager |
OLD | NEW |