cpu: make getCpuLoad more portable
../include/modules/cpu.hpp:4:10: fatal error: 'sys/sysinfo.h' file not found #include <sys/sysinfo.h> ^~~~~~~~~~~~~~~pull/425/head
parent
c94ef092ff
commit
d5df185ac6
|
@ -1,7 +1,7 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <fmt/format.h>
|
#include <fmt/format.h>
|
||||||
#include <sys/sysinfo.h>
|
#include <unistd.h>
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <numeric>
|
#include <numeric>
|
||||||
|
|
|
@ -23,11 +23,9 @@ auto waybar::modules::Cpu::update() -> void {
|
||||||
}
|
}
|
||||||
|
|
||||||
uint16_t waybar::modules::Cpu::getCpuLoad() {
|
uint16_t waybar::modules::Cpu::getCpuLoad() {
|
||||||
struct sysinfo info = {0};
|
double load[1];
|
||||||
if (sysinfo(&info) == 0) {
|
if (getloadavg(load, 1) != -1) {
|
||||||
float f_load = 1.F / (1U << SI_LOAD_SHIFT);
|
return load[0] * 100 / sysconf(_SC_NPROCESSORS_ONLN);
|
||||||
uint16_t load = info.loads[0] * f_load * 100 / get_nprocs();
|
|
||||||
return load;
|
|
||||||
}
|
}
|
||||||
throw std::runtime_error("Can't get Cpu load");
|
throw std::runtime_error("Can't get Cpu load");
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue