| 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 <string> | 7 #include <string> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| (...skipping 24 matching lines...) Expand all Loading... |
| 35 | 35 |
| 36 return blocking_pool->GetSequencedTaskRunner(token); | 36 return blocking_pool->GetSequencedTaskRunner(token); |
| 37 } | 37 } |
| 38 | 38 |
| 39 base::LazyInstance<TaskManagerImpl> lazy_task_manager_instance = | 39 base::LazyInstance<TaskManagerImpl> lazy_task_manager_instance = |
| 40 LAZY_INSTANCE_INITIALIZER; | 40 LAZY_INSTANCE_INITIALIZER; |
| 41 | 41 |
| 42 } // namespace | 42 } // namespace |
| 43 | 43 |
| 44 TaskManagerImpl::TaskManagerImpl() | 44 TaskManagerImpl::TaskManagerImpl() |
| 45 : blocking_pool_runner_(GetBlockingPoolRunner()), | 45 : on_background_data_ready_callback_(base::Bind( |
| 46 &TaskManagerImpl::OnTaskGroupBackgroundCalculationsDone, |
| 47 base::Unretained(this))), |
| 48 blocking_pool_runner_(GetBlockingPoolRunner()), |
| 46 is_running_(false) { | 49 is_running_(false) { |
| 47 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 50 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 48 | 51 |
| 49 task_providers_.push_back(new BrowserProcessTaskProvider()); | 52 task_providers_.push_back(new BrowserProcessTaskProvider()); |
| 50 task_providers_.push_back(new ChildProcessTaskProvider()); | 53 task_providers_.push_back(new ChildProcessTaskProvider()); |
| 51 task_providers_.push_back(new WebContentsTaskProvider()); | 54 task_providers_.push_back(new WebContentsTaskProvider()); |
| 52 #if defined(OS_CHROMEOS) | 55 #if defined(OS_CHROMEOS) |
| 53 if (arc::ArcBridgeService::GetEnabled( | 56 if (arc::ArcBridgeService::GetEnabled( |
| 54 base::CommandLine::ForCurrentProcess())) { | 57 base::CommandLine::ForCurrentProcess())) { |
| 55 task_providers_.push_back(new ArcProcessTaskProvider()); | 58 task_providers_.push_back(new ArcProcessTaskProvider()); |
| (...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 176 } | 179 } |
| 177 | 180 |
| 178 const base::ProcessId& TaskManagerImpl::GetProcessId(TaskId task_id) const { | 181 const base::ProcessId& TaskManagerImpl::GetProcessId(TaskId task_id) const { |
| 179 return GetTaskGroupByTaskId(task_id)->process_id(); | 182 return GetTaskGroupByTaskId(task_id)->process_id(); |
| 180 } | 183 } |
| 181 | 184 |
| 182 Task::Type TaskManagerImpl::GetType(TaskId task_id) const { | 185 Task::Type TaskManagerImpl::GetType(TaskId task_id) const { |
| 183 return GetTaskByTaskId(task_id)->GetType(); | 186 return GetTaskByTaskId(task_id)->GetType(); |
| 184 } | 187 } |
| 185 | 188 |
| 189 int TaskManagerImpl::GetTabId(TaskId task_id) const { |
| 190 return GetTaskByTaskId(task_id)->GetTabId(); |
| 191 } |
| 192 |
| 193 int TaskManagerImpl::GetChildProcessUniqueId(TaskId task_id) const { |
| 194 return GetTaskByTaskId(task_id)->GetChildProcessUniqueID(); |
| 195 } |
| 196 |
| 197 void TaskManagerImpl::GetTerminationStatus(TaskId task_id, |
| 198 base::TerminationStatus* out_status, |
| 199 int* out_error_code) const { |
| 200 GetTaskByTaskId(task_id)->GetTerminationStatus(out_status, out_error_code); |
| 201 } |
| 202 |
| 186 int64_t TaskManagerImpl::GetNetworkUsage(TaskId task_id) const { | 203 int64_t TaskManagerImpl::GetNetworkUsage(TaskId task_id) const { |
| 187 return GetTaskByTaskId(task_id)->network_usage(); | 204 return GetTaskByTaskId(task_id)->network_usage(); |
| 188 } | 205 } |
| 189 | 206 |
| 190 int64_t TaskManagerImpl::GetProcessTotalNetworkUsage(TaskId task_id) const { | 207 int64_t TaskManagerImpl::GetProcessTotalNetworkUsage(TaskId task_id) const { |
| 191 return GetTaskGroupByTaskId(task_id)->per_process_network_usage(); | 208 return GetTaskGroupByTaskId(task_id)->per_process_network_usage(); |
| 192 } | 209 } |
| 193 | 210 |
| 194 int64_t TaskManagerImpl::GetSqliteMemoryUsed(TaskId task_id) const { | 211 int64_t TaskManagerImpl::GetSqliteMemoryUsed(TaskId task_id) const { |
| 195 return GetTaskByTaskId(task_id)->GetSqliteMemoryUsed(); | 212 return GetTaskByTaskId(task_id)->GetSqliteMemoryUsed(); |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 237 if (groups_pair.second == browser_group) | 254 if (groups_pair.second == browser_group) |
| 238 continue; | 255 continue; |
| 239 | 256 |
| 240 groups_pair.second->AppendSortedTaskIds(&sorted_task_ids_); | 257 groups_pair.second->AppendSortedTaskIds(&sorted_task_ids_); |
| 241 } | 258 } |
| 242 } | 259 } |
| 243 | 260 |
| 244 return sorted_task_ids_; | 261 return sorted_task_ids_; |
| 245 } | 262 } |
| 246 | 263 |
| 264 TaskIdList TaskManagerImpl::GetIdsOfTasksSharingSameProcess( |
| 265 TaskId task_id) const { |
| 266 DCHECK(is_running_) << "Task manager is not running. You must observe the " |
| 267 "task manager for it to start running"; |
| 268 |
| 269 TaskIdList result; |
| 270 GetTaskGroupByTaskId(task_id)->AppendSortedTaskIds(&result); |
| 271 return result; |
| 272 } |
| 273 |
| 247 size_t TaskManagerImpl::GetNumberOfTasksOnSameProcess(TaskId task_id) const { | 274 size_t TaskManagerImpl::GetNumberOfTasksOnSameProcess(TaskId task_id) const { |
| 248 return GetTaskGroupByTaskId(task_id)->num_tasks(); | 275 return GetTaskGroupByTaskId(task_id)->num_tasks(); |
| 249 } | 276 } |
| 250 | 277 |
| 251 void TaskManagerImpl::TaskAdded(Task* task) { | 278 void TaskManagerImpl::TaskAdded(Task* task) { |
| 252 DCHECK(task); | 279 DCHECK(task); |
| 253 | 280 |
| 254 TaskGroup* task_group = nullptr; | 281 TaskGroup* task_group = nullptr; |
| 255 const base::ProcessId proc_id = task->process_id(); | 282 const base::ProcessId proc_id = task->process_id(); |
| 256 const TaskId task_id = task->task_id(); | 283 const TaskId task_id = task->task_id(); |
| 257 | 284 |
| 258 auto itr = task_groups_by_proc_id_.find(proc_id); | 285 auto itr = task_groups_by_proc_id_.find(proc_id); |
| 259 if (itr == task_groups_by_proc_id_.end()) { | 286 if (itr == task_groups_by_proc_id_.end()) { |
| 260 task_group = new TaskGroup(task->process_handle(), | 287 task_group = new TaskGroup(task->process_handle(), |
| 261 proc_id, | 288 proc_id, |
| 289 on_background_data_ready_callback_, |
| 262 blocking_pool_runner_); | 290 blocking_pool_runner_); |
| 263 task_groups_by_proc_id_[proc_id] = task_group; | 291 task_groups_by_proc_id_[proc_id] = task_group; |
| 264 } else { | 292 } else { |
| 265 task_group = itr->second; | 293 task_group = itr->second; |
| 266 } | 294 } |
| 267 | 295 |
| 268 task_group->AddTask(task); | 296 task_group->AddTask(task); |
| 269 | 297 |
| 270 task_groups_by_task_id_[task_id] = task_group; | 298 task_groups_by_task_id_[task_id] = task_group; |
| 271 | 299 |
| (...skipping 21 matching lines...) Expand all Loading... |
| 293 | 321 |
| 294 // Invalidate the cached sorted IDs by clearing the list. | 322 // Invalidate the cached sorted IDs by clearing the list. |
| 295 sorted_task_ids_.clear(); | 323 sorted_task_ids_.clear(); |
| 296 | 324 |
| 297 if (task_group->empty()) { | 325 if (task_group->empty()) { |
| 298 task_groups_by_proc_id_.erase(proc_id); | 326 task_groups_by_proc_id_.erase(proc_id); |
| 299 delete task_group; | 327 delete task_group; |
| 300 } | 328 } |
| 301 } | 329 } |
| 302 | 330 |
| 331 void TaskManagerImpl::TaskUnresponsive(Task* task) { |
| 332 DCHECK(task); |
| 333 NotifyObserversOnTaskUnresponsive(task->task_id()); |
| 334 } |
| 335 |
| 303 void TaskManagerImpl::OnVideoMemoryUsageStatsUpdate( | 336 void TaskManagerImpl::OnVideoMemoryUsageStatsUpdate( |
| 304 const gpu::VideoMemoryUsageStats& gpu_memory_stats) { | 337 const gpu::VideoMemoryUsageStats& gpu_memory_stats) { |
| 305 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 338 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 306 | 339 |
| 307 gpu_memory_stats_ = gpu_memory_stats; | 340 gpu_memory_stats_ = gpu_memory_stats; |
| 308 } | 341 } |
| 309 | 342 |
| 310 // static | 343 // static |
| 311 void TaskManagerImpl::OnMultipleBytesReadUI( | 344 void TaskManagerImpl::OnMultipleBytesReadUI( |
| 312 std::vector<BytesReadParam>* params) { | 345 std::vector<BytesReadParam>* params) { |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 392 TaskGroup* TaskManagerImpl::GetTaskGroupByTaskId(TaskId task_id) const { | 425 TaskGroup* TaskManagerImpl::GetTaskGroupByTaskId(TaskId task_id) const { |
| 393 DCHECK(ContainsKey(task_groups_by_task_id_, task_id)); | 426 DCHECK(ContainsKey(task_groups_by_task_id_, task_id)); |
| 394 | 427 |
| 395 return task_groups_by_task_id_.at(task_id); | 428 return task_groups_by_task_id_.at(task_id); |
| 396 } | 429 } |
| 397 | 430 |
| 398 Task* TaskManagerImpl::GetTaskByTaskId(TaskId task_id) const { | 431 Task* TaskManagerImpl::GetTaskByTaskId(TaskId task_id) const { |
| 399 return GetTaskGroupByTaskId(task_id)->GetTaskById(task_id); | 432 return GetTaskGroupByTaskId(task_id)->GetTaskById(task_id); |
| 400 } | 433 } |
| 401 | 434 |
| 435 void TaskManagerImpl::OnTaskGroupBackgroundCalculationsDone() { |
| 436 // TODO(afakhry): There should be a better way for doing this! |
| 437 bool are_all_processes_data_ready = true; |
| 438 for (auto& groups_itr : task_groups_by_proc_id_) { |
| 439 are_all_processes_data_ready &= |
| 440 groups_itr.second->AreBackgroundCalculationsDone(); |
| 441 } |
| 442 if (are_all_processes_data_ready) { |
| 443 NotifyObserversOnRefreshWithBackgroundCalculations(GetTaskIdsList()); |
| 444 for (auto& groups_itr : task_groups_by_proc_id_) |
| 445 groups_itr.second->ClearCurrentBackgroundCalculationsFlags(); |
| 446 } |
| 447 } |
| 448 |
| 402 } // namespace task_management | 449 } // namespace task_management |
| OLD | NEW |