Skip to content

Commit

Permalink
Merge pull request #2949 from aokblast/feat/bsd_cpufreq
Browse files Browse the repository at this point in the history
feat: implement cpufreq for bsd by sysctl
  • Loading branch information
Alexays authored Feb 22, 2024
2 parents 977c66e + 514d008 commit 793394c
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions src/modules/cpu_frequency/bsd.cpp
Original file line number Diff line number Diff line change
@@ -1,15 +1,28 @@
#include <spdlog/spdlog.h>

#include <cmath> // NAN
#include <sys/sysctl.h>

Check failure on line 3 in src/modules/cpu_frequency/bsd.cpp

View workflow job for this annotation

GitHub Actions / build

src/modules/cpu_frequency/bsd.cpp:3:10 [clang-diagnostic-error]

'sys/sysctl.h' file not found

#include "modules/cpu_frequency.hpp"

std::vector<float> waybar::modules::CpuFrequency::parseCpuFrequencies() {
static std::vector<float> frequencies;
std::vector<float> frequencies;
char buffer[256];

Check warning on line 9 in src/modules/cpu_frequency/bsd.cpp

View workflow job for this annotation

GitHub Actions / build

src/modules/cpu_frequency/bsd.cpp:9:3 [modernize-avoid-c-arrays]

do not declare C-style arrays, use std::array<> instead
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()) {
spdlog::warn(
"cpu/bsd: parseCpuFrequencies is not implemented, expect garbage in {*_frequency}");
spdlog::warn("cpu/bsd: parseCpuFrequencies failed, not found in sysctl");
frequencies.push_back(NAN);
}

return frequencies;
}

0 comments on commit 793394c

Please sign in to comment.