use std::array instead of c-style bufs

This commit is contained in:
2026-01-02 13:44:01 +01:00
parent 27350122b2
commit 0eb401cdcc
3 changed files with 21 additions and 18 deletions

View File

@@ -1,3 +1,4 @@
#include <array>
#include <chrono>
#include <cpu.hpp>
#include <cstdint>
@@ -22,7 +23,7 @@ void detectHwmon(cpuSensors* target, const std::string& pci) {
}
void update(cpuSensors* c) {
static char buf[32];
static std::array<char, 32> buf;
struct EnergyTs {
uint64_t energy = 0;
std::chrono::time_point<std::chrono::steady_clock> ts;
@@ -41,8 +42,9 @@ void update(cpuSensors* c) {
// lots of reads but still faster than reading /proc/cpuinfo
c->avg_freq = 0;
for (uint8_t i = 0; i < N_CPU; i++) {
utils::readFile("/sys/devices/system/cpu/cpu" + std::to_string(i) + "/cpufreq/cpuinfo_avg_freq", buf, sizeof(buf));
c->avg_freq += strtol(buf, nullptr, 10) / 1000;
uint32_t t = 0;
utils::fastReadNum<1000>("/sys/devices/system/cpu/cpu" + std::to_string(i) + "/cpufreq/cpuinfo_avg_freq", buf, t);
c->avg_freq += t;
}
c->avg_freq /= N_CPU;