Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(6)

Side by Side Diff: chrome/browser/chromeos/resource_reporter/resource_reporter.h

Issue 2388933003: Make ResourceReporter a client of memory coordinator (Closed)
Patch Set: Address on afakhry's review Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | chrome/browser/chromeos/resource_reporter/resource_reporter.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
11 #include <string> 11 #include <string>
12 #include <vector> 12 #include <vector>
13 13
14 #include "base/gtest_prod_util.h" 14 #include "base/gtest_prod_util.h"
15 #include "base/macros.h" 15 #include "base/macros.h"
16 #include "base/memory/memory_coordinator_client.h"
16 #include "base/memory/memory_pressure_listener.h" 17 #include "base/memory/memory_pressure_listener.h"
17 #include "base/memory/singleton.h" 18 #include "base/memory/singleton.h"
18 #include "chrome/browser/task_manager/task_manager_observer.h" 19 #include "chrome/browser/task_manager/task_manager_observer.h"
19 #include "components/metrics/metrics_service.h" 20 #include "components/metrics/metrics_service.h"
20 #include "components/prefs/pref_registry_simple.h" 21 #include "components/prefs/pref_registry_simple.h"
21 #include "components/rappor/sample.h" 22 #include "components/rappor/sample.h"
22 23
23 namespace chromeos { 24 namespace chromeos {
24 25
25 // A system that tracks the top |kTopConsumersCount| CPU and memory consumer 26 // A system that tracks the top |kTopConsumersCount| CPU and memory consumer
26 // Chrome tasks and reports a weighted random sample of them via Rappor whenever 27 // Chrome tasks and reports a weighted random sample of them via Rappor whenever
27 // memory pressure is critical. The reporting is limited to once per 28 // memory pressure is critical. The reporting is limited to once per
28 // |kMinimumTimeBetweenReportsInMS|. 29 // |kMinimumTimeBetweenReportsInMS|.
29 class ResourceReporter : public task_manager::TaskManagerObserver { 30 class ResourceReporter : public task_manager::TaskManagerObserver,
31 public base::MemoryCoordinatorClient {
30 public: 32 public:
31 // A collection of the data of a task manager's task that the ResourceReporter 33 // A collection of the data of a task manager's task that the ResourceReporter
32 // is interested in. 34 // is interested in.
33 struct TaskRecord { 35 struct TaskRecord {
34 explicit TaskRecord(task_manager::TaskId task_id); 36 explicit TaskRecord(task_manager::TaskId task_id);
35 37
36 TaskRecord(task_manager::TaskId task_id, 38 TaskRecord(task_manager::TaskId task_id,
37 const std::string& task_name, 39 const std::string& task_name,
38 double cpu_percent, 40 double cpu_percent,
39 int64_t memory_bytes, 41 int64_t memory_bytes,
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
142 const TaskRecord& task_record); 144 const TaskRecord& task_record);
143 145
144 // Gets the CPU/memory usage ranges given the |cpu| / |memory_in_bytes| 146 // Gets the CPU/memory usage ranges given the |cpu| / |memory_in_bytes|
145 // values. 147 // values.
146 static CpuUsageRange GetCpuUsageRange(double cpu); 148 static CpuUsageRange GetCpuUsageRange(double cpu);
147 static MemoryUsageRange GetMemoryUsageRange(int64_t memory_in_bytes); 149 static MemoryUsageRange GetMemoryUsageRange(int64_t memory_in_bytes);
148 150
149 // Gets the bucket in which the current system's number of CPU cores fall. 151 // Gets the bucket in which the current system's number of CPU cores fall.
150 static CpuCoresNumberRange GetCurrentSystemCpuCoresRange(); 152 static CpuCoresNumberRange GetCurrentSystemCpuCoresRange();
151 153
154 // base::MemoryCoordinatorClient:
155 void OnMemoryStateChange(base::MemoryState state) override;
156
152 // Perform a weighted random sampling to select a task by its CPU or memory 157 // Perform a weighted random sampling to select a task by its CPU or memory
153 // usage weights so that we can record samples for them via Rappor. 158 // usage weights so that we can record samples for them via Rappor.
154 // They return nullptr if no TaskRecord has been selected. 159 // They return nullptr if no TaskRecord has been selected.
155 const TaskRecord* SampleTaskByCpu() const; 160 const TaskRecord* SampleTaskByCpu() const;
156 const TaskRecord* SampleTaskByMemory() const; 161 const TaskRecord* SampleTaskByMemory() const;
157 162
158 // Does the actual recording of Rappor and UMA samples. 163 // Does the actual recording of Rappor and UMA samples.
159 void ReportSamples(); 164 void ReportSamples();
160 165
161 // The callback function that will be invoked on memory pressure events. 166 // The callback function that will be invoked on memory pressure events.
162 using MemoryPressureLevel = base::MemoryPressureListener::MemoryPressureLevel; 167 using MemoryPressureLevel = base::MemoryPressureListener::MemoryPressureLevel;
163 void OnMemoryPressure(MemoryPressureLevel memory_pressure_level); 168 void OnMemoryPressure(MemoryPressureLevel memory_pressure_level);
164 169
170 void StartRecordingCurrentState();
171 void StopRecordingCurrentState();
172
165 // Monitor memory pressure events. 173 // Monitor memory pressure events.
166 std::unique_ptr<base::MemoryPressureListener> memory_pressure_listener_; 174 std::unique_ptr<base::MemoryPressureListener> memory_pressure_listener_;
167 175
168 // Contains the data about the most CPU and memory intensive tasks collected 176 // Contains the data about the most CPU and memory intensive tasks collected
169 // at a critical memory pressure event. 177 // at a critical memory pressure event.
170 std::vector<TaskRecord> task_records_; 178 std::vector<TaskRecord> task_records_;
171 179
172 // Either the real task manager implementation, or a test implementation in 180 // Either the real task manager implementation, or a test implementation in
173 // unit tests. 181 // unit tests.
174 task_manager::TaskManagerInterface* task_manager_to_observe_; 182 task_manager::TaskManagerInterface* task_manager_to_observe_;
(...skipping 10 matching lines...) Expand all
185 193
186 // Tracks whether monitoring started or not. 194 // Tracks whether monitoring started or not.
187 bool is_monitoring_; 195 bool is_monitoring_;
188 196
189 DISALLOW_COPY_AND_ASSIGN(ResourceReporter); 197 DISALLOW_COPY_AND_ASSIGN(ResourceReporter);
190 }; 198 };
191 199
192 } // namespace chromeos 200 } // namespace chromeos
193 201
194 #endif // CHROME_BROWSER_CHROMEOS_RESOURCE_REPORTER_RESOURCE_REPORTER_H_ 202 #endif // CHROME_BROWSER_CHROMEOS_RESOURCE_REPORTER_RESOURCE_REPORTER_H_
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/chromeos/resource_reporter/resource_reporter.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698