#include "chrome/browser/performance_manager/metrics/page_resource_monitor.h"
#include <stdint.h>
#include <optional>
#include <utility>
#include "base/functional/bind.h"
#include "base/functional/callback.h"
#include "base/scoped_observation.h"
#include "components/performance_manager/public/graph/page_node.h"
#include "components/performance_manager/public/resource_attribution/cpu_proportion_tracker.h"
#include "components/performance_manager/public/resource_attribution/resource_types.h"
#include "components/system_cpu/cpu_probe.h"
#include "services/metrics/public/cpp/ukm_builders.h"
#include "services/metrics/public/cpp/ukm_recorder.h"
#include "services/metrics/public/cpp/ukm_source_id.h"
namespace performance_manager::metrics {
namespace {
CpuProbe;
CpuSample;
PageMeasurementBackgroundState;
PageContext;
QueryResultMap;
ResourceContext;
ResourceType;
constexpr int kCPUUsageFactor = …;
constexpr base::TimeDelta kCollectionDelay = …;
PageMeasurementBackgroundState GetBackgroundStateForMeasurementPeriod(
const PageNode* page_node,
base::TimeDelta time_since_last_measurement) { … }
resource_attribution::QueryBuilder CPUQueryBuilder() { … }
const PageNode* PageNodeFromContext(const ResourceContext& context) { … }
bool ContextIsTab(const ResourceContext& context) { … }
}
class PageResourceMonitor::CPUResultConverter { … };
PageResourceMonitor::PageResourceMonitor(bool enable_system_cpu_probe)
: … { … }
PageResourceMonitor::~PageResourceMonitor() = default;
void PageResourceMonitor::OnResourceUsageUpdated(
const QueryResultMap& results) { … }
base::TimeDelta PageResourceMonitor::GetCollectionDelayForTesting() const { … }
void PageResourceMonitor::OnPageResourceUsageResult(
const QueryResultMap& results,
const PageCPUUsageMap& page_cpu_usage,
std::optional<CpuSample> system_cpu) { … }
PageResourceMonitor::CPUResultConverter::CPUResultConverter(
std::unique_ptr<CpuProbe> system_cpu_probe)
: … { … }
base::WeakPtr<PageResourceMonitor::CPUResultConverter>
PageResourceMonitor::CPUResultConverter::GetWeakPtr() { … }
bool PageResourceMonitor::CPUResultConverter::HasSystemCPUProbe() const { … }
void PageResourceMonitor::CPUResultConverter::OnResourceUsageUpdated(
CPUResultConverter::ResultCallback result_callback,
const QueryResultMap& results) { … }
void PageResourceMonitor::CPUResultConverter::StartFirstInterval(
base::TimeTicks time,
const QueryResultMap& results) { … }
void PageResourceMonitor::CPUResultConverter::StartNextInterval(
CPUResultConverter::ResultCallback result_callback,
base::TimeTicks time,
const QueryResultMap& results,
std::optional<CpuSample> system_cpu) { … }
}