Pin Chrome's shortcut to the Win10 Start menu on install and OS upgrade.
[chromium-blink-merge.git] / chrome / browser / task_management / sampling / task_group.h
blob718620a5df18dbddb0ee311c3bf4fd720b52cffd
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.
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 Task* GetTaskById(TaskId task_id) const;
41 size_t num_tasks() const { return tasks_.size(); }
42 bool empty() const { return tasks_.empty(); }
44 double cpu_usage() const { return cpu_usage_; }
45 int64 private_bytes() const { return memory_usage_.private_bytes; }
46 int64 shared_bytes() const { return memory_usage_.shared_bytes; }
47 int64 physical_bytes() const { return memory_usage_.physical_bytes; }
48 int64 gpu_memory() const { return gpu_memory_; }
49 bool gpu_memory_has_duplicates() const { return gpu_memory_has_duplicates_; }
51 #if defined(OS_WIN)
52 int64 gdi_current_handles() const { return gdi_current_handles_; }
53 int64 gdi_peak_handles() const { return gdi_peak_handles_; }
54 int64 user_current_handles() const { return user_current_handles_; }
55 int64 user_peak_handles() const { return user_peak_handles_; }
56 #endif // defined(OS_WIN)
58 #if !defined(DISABLE_NACL)
59 int nacl_debug_stub_port() const { return nacl_debug_stub_port_; }
60 #endif // !defined(DISABLE_NACL)
62 int idle_wakeups_per_second() const { return idle_wakeups_per_second_; }
64 private:
65 void RefreshGpuMemory(
66 const content::GPUVideoMemoryUsageStats& gpu_memory_stats);
68 void RefreshWindowsHandles();
70 // |child_process_unique_id| see Task::GetChildProcessUniqueID().
71 void RefreshNaClDebugStubPort(int child_process_unique_id);
73 void OnCpuRefreshDone(double cpu_usage);
75 void OnMemoryUsageRefreshDone(MemoryUsageStats memory_usage);
77 void OnIdleWakeupsRefreshDone(int idle_wakeups_per_second);
79 // The process' handle and ID.
80 base::ProcessHandle process_handle_;
81 base::ProcessId process_id_;
83 scoped_refptr<TaskGroupSampler> worker_thread_sampler_;
85 // Maps the Tasks by their IDs.
86 // Tasks are not owned by the TaskGroup. They're owned by the TaskProviders.
87 std::map<TaskId, Task*> tasks_;
89 // The per process resources usages.
90 double cpu_usage_;
91 MemoryUsageStats memory_usage_;
92 int64 gpu_memory_;
93 #if defined(OS_WIN)
94 // Windows GDI and USER Handles.
95 int64 gdi_current_handles_;
96 int64 gdi_peak_handles_;
97 int64 user_current_handles_;
98 int64 user_peak_handles_;
99 #endif // defined(OS_WIN)
100 #if !defined(DISABLE_NACL)
101 int nacl_debug_stub_port_;
102 #endif // !defined(DISABLE_NACL)
103 int idle_wakeups_per_second_;
104 bool gpu_memory_has_duplicates_;
106 // Always keep this the last member of this class so that it's the first to be
107 // destroyed.
108 base::WeakPtrFactory<TaskGroup> weak_ptr_factory_;
110 DISALLOW_COPY_AND_ASSIGN(TaskGroup);
113 } // namespace task_management
116 #endif // CHROME_BROWSER_TASK_MANAGEMENT_SAMPLING_TASK_GROUP_H_