refactor utils
This commit is contained in:
22
src/cpu.cpp
22
src/cpu.cpp
@@ -11,7 +11,7 @@ void detectHwmon(cpuSensors* target, const std::string& pci) {
|
||||
std::string path = "/sys/bus/pci/devices/" + pci + "/hwmon";
|
||||
|
||||
try {
|
||||
target->hwmon = getFirstDir(path);
|
||||
target->hwmon = utils::getFirstDir(path);
|
||||
} catch (...) {
|
||||
applog(LOG::ERR, "NO CPU HWMON KERNEL MODULE DETECTED");
|
||||
return;
|
||||
@@ -34,15 +34,15 @@ void update(cpuSensors* c) {
|
||||
// read power from intel-rapl? works on amd too, btop uses this trick, seems accurate
|
||||
// it tracks with "socket power" in hwinfo on windows, its actually the same thing i had in lcdsmartie
|
||||
curr.ts = std::chrono::steady_clock::now();
|
||||
// fastReadNum("/sys/class/powercap/intel-rapl:0/energy_uj", curr.energy);
|
||||
curr.energy = fastReadNum("/sys/class/powercap/intel-rapl:0/energy_uj", buf);
|
||||
// utils::fastReadNum("/sys/class/powercap/intel-rapl:0/energy_uj", curr.energy);
|
||||
curr.energy = utils::fastReadNum("/sys/class/powercap/intel-rapl:0/energy_uj", buf);
|
||||
c->ptotal = (float)(curr.energy - prev.energy) / (float)(std::chrono::duration_cast<std::chrono::microseconds>(curr.ts - prev.ts).count());
|
||||
prev = curr;
|
||||
|
||||
// lots of reads but still faster than reading /proc/cpuinfo
|
||||
c->avg_freq = 0;
|
||||
for (uint8_t i = 0; i < N_CPU; i++) {
|
||||
readFile("/sys/devices/system/cpu/cpu" + std::to_string(i) + "/cpufreq/cpuinfo_avg_freq", buf, sizeof(buf));
|
||||
utils::readFile("/sys/devices/system/cpu/cpu" + std::to_string(i) + "/cpufreq/cpuinfo_avg_freq", buf, sizeof(buf));
|
||||
c->avg_freq += strtol(buf, NULL, 10) / 1000;
|
||||
}
|
||||
c->avg_freq /= N_CPU;
|
||||
@@ -51,14 +51,14 @@ void update(cpuSensors* c) {
|
||||
|
||||
// commented out unused values so its faster
|
||||
if (c->zenpower) {
|
||||
c->tdie = fastReadNum(c->hwmon + "/temp1_input", buf) / 1000;
|
||||
c->tctl = fastReadNum(c->hwmon + "/temp2_input", buf) / 1000;
|
||||
c->tccd1 = fastReadNum(c->hwmon + "/temp3_input", buf) / 1000;
|
||||
c->vcore = fastReadNum(c->hwmon + "/in1_input", buf) / 1000.0;
|
||||
c->vsoc = fastReadNum(c->hwmon + "/in2_input", buf) / 1000.0;
|
||||
c->tdie = utils::fastReadNum(c->hwmon + "/temp1_input", buf) / 1000;
|
||||
c->tctl = utils::fastReadNum(c->hwmon + "/temp2_input", buf) / 1000;
|
||||
c->tccd1 = utils::fastReadNum(c->hwmon + "/temp3_input", buf) / 1000;
|
||||
c->vcore = utils::fastReadNum(c->hwmon + "/in1_input", buf) / 1000.0;
|
||||
c->vsoc = utils::fastReadNum(c->hwmon + "/in2_input", buf) / 1000.0;
|
||||
} else {
|
||||
c->tctl = fastReadNum(c->hwmon + "/temp1_input", buf) / 1000;
|
||||
c->tccd1 = fastReadNum(c->hwmon + "/temp3_input", buf) / 1000;
|
||||
c->tctl = utils::fastReadNum(c->hwmon + "/temp1_input", buf) / 1000;
|
||||
c->tccd1 = utils::fastReadNum(c->hwmon + "/temp3_input", buf) / 1000;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user