mirror of
https://github.com/rad4day/Waybar.git
synced 2025-07-13 14:42:29 +02:00
feat: implement cpufreq for bsd by sysctl
This commit is contained in:
@ -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;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user