This commit is contained in:
Drath
2025-10-23 13:04:01 +02:00
3 changed files with 14 additions and 4 deletions

View File

@@ -17,6 +17,8 @@ void detectHwmon(cpuSensors* target, std::string pci) {
}
void update(cpuSensors* c) {
static std::chrono::time_point<std::chrono::steady_clock> previous_ts;
static uint64_t previous_usage = 0;
// commented out unused values so its faster
if (c->hwmon == "") return; // break if no module
if (c->zenpower) {
@@ -31,6 +33,12 @@ void update(cpuSensors* c) {
} else {
c->tctl = std::stoi(readFile(c->hwmon + "/temp1_input", 2));
c->tccd1 = std::stoi(readFile(c->hwmon + "/temp3_input", 2));
// read power from intel-rapl? works on amd too, btop uses this trick, seems accurate
auto current_ts = std::chrono::steady_clock::now();
auto current_usage = std::stoul(readFile("/sys/class/powercap/intel-rapl:0/energy_uj", 24));
c->ptotal = (float)(current_usage - previous_usage) / (float)(std::chrono::duration_cast<std::chrono::microseconds>(current_ts - previous_ts).count());
previous_ts = current_ts;
previous_usage = current_usage;
}
// lots of reads but still faster than reading /proc/cpuinfo
@@ -42,4 +50,4 @@ void update(cpuSensors* c) {
c->avg_freq /= N_CPU;
}
} // namespace cpu
} // namespace cpu