Merge pull request #2949 from aokblast/feat/bsd_cpufreq

feat: implement cpufreq for bsd by sysctl
pull/2958/head
Alexis Rouillard 2024-02-22 01:25:21 +01:00 committed by GitHub
commit 793394c862
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 17 additions and 4 deletions

View File

@ -1,15 +1,28 @@
#include <spdlog/spdlog.h> #include <spdlog/spdlog.h>
#include <cmath> // NAN #include <sys/sysctl.h>
#include "modules/cpu_frequency.hpp" #include "modules/cpu_frequency.hpp"
std::vector<float> waybar::modules::CpuFrequency::parseCpuFrequencies() { std::vector<float> waybar::modules::CpuFrequency::parseCpuFrequencies() {
static std::vector<float> frequencies; std::vector<float> frequencies;
char buffer[256];
size_t len;
int32_t freq;
uint32_t i = 0;
while (true) {
len = 4;
snprintf(buffer, 256, "dev.cpu.%u.freq", i);
if (sysctlbyname(buffer, &freq, &len, NULL, 0) == -1 || len <= 0) break;
frequencies.push_back(freq);
++i;
}
if (frequencies.empty()) { if (frequencies.empty()) {
spdlog::warn( spdlog::warn("cpu/bsd: parseCpuFrequencies failed, not found in sysctl");
"cpu/bsd: parseCpuFrequencies is not implemented, expect garbage in {*_frequency}");
frequencies.push_back(NAN); frequencies.push_back(NAN);
} }
return frequencies; return frequencies;
} }