#include "chrome/browser/metrics/power/power_metrics_reporter.h"
#include <optional>
#include <vector>
#include "base/functional/bind.h"
#include "base/metrics/histogram_functions.h"
#include "base/strings/strcat.h"
#include "base/strings/string_util.h"
#include "base/time/time.h"
#include "base/trace_event/named_trigger.h"
#include "base/trace_event/trace_event.h"
#include "build/build_config.h"
#include "chrome/browser/lifetime/browser_shutdown.h"
#include "chrome/browser/metrics/power/power_metrics.h"
#include "chrome/browser/metrics/power/power_metrics_constants.h"
#include "chrome/browser/metrics/power/process_metrics_recorder_util.h"
#include "chrome/browser/metrics/power/process_monitor.h"
#include "chrome/browser/metrics/usage_scenario/usage_scenario_data_store.h"
#include "services/metrics/public/cpp/metrics_utils.h"
#include "services/metrics/public/cpp/ukm_builders.h"
#include "services/metrics/public/cpp/ukm_source_id.h"
namespace {
int64_t GetBucketForSample(base::TimeDelta value) { … }
const char* GetMetricSuffixFromProcessType(MonitoredProcessType type) { … }
}
PowerMetricsReporter::PowerMetricsReporter(
ProcessMonitor* process_monitor,
UsageScenarioDataStore* long_usage_scenario_data_store,
std::unique_ptr<base::BatteryLevelProvider> battery_level_provider)
: … { … }
PowerMetricsReporter::~PowerMetricsReporter() = default;
int64_t PowerMetricsReporter::GetBucketForSampleForTesting(
base::TimeDelta value) { … }
void PowerMetricsReporter::OnFirstBatteryStateSampled(
const std::optional<base::BatteryLevelProvider::BatteryState>&
battery_state) { … }
void PowerMetricsReporter::StartNextLongInterval() { … }
void PowerMetricsReporter::OnLongIntervalEnd() { … }
void PowerMetricsReporter::OnMetricsSampled(
MonitoredProcessType type,
const ProcessMonitor::Metrics& metrics) { … }
void PowerMetricsReporter::OnAggregatedMetricsSampled(
const ProcessMonitor::Metrics& metrics) { … }
void PowerMetricsReporter::OnBatteryAndAggregatedProcessMetricsSampled(
const ProcessMonitor::Metrics& aggregated_process_metrics,
base::TimeDelta interval_duration,
const std::optional<base::BatteryLevelProvider::BatteryState>&
new_battery_state) { … }
void PowerMetricsReporter::ReportMetrics(
const UsageScenarioDataStore::IntervalData& long_interval_data,
base::TimeDelta interval_duration,
const ProcessMonitor::Metrics& aggregated_process_metrics) { … }
void PowerMetricsReporter::ReportBatterySpecificMetrics(
const UsageScenarioDataStore::IntervalData& long_interval_data,
base::TimeDelta interval_duration,
const ProcessMonitor::Metrics& aggregated_process_metrics,
BatteryDischarge battery_discharge) { … }
void PowerMetricsReporter::ReportBatteryUKMs(
const UsageScenarioDataStore::IntervalData& interval_data,
const ProcessMonitor::Metrics& metrics,
base::TimeDelta interval_duration,
BatteryDischarge battery_discharge) { … }