| Index: chrome/browser/chromeos/resource_reporter/resource_reporter.h
|
| diff --git a/chrome/browser/chromeos/resource_reporter/resource_reporter.h b/chrome/browser/chromeos/resource_reporter/resource_reporter.h
|
| index 763740a3fa2d124e4953c47a6f913d3d95d5602d..405a2d799c89fe874ff55a8847b1ab9b06260d3a 100644
|
| --- a/chrome/browser/chromeos/resource_reporter/resource_reporter.h
|
| +++ b/chrome/browser/chromeos/resource_reporter/resource_reporter.h
|
| @@ -8,7 +8,6 @@
|
| #include <stddef.h>
|
| #include <stdint.h>
|
|
|
| -#include <map>
|
| #include <string>
|
| #include <vector>
|
|
|
| @@ -16,9 +15,9 @@
|
| #include "base/macros.h"
|
| #include "base/memory/memory_pressure_listener.h"
|
| #include "base/memory/singleton.h"
|
| -#include "base/time/time.h"
|
| #include "chrome/browser/task_manager/task_manager_observer.h"
|
| #include "components/metrics/metrics_service.h"
|
| +#include "components/prefs/pref_registry_simple.h"
|
| #include "components/rappor/sample.h"
|
|
|
| namespace chromeos {
|
| @@ -66,14 +65,16 @@ class ResourceReporter : public task_manager::TaskManagerObserver {
|
| // The singleton instance.
|
| static ResourceReporter* GetInstance();
|
|
|
| + static void RegisterPrefs(PrefRegistrySimple* registry);
|
| +
|
| // Start / stop observing the task manager and the memory pressure events.
|
| - void StartMonitoring();
|
| + void StartMonitoring(
|
| + task_manager::TaskManagerInterface* task_manager_to_observe);
|
| void StopMonitoring();
|
|
|
| // task_manager::TaskManagerObserver:
|
| - void OnTaskAdded(task_manager::TaskId id) override;
|
| - void OnTaskToBeRemoved(task_manager::TaskId id) override;
|
| - void OnTasksRefreshed(const task_manager::TaskIdList& task_ids) override;
|
| + void OnTasksRefreshedWithBackgroundCalculations(
|
| + const task_manager::TaskIdList& task_ids) override;
|
|
|
| private:
|
| friend struct base::DefaultSingletonTraits<ResourceReporter>;
|
| @@ -129,9 +130,9 @@ class ResourceReporter : public task_manager::TaskManagerObserver {
|
| NUM_RANGES = 7,
|
| };
|
|
|
| - // The maximum number of top consumer tasks of each resource that we're
|
| - // interested in reporting.
|
| - static const size_t kTopConsumersCount;
|
| + // The CPU and memory thresholds beyond which the tasks will be reported.
|
| + static const double kTaskCpuThresholdForReporting;
|
| + static const int64_t kTaskMemoryThresholdForReporting;
|
|
|
| ResourceReporter();
|
|
|
| @@ -154,51 +155,36 @@ class ResourceReporter : public task_manager::TaskManagerObserver {
|
| const TaskRecord* SampleTaskByCpu() const;
|
| const TaskRecord* SampleTaskByMemory() const;
|
|
|
| + // Does the actual recording of Rappor and UMA samples.
|
| + void ReportSamples();
|
| +
|
| // The callback function that will be invoked on memory pressure events.
|
| using MemoryPressureLevel = base::MemoryPressureListener::MemoryPressureLevel;
|
| void OnMemoryPressure(MemoryPressureLevel memory_pressure_level);
|
|
|
| - // We'll use this to watch for memory pressure events so that we can trigger
|
| - // Rappor sampling at at the critical memory pressure level.
|
| + // Monitor memory pressure events.
|
| std::unique_ptr<base::MemoryPressureListener> memory_pressure_listener_;
|
|
|
| - // Contains the collected data about the currently running tasks from the most
|
| - // recent task manager refresh.
|
| - std::map<task_manager::TaskId, std::unique_ptr<TaskRecord>> task_records_;
|
| -
|
| - // Contains the top |kTopConsumerCount| CPU consumer tasks sorted in a
|
| - // descending order by their CPU usage.
|
| - std::vector<TaskRecord*> task_records_by_cpu_;
|
| + // Contains the data about the most CPU and memory intensive tasks collected
|
| + // at a critical memory pressure event.
|
| + std::vector<TaskRecord> task_records_;
|
|
|
| - // Contains the top |kTopConsumerCount| memory consumer tasks sorted in a
|
| - // descending order by their memory usage.
|
| - std::vector<TaskRecord*> task_records_by_memory_;
|
| -
|
| - // The time at which the previous critical memory pressure event was received
|
| - // at which we recorded Rappor samples. This is used to limit generating a
|
| - // Rappor report to once per |kMinimumTimeBetweenReportsInMS|.
|
| - // This is needed to avoid generating a lot of samples that can lower the
|
| - // Rappor privacy guarantees.
|
| - base::TimeTicks last_memory_pressure_event_time_;
|
| + // Either the real task manager implementation, or a test implementation in
|
| + // unit tests.
|
| + task_manager::TaskManagerInterface* task_manager_to_observe_;
|
|
|
| // The range that includes the number of CPU cores in the current system.
|
| const CpuCoresNumberRange system_cpu_cores_range_;
|
|
|
| // The most recent reading for the browser and GPU processes to be reported as
|
| // UMA histograms when the system is under critical memory pressure.
|
| - double last_browser_process_cpu_ = 0.0;
|
| - double last_gpu_process_cpu_ = 0.0;
|
| - int64_t last_browser_process_memory_ = 0;
|
| - int64_t last_gpu_process_memory_ = 0;
|
| + double last_browser_process_cpu_;
|
| + double last_gpu_process_cpu_;
|
| + int64_t last_browser_process_memory_;
|
| + int64_t last_gpu_process_memory_;
|
|
|
| // Tracks whether monitoring started or not.
|
| - bool is_monitoring_ = false;
|
| -
|
| - // True after we've seen a critical memory pressure event.
|
| - bool have_seen_first_memory_pressure_event_ = false;
|
| -
|
| - // True after the first task manager OnTasksRefreshed() event is received.
|
| - bool have_seen_first_task_manager_refresh_ = false;
|
| + bool is_monitoring_;
|
|
|
| DISALLOW_COPY_AND_ASSIGN(ResourceReporter);
|
| };
|
|
|