chromium/components/power_metrics/energy_metrics_provider_linux.cc

// Copyright 2023 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifdef UNSAFE_BUFFERS_BUILD
// TODO(crbug.com/40285824): Remove this and convert code to safer constructs.
#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 =;

// Existing metrics that can be read via perf event.
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) {}

// When pid == -1 and cpu >= 0, perf event measures all processes/threads on the
// specified CPU. This requires admin or a /proc/sys/kernel/perf_event_paranoid
// value of less than 1. Here, we only consider cpu0. See details in
// https://man7.org/linux/man-pages/man2/perf_event_open.2.html.
base::ScopedFD OpenPerfEvent(perf_event_attr* perf_attr) {}

void SetEnergyMetric(const std::string& metric_type,
                     EnergyMetricsProvider::EnergyMetrics& energy_metrics,
                     uint64_t absolute_energy) {}

}  // namespace

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;

// static
std::unique_ptr<EnergyMetricsProviderLinux>
EnergyMetricsProviderLinux::Create() {}

std::optional<EnergyMetricsProvider::EnergyMetrics>
EnergyMetricsProviderLinux::CaptureMetrics() {}

bool EnergyMetricsProviderLinux::Initialize() {}

}  // namespace power_metrics