#include "chrome/browser/performance_monitor/system_monitor.h"
#include <algorithm>
#include <utility>
#include "base/feature_list.h"
#include "base/memory/ptr_util.h"
#include "base/not_fatal_until.h"
#include "base/notreached.h"
#include "base/observer_list.h"
#include "base/task/thread_pool.h"
#include "build/build_config.h"
#if BUILDFLAG(IS_WIN)
#include "chrome/browser/performance_monitor/metric_evaluator_helper_win.h"
#elif BUILDFLAG(IS_POSIX)
#include "chrome/browser/performance_monitor/metric_evaluator_helper_posix.h"
#endif
namespace performance_monitor {
namespace {
MetricRefreshFrequencies;
SystemMonitor* g_system_metrics_monitor = …;
constexpr base::TimeDelta kDefaultRefreshInterval = …;
}
SystemMonitor::SystemMonitor(
std::unique_ptr<MetricEvaluatorsHelper> metric_evaluators_helper)
: … { … }
SystemMonitor::~SystemMonitor() { … }
std::unique_ptr<SystemMonitor> SystemMonitor::Create() { … }
std::unique_ptr<SystemMonitor> SystemMonitor::CreateForTesting(
std::unique_ptr<MetricEvaluatorsHelper> helper) { … }
SystemMonitor* SystemMonitor::Get() { … }
MetricRefreshFrequencies::Builder&
MetricRefreshFrequencies::Builder::SetFreePhysMemoryMbFrequency(
SamplingFrequency freq) { … }
MetricRefreshFrequencies::Builder&
MetricRefreshFrequencies::Builder::SetSystemMetricsSamplingFrequency(
SamplingFrequency freq) { … }
MetricRefreshFrequencies MetricRefreshFrequencies::Builder::Build() { … }
SystemMonitor::SystemObserver::~SystemObserver() { … }
void SystemMonitor::SystemObserver::OnFreePhysicalMemoryMbSample(
int free_phys_memory_mb) { … }
void SystemMonitor::SystemObserver::OnSystemMetricsStruct(
const base::SystemMetrics& system_metrics) { … }
void SystemMonitor::AddOrUpdateObserver(
SystemMonitor::SystemObserver* observer,
MetricRefreshFrequencies metrics_and_frequencies) { … }
void SystemMonitor::RemoveObserver(SystemMonitor::SystemObserver* observer) { … }
SystemMonitor::MetricVector SystemMonitor::GetMetricsToEvaluate() const { … }
SystemMonitor::MetricVector SystemMonitor::EvaluateMetrics(
SystemMonitor::MetricVector metrics_to_evaluate) { … }
SystemMonitor::MetricMetadataArray SystemMonitor::CreateMetricMetadataArray() { … }
void SystemMonitor::UpdateObservedMetrics() { … }
void SystemMonitor::RefreshCallback() { … }
void SystemMonitor::NotifyObservers(SystemMonitor::MetricVector metrics) { … }
std::unique_ptr<MetricEvaluatorsHelper>
SystemMonitor::CreateMetricEvaluatorsHelper() { … }
SystemMonitor::MetricEvaluator::MetricEvaluator(Type type) : … { … }
SystemMonitor::MetricEvaluator::~MetricEvaluator() = default;
template <typename T>
SystemMonitor::MetricEvaluatorImpl<T>::MetricEvaluatorImpl(
Type type,
base::OnceCallback<std::optional<T>()> evaluate_function,
void (SystemObserver::*notify_function)(ObserverArgType))
: … { … }
template <typename T>
SystemMonitor::MetricEvaluatorImpl<T>::~MetricEvaluatorImpl() = default;
SystemMonitor::MetricMetadata::MetricMetadata(
std::unique_ptr<MetricEvaluator> (*create_function)(
MetricEvaluatorsHelper* helper),
SamplingFrequency (*get_refresh_field_function)(
const SystemMonitor::SystemObserver::MetricRefreshFrequencies&))
: … { … }
template <typename T>
void SystemMonitor::MetricEvaluatorImpl<T>::NotifyObserver(
SystemObserver* observer) { … }
template <typename T>
void SystemMonitor::MetricEvaluatorImpl<T>::Evaluate() { … }
std::optional<base::SystemMetrics>
MetricEvaluatorsHelper::GetSystemMetricsStruct() { … }
}