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;