blob: 02459fd5ab4e8e2eac94e01dca599dd950381d8d (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
|
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROME_BROWSER_TASK_MANAGEMENT_SAMPLING_TASK_GROUP_H_
#define CHROME_BROWSER_TASK_MANAGEMENT_SAMPLING_TASK_GROUP_H_
#include <stddef.h>
#include <stdint.h>
#include <map>
#include "base/macros.h"
#include "base/memory/weak_ptr.h"
#include "base/process/process_handle.h"
#include "base/process/process_metrics.h"
#include "build/build_config.h"
#include "chrome/browser/task_management/providers/task.h"
#include "chrome/browser/task_management/sampling/task_group_sampler.h"
#include "chrome/browser/task_management/task_manager_observer.h"
#include "content/public/common/gpu_memory_stats.h"
namespace task_management {
// Defines a group of tasks tracked by the task manager which belong to the same
// process. This class lives on the UI thread.
class TaskGroup {
public:
TaskGroup(
base::ProcessHandle proc_handle,
base::ProcessId proc_id,
const scoped_refptr<base::SequencedTaskRunner>& blocking_pool_runner);
~TaskGroup();
// Adds and removes the given |task| to this group. |task| must be running on
// the same process represented by this group.
void AddTask(Task* task);
void RemoveTask(Task* task);
void Refresh(const content::GPUVideoMemoryUsageStats& gpu_memory_stats,
base::TimeDelta update_interval,
int64_t refresh_flags);
// Appends the sorted IDs of the tasks that belong to this group to
// |out_list|.
void AppendSortedTaskIds(TaskIdList* out_list) const;
Task* GetTaskById(TaskId task_id) const;
const base::ProcessHandle& process_handle() const { return process_handle_; }
const base::ProcessId& process_id() const { return process_id_; }
size_t num_tasks() const { return tasks_.size(); }
bool empty() const { return tasks_.empty(); }
double cpu_usage() const { return cpu_usage_; }
int64_t private_bytes() const { return memory_usage_.private_bytes; }
int64_t shared_bytes() const { return memory_usage_.shared_bytes; }
int64_t physical_bytes() const { return memory_usage_.physical_bytes; }
int64_t gpu_memory() const { return gpu_memory_; }
bool gpu_memory_has_duplicates() const { return gpu_memory_has_duplicates_; }
int64_t per_process_network_usage() const {
return per_process_network_usage_;
}
bool is_backgrounded() const { return is_backgrounded_; }
#if defined(OS_WIN)
int64_t gdi_current_handles() const { return gdi_current_handles_; }
int64_t gdi_peak_handles() const { return gdi_peak_handles_; }
int64_t user_current_handles() const { return user_current_handles_; }
int64_t user_peak_handles() const { return user_peak_handles_; }
#endif // defined(OS_WIN)
#if !defined(DISABLE_NACL)
int nacl_debug_stub_port() const { return nacl_debug_stub_port_; }
#endif // !defined(DISABLE_NACL)
#if defined(OS_LINUX)
int open_fd_count() const { return open_fd_count_; }
#endif // defined(OS_LINUX)
int idle_wakeups_per_second() const { return idle_wakeups_per_second_; }
private:
void RefreshGpuMemory(
const content::GPUVideoMemoryUsageStats& gpu_memory_stats);
void RefreshWindowsHandles();
// |child_process_unique_id| see Task::GetChildProcessUniqueID().
void RefreshNaClDebugStubPort(int child_process_unique_id);
void OnCpuRefreshDone(double cpu_usage);
void OnMemoryUsageRefreshDone(MemoryUsageStats memory_usage);
void OnIdleWakeupsRefreshDone(int idle_wakeups_per_second);
#if defined(OS_LINUX)
void OnOpenFdCountRefreshDone(int open_fd_count);
#endif // defined(OS_LINUX)
void OnProcessPriorityDone(bool is_backgrounded);
// The process' handle and ID.
base::ProcessHandle process_handle_;
base::ProcessId process_id_;
scoped_refptr<TaskGroupSampler> worker_thread_sampler_;
// Maps the Tasks by their IDs.
// Tasks are not owned by the TaskGroup. They're owned by the TaskProviders.
std::map<TaskId, Task*> tasks_;
// The per process resources usages.
double cpu_usage_;
MemoryUsageStats memory_usage_;
int64_t gpu_memory_;
// The network usage in bytes per second as the sum of all network usages of
// the individual tasks sharing the same process.
int64_t per_process_network_usage_;
#if defined(OS_WIN)
// Windows GDI and USER Handles.
int64_t gdi_current_handles_;
int64_t gdi_peak_handles_;
int64_t user_current_handles_;
int64_t user_peak_handles_;
#endif // defined(OS_WIN)
#if !defined(DISABLE_NACL)
int nacl_debug_stub_port_;
#endif // !defined(DISABLE_NACL)
int idle_wakeups_per_second_;
#if defined(OS_LINUX)
// The number of file descriptors currently open by the process.
int open_fd_count_;
#endif // defined(OS_LINUX)
bool gpu_memory_has_duplicates_;
bool is_backgrounded_;
// Always keep this the last member of this class so that it's the first to be
// destroyed.
base::WeakPtrFactory<TaskGroup> weak_ptr_factory_;
DISALLOW_COPY_AND_ASSIGN(TaskGroup);
};
} // namespace task_management
#endif // CHROME_BROWSER_TASK_MANAGEMENT_SAMPLING_TASK_GROUP_H_
|