From: Michael Tremer Date: Tue, 31 Oct 2023 11:43:03 +0000 (+0000) Subject: os: Fix CPU time calculation X-Git-Tag: 0.9.30~1372 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d955ac99af0083e58c90f5db21f36a82fe6cdbcf;p=pakfire.git os: Fix CPU time calculation Signed-off-by: Michael Tremer --- diff --git a/src/libpakfire/os.c b/src/libpakfire/os.c index c1b8807bc..f3142aabf 100644 --- a/src/libpakfire/os.c +++ b/src/libpakfire/os.c @@ -179,19 +179,20 @@ static int pakfire_parse_cpustat(char* line, size_t length, void* data) { return -EINVAL; // Fetch how many ticks a second - long int ticks = sysconf(_SC_CLK_TCK); + unsigned long int ticks = stat.user + stat.nice + stat.system + stat.idle + + stat.iowait + stat.irq + stat.softirq + stat.steal + stat.guest + stat.guest_nice; // Convert to relative terms - cpustat->user = stat.user / ticks; - cpustat->nice = stat.nice / ticks; - cpustat->system = stat.system / ticks; - cpustat->idle = stat.idle / ticks; - cpustat->iowait = stat.iowait / ticks; - cpustat->irq = stat.irq / ticks; - cpustat->softirq = stat.softirq / ticks; - cpustat->steal = stat.steal / ticks; - cpustat->guest = stat.guest / ticks; - cpustat->guest_nice = stat.guest_nice / ticks; + cpustat->user = (double)stat.user / ticks; + cpustat->nice = (double)stat.nice / ticks; + cpustat->system = (double)stat.system / ticks; + cpustat->idle = (double)stat.idle / ticks; + cpustat->iowait = (double)stat.iowait / ticks; + cpustat->irq = (double)stat.irq / ticks; + cpustat->softirq = (double)stat.softirq / ticks; + cpustat->steal = (double)stat.steal / ticks; + cpustat->guest = (double)stat.guest / ticks; + cpustat->guest_nice = (double)stat.guest_nice / ticks; } return 0;