get rid of macro, use inline func
This commit is contained in:
24
src/cpu.cpp
24
src/cpu.cpp
@@ -17,13 +17,16 @@ void detectHwmon(cpuSensors* target, const std::string& pci) {
|
||||
return;
|
||||
}
|
||||
|
||||
target->zenpower = false; // we were using readFileToStr to figure this out, we dont f/w it anymore, find another way (see if hwmon/in1_input exists?)
|
||||
target->zenpower = false; // we were using readFileToStr to figure this out, we dont f/w it anymore, find another way (see if hwmon/in1_input exists?)
|
||||
applog(LOG::INF, "Detected module \"{}\" in path \"{}\"", target->zenpower ? "zenpower" : "k10temp", target->hwmon);
|
||||
}
|
||||
|
||||
void update(cpuSensors* c) {
|
||||
static char buf[32];
|
||||
struct EnergyTs { uint64_t energy = 0; std::chrono::time_point<std::chrono::steady_clock> ts; };
|
||||
struct EnergyTs {
|
||||
uint64_t energy = 0;
|
||||
std::chrono::time_point<std::chrono::steady_clock> ts;
|
||||
};
|
||||
|
||||
static EnergyTs prev;
|
||||
EnergyTs curr;
|
||||
@@ -31,7 +34,8 @@ 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);
|
||||
// fastReadNum("/sys/class/powercap/intel-rapl:0/energy_uj", curr.energy);
|
||||
curr.energy = 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;
|
||||
|
||||
@@ -47,14 +51,14 @@ void update(cpuSensors* c) {
|
||||
|
||||
// commented out unused values so its faster
|
||||
if (c->zenpower) {
|
||||
fastReadNum(c->hwmon + "/temp1_input", c->tdie) / 1000;
|
||||
fastReadNum(c->hwmon + "/temp2_input", c->tctl) / 1000;
|
||||
fastReadNum(c->hwmon + "/temp3_input", c->tccd1) / 1000;
|
||||
fastReadNum(c->hwmon + "/in1_input", c->vcore) / 1000.0;
|
||||
fastReadNum(c->hwmon + "/in2_input", c->vsoc) / 1000.0;
|
||||
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;
|
||||
} else {
|
||||
fastReadNum(c->hwmon + "/temp1_input", c->tctl) / 1000;
|
||||
fastReadNum(c->hwmon + "/temp3_input", c->tccd1) / 1000;
|
||||
c->tctl = fastReadNum(c->hwmon + "/temp1_input", buf) / 1000;
|
||||
c->tccd1 = fastReadNum(c->hwmon + "/temp3_input", buf) / 1000;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
18
src/gpu.cpp
18
src/gpu.cpp
@@ -24,23 +24,23 @@ void detectHwmon(gpuSensors* target, const std::string& pci) {
|
||||
/* some metrics are missing in gpu_metrics, we always fill them from fs, unused metrics are commented out */
|
||||
void fillMissingMetrics(gpuSensors* g) {
|
||||
static char buf[32];
|
||||
fastReadNum(g->hwmon + "/in0_input", g->vcore) / 1000.0;
|
||||
g->vcore = fastReadNum(g->hwmon + "/in0_input", buf) / 1000.0;
|
||||
// g->fan_pwm = std::stoi(readFile(g->hwmon + "/pwm1", 4)) * 100 / 256;
|
||||
fastReadNum(g->hwmon + "/fan1_input", g->fan_speed);
|
||||
fastReadNum(g->hwmon + "/power1_cap", g->power_cap) / 1000000;
|
||||
g->fan_speed = fastReadNum(g->hwmon + "/fan1_input", buf);
|
||||
g->power_cap = fastReadNum(g->hwmon + "/power1_cap", buf) / 1000000;
|
||||
// fastReadNum(g->hwmon + "/power1_cap_max", g->power_cap_max) / 1000000;
|
||||
fastReadNum(g->hwmon + "/../../mem_info_vram_used", g->vram_used);
|
||||
g->vram_used = fastReadNum(g->hwmon + "/../../mem_info_vram_used", buf);
|
||||
// fastReadNum(g->hwmon + "/../../mem_info_vram_total", g->vram_total);
|
||||
}
|
||||
|
||||
/* get sensors for pre-vega cards (rx480/580) */
|
||||
void updateFromFs(gpuSensors* g) {
|
||||
static char buf[32];
|
||||
fastReadNum(g->hwmon + "/freq1_input", g->clock_core) / 1000000;
|
||||
fastReadNum(g->hwmon + "/freq2_input", g->clock_mem) / 1000000;
|
||||
fastReadNum(g->hwmon + "/power1_input", g->power_avg) / 1000000;
|
||||
fastReadNum(g->hwmon + "/temp1_input", g->temp_edge) / 1000;
|
||||
fastReadNum(g->hwmon + "/../../gpu_busy_percent", g->usage_core);
|
||||
g->clock_core = fastReadNum(g->hwmon + "/freq1_input", buf) / 1000000;
|
||||
g->clock_mem = fastReadNum(g->hwmon + "/freq2_input", buf) / 1000000;
|
||||
g->power_avg = fastReadNum(g->hwmon + "/power1_input", buf) / 1000000;
|
||||
g->temp_edge = fastReadNum(g->hwmon + "/temp1_input", buf) / 1000;
|
||||
g->usage_core = fastReadNum(g->hwmon + "/../../gpu_busy_percent", buf);
|
||||
}
|
||||
|
||||
/* get sensors for vega and newer (rx5700xt, rx7800xt [*]) */
|
||||
|
||||
10
src/sys.cpp
10
src/sys.cpp
@@ -55,8 +55,8 @@ void sys::getNetwork(Network* net, const std::string& device) {
|
||||
_net current;
|
||||
|
||||
current.ts = std::chrono::steady_clock::now();
|
||||
fastReadNum("/sys/class/net/" + device + "/statistics/rx_bytes", current.rx);
|
||||
fastReadNum("/sys/class/net/" + device + "/statistics/tx_bytes", current.tx);
|
||||
current.rx = fastReadNum("/sys/class/net/" + device + "/statistics/rx_bytes", buf);
|
||||
current.tx = fastReadNum("/sys/class/net/" + device + "/statistics/tx_bytes", buf);
|
||||
float ts_diff = std::chrono::duration_cast<std::chrono::microseconds>(current.ts - prev.ts).count() / 1000000.0f;
|
||||
net->download = (current.rx - prev.rx) / ts_diff;
|
||||
net->upload = (current.tx - prev.tx) / ts_diff;
|
||||
@@ -77,7 +77,7 @@ void sys::updateSensors(sysSensors* s) {
|
||||
if (s->hwmon.length() < 1)
|
||||
return;
|
||||
static char buf[8];
|
||||
fastReadNum(s->hwmon + "/fan2_input", s->fan_speed[0]);
|
||||
fastReadNum(s->hwmon + "/fan7_input", s->fan_speed[1]);
|
||||
fastReadNum(s->hwmon + "/temp5_input", s->t_sensor) / 1000;
|
||||
s->fan_speed[0] = fastReadNum(s->hwmon + "/fan2_input", buf);
|
||||
s->fan_speed[1] = fastReadNum(s->hwmon + "/fan7_input", buf);
|
||||
s->t_sensor = fastReadNum(s->hwmon + "/temp5_input", buf) / 1000;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user