Update broken references to image assets
[chromium-blink-merge.git] / chrome / browser / task_management / sampling / task_group.h
blob6f882d00a27dc207dbede79b68a898a87aa73b21
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
3 // found in the LICENSE file.
5 #ifndef CHROME_BROWSER_TASK_MANAGEMENT_SAMPLING_TASK_GROUP_H_
6 #define CHROME_BROWSER_TASK_MANAGEMENT_SAMPLING_TASK_GROUP_H_
8 #include <map>
10 #include "base/memory/weak_ptr.h"
11 #include "base/process/process_handle.h"
12 #include "base/process/process_metrics.h"
13 #include "chrome/browser/task_management/providers/task.h"
14 #include "chrome/browser/task_management/sampling/task_group_sampler.h"
15 #include "chrome/browser/task_management/task_manager_observer.h"
16 #include "content/public/common/gpu_memory_stats.h"
18 namespace task_management {
20 // Defines a group of tasks tracked by the task manager which belong to the same
21 // process. This class lives on the UI thread.
22 class TaskGroup {
23 public:
24 TaskGroup(
25 base::ProcessHandle proc_handle,
26 base::ProcessId proc_id,
27 const scoped_refptr<base::SequencedTaskRunner>& blocking_pool_runner);
28 ~TaskGroup();
30 // Adds and removes the given |task| to this group. |task| must be running on
31 // the same process represented by this group.
32 void AddTask(Task* task);
33 void RemoveTask(Task* task);
35 void Refresh(const content::GPUVideoMemoryUsageStats& gpu_memory_stats,
36 base::TimeDelta update_interval,
37 int64 refresh_flags);
39 // Appends the sorted IDs of the tasks that belong to this group to
40 // |out_list|.
41 void AppendSortedTaskIds(TaskIdList* out_list) const;
43 Task* GetTaskById(TaskId task_id) const;
45 const base::ProcessHandle& process_handle() const { return process_handle_; }
46 const base::ProcessId& process_id() const { return process_id_; }
48 size_t num_tasks() const { return tasks_.size(); }
49 bool empty() const { return tasks_.empty(); }
51 double cpu_usage() const { return cpu_usage_; }
52 int64 private_bytes() const { return memory_usage_.private_bytes; }
53 int64 shared_bytes() const { return memory_usage_.shared_bytes; }
54 int64 physical_bytes() const { return memory_usage_.physical_bytes; }
55 int64 gpu_memory() const { return gpu_memory_; }
56 bool gpu_memory_has_duplicates() const { return gpu_memory_has_duplicates_; }
58 #if defined(OS_WIN)
59 int64 gdi_current_handles() const { return gdi_current_handles_; }
60 int64 gdi_peak_handles() const { return gdi_peak_handles_; }
61 int64 user_current_handles() const { return user_current_handles_; }
62 int64 user_peak_handles() const { return user_peak_handles_; }
63 #endif // defined(OS_WIN)
65 #if !defined(DISABLE_NACL)
66 int nacl_debug_stub_port() const { return nacl_debug_stub_port_; }
67 #endif // !defined(DISABLE_NACL)
69 int idle_wakeups_per_second() const { return idle_wakeups_per_second_; }
71 private:
72 void RefreshGpuMemory(
73 const content::GPUVideoMemoryUsageStats& gpu_memory_stats);
75 void RefreshWindowsHandles();
77 // |child_process_unique_id| see Task::GetChildProcessUniqueID().
78 void RefreshNaClDebugStubPort(int child_process_unique_id);
80 void OnCpuRefreshDone(double cpu_usage);
82 void OnMemoryUsageRefreshDone(MemoryUsageStats memory_usage);
84 void OnIdleWakeupsRefreshDone(int idle_wakeups_per_second);
86 // The process' handle and ID.
87 base::ProcessHandle process_handle_;
88 base::ProcessId process_id_;
90 scoped_refptr<TaskGroupSampler> worker_thread_sampler_;
92 // Maps the Tasks by their IDs.
93 // Tasks are not owned by the TaskGroup. They're owned by the TaskProviders.
94 std::map<TaskId, Task*> tasks_;
96 // The per process resources usages.
97 double cpu_usage_;
98 MemoryUsageStats memory_usage_;
99 int64 gpu_memory_;
100 #if defined(OS_WIN)
101 // Windows GDI and USER Handles.
102 int64 gdi_current_handles_;
103 int64 gdi_peak_handles_;
104 int64 user_current_handles_;
105 int64 user_peak_handles_;
106 #endif // defined(OS_WIN)
107 #if !defined(DISABLE_NACL)
108 int nacl_debug_stub_port_;
109 #endif // !defined(DISABLE_NACL)
110 int idle_wakeups_per_second_;
111 bool gpu_memory_has_duplicates_;
113 // Always keep this the last member of this class so that it's the first to be
114 // destroyed.
115 base::WeakPtrFactory<TaskGroup> weak_ptr_factory_;
117 DISALLOW_COPY_AND_ASSIGN(TaskGroup);
120 } // namespace task_management
123 #endif // CHROME_BROWSER_TASK_MANAGEMENT_SAMPLING_TASK_GROUP_H_