-
-
Notifications
You must be signed in to change notification settings - Fork 728
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2949 from aokblast/feat/bsd_cpufreq
feat: implement cpufreq for bsd by sysctl
- Loading branch information
Showing
1 changed file
with
17 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> | ||
|
||
#include "modules/cpu_frequency.hpp" | ||
|
||
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()) { | ||
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; | ||
} |