#ifdef UNSAFE_BUFFERS_BUILD
#pragma allow_unsafe_buffers
#endif
#include "components/power_metrics/energy_metrics_provider_linux.h"
#include <linux/perf_event.h>
#include <sys/syscall.h>
#include <array>
#include "base/containers/span.h"
#include "base/files/file_path.h"
#include "base/files/file_util.h"
#include "base/files/scoped_file.h"
#include "base/logging.h"
#include "base/memory/ptr_util.h"
#include "base/strings/strcat.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/string_util.h"
namespace power_metrics {
namespace {
constexpr const char* kPowerEventPath = …;
constexpr std::array<const char*, 5> kMetrics{ … };
bool ReadUint64FromFile(base::FilePath path, uint64_t* output) { … }
bool ReadHexFromFile(base::FilePath path, uint64_t* output) { … }
bool ReadDoubleFromFile(base::FilePath path, double* output) { … }
base::ScopedFD OpenPerfEvent(perf_event_attr* perf_attr) { … }
void SetEnergyMetric(const std::string& metric_type,
EnergyMetricsProvider::EnergyMetrics& energy_metrics,
uint64_t absolute_energy) { … }
}
EnergyMetricsProviderLinux::PowerEvent::PowerEvent(std::string metric_type,
double scale,
base::ScopedFD fd)
: … { … }
EnergyMetricsProviderLinux::PowerEvent::~PowerEvent() = default;
EnergyMetricsProviderLinux::PowerEvent::PowerEvent(PowerEvent&& other) =
default;
EnergyMetricsProviderLinux::PowerEvent&
EnergyMetricsProviderLinux::PowerEvent::operator=(PowerEvent&& other) = default;
EnergyMetricsProviderLinux::EnergyMetricsProviderLinux() = default;
EnergyMetricsProviderLinux::~EnergyMetricsProviderLinux() = default;
std::unique_ptr<EnergyMetricsProviderLinux>
EnergyMetricsProviderLinux::Create() { … }
std::optional<EnergyMetricsProvider::EnergyMetrics>
EnergyMetricsProviderLinux::CaptureMetrics() { … }
bool EnergyMetricsProviderLinux::Initialize() { … }
}