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 #ifndef CHROME_BROWSER_CHROMEOS_RESOURCE_REPORTER_RESOURCE_REPORTER_H_ | 5 #ifndef CHROME_BROWSER_CHROMEOS_RESOURCE_REPORTER_RESOURCE_REPORTER_H_ |
6 #define CHROME_BROWSER_CHROMEOS_RESOURCE_REPORTER_RESOURCE_REPORTER_H_ | 6 #define CHROME_BROWSER_CHROMEOS_RESOURCE_REPORTER_RESOURCE_REPORTER_H_ |
7 | 7 |
8 #include <stddef.h> | 8 #include <stddef.h> |
9 #include <stdint.h> | 9 #include <stdint.h> |
10 | 10 |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
129 NUM_RANGES = 7, | 129 NUM_RANGES = 7, |
130 }; | 130 }; |
131 | 131 |
132 // The maximum number of top consumer tasks of each resource that we're | 132 // The maximum number of top consumer tasks of each resource that we're |
133 // interested in reporting. | 133 // interested in reporting. |
134 static const size_t kTopConsumersCount; | 134 static const size_t kTopConsumersCount; |
135 | 135 |
136 ResourceReporter(); | 136 ResourceReporter(); |
137 | 137 |
138 // Creates a Rappor sample for the given |task_record|. | 138 // Creates a Rappor sample for the given |task_record|. |
139 static scoped_ptr<rappor::Sample> CreateRapporSample( | 139 static std::unique_ptr<rappor::Sample> CreateRapporSample( |
140 rappor::RapporService* rappor_service, | 140 rappor::RapporService* rappor_service, |
141 const TaskRecord& task_record); | 141 const TaskRecord& task_record); |
142 | 142 |
143 // Gets the CPU/memory usage ranges given the |cpu| / |memory_in_bytes| | 143 // Gets the CPU/memory usage ranges given the |cpu| / |memory_in_bytes| |
144 // values. | 144 // values. |
145 static CpuUsageRange GetCpuUsageRange(double cpu); | 145 static CpuUsageRange GetCpuUsageRange(double cpu); |
146 static MemoryUsageRange GetMemoryUsageRange(int64_t memory_in_bytes); | 146 static MemoryUsageRange GetMemoryUsageRange(int64_t memory_in_bytes); |
147 | 147 |
148 // Gets the bucket in which the current system's number of CPU cores fall. | 148 // Gets the bucket in which the current system's number of CPU cores fall. |
149 static CpuCoresNumberRange GetCurrentSystemCpuCoresRange(); | 149 static CpuCoresNumberRange GetCurrentSystemCpuCoresRange(); |
150 | 150 |
151 // Perform a weighted random sampling to select a task by its CPU or memory | 151 // Perform a weighted random sampling to select a task by its CPU or memory |
152 // usage weights so that we can record samples for them via Rappor. | 152 // usage weights so that we can record samples for them via Rappor. |
153 // They return nullptr if no TaskRecord has been selected. | 153 // They return nullptr if no TaskRecord has been selected. |
154 const TaskRecord* SampleTaskByCpu() const; | 154 const TaskRecord* SampleTaskByCpu() const; |
155 const TaskRecord* SampleTaskByMemory() const; | 155 const TaskRecord* SampleTaskByMemory() const; |
156 | 156 |
157 // The callback function that will be invoked on memory pressure events. | 157 // The callback function that will be invoked on memory pressure events. |
158 using MemoryPressureLevel = base::MemoryPressureListener::MemoryPressureLevel; | 158 using MemoryPressureLevel = base::MemoryPressureListener::MemoryPressureLevel; |
159 void OnMemoryPressure(MemoryPressureLevel memory_pressure_level); | 159 void OnMemoryPressure(MemoryPressureLevel memory_pressure_level); |
160 | 160 |
161 // We'll use this to watch for memory pressure events so that we can trigger | 161 // We'll use this to watch for memory pressure events so that we can trigger |
162 // Rappor sampling at at the critical memory pressure level. | 162 // Rappor sampling at at the critical memory pressure level. |
163 scoped_ptr<base::MemoryPressureListener> memory_pressure_listener_; | 163 std::unique_ptr<base::MemoryPressureListener> memory_pressure_listener_; |
164 | 164 |
165 // Contains the collected data about the currently running tasks from the most | 165 // Contains the collected data about the currently running tasks from the most |
166 // recent task manager refresh. | 166 // recent task manager refresh. |
167 std::map<task_management::TaskId, scoped_ptr<TaskRecord>> task_records_; | 167 std::map<task_management::TaskId, std::unique_ptr<TaskRecord>> task_records_; |
168 | 168 |
169 // Contains the top |kTopConsumerCount| CPU consumer tasks sorted in a | 169 // Contains the top |kTopConsumerCount| CPU consumer tasks sorted in a |
170 // descending order by their CPU usage. | 170 // descending order by their CPU usage. |
171 std::vector<TaskRecord*> task_records_by_cpu_; | 171 std::vector<TaskRecord*> task_records_by_cpu_; |
172 | 172 |
173 // Contains the top |kTopConsumerCount| memory consumer tasks sorted in a | 173 // Contains the top |kTopConsumerCount| memory consumer tasks sorted in a |
174 // descending order by their memory usage. | 174 // descending order by their memory usage. |
175 std::vector<TaskRecord*> task_records_by_memory_; | 175 std::vector<TaskRecord*> task_records_by_memory_; |
176 | 176 |
177 // The time at which the previous critical memory pressure event was received | 177 // The time at which the previous critical memory pressure event was received |
(...skipping 21 matching lines...) Expand all Loading... |
199 | 199 |
200 // True after the first task manager OnTasksRefreshed() event is received. | 200 // True after the first task manager OnTasksRefreshed() event is received. |
201 bool have_seen_first_task_manager_refresh_ = false; | 201 bool have_seen_first_task_manager_refresh_ = false; |
202 | 202 |
203 DISALLOW_COPY_AND_ASSIGN(ResourceReporter); | 203 DISALLOW_COPY_AND_ASSIGN(ResourceReporter); |
204 }; | 204 }; |
205 | 205 |
206 } // namespace chromeos | 206 } // namespace chromeos |
207 | 207 |
208 #endif // CHROME_BROWSER_CHROMEOS_RESOURCE_REPORTER_RESOURCE_REPORTER_H_ | 208 #endif // CHROME_BROWSER_CHROMEOS_RESOURCE_REPORTER_RESOURCE_REPORTER_H_ |
OLD | NEW |