sysinfo
(kernel source), which returns some metrics about the current process.What immediately stands out, is the load averages array. They are
long
values, how to make them to be our beloved fractional numbers?These three values are scaled up by 65536, or more precisely by
SI_LOAD_SHIFT
. So we just divide them:#include <sys/sysinfo.h> // ... struct sysinfo memInfo; sysinfo(&memInfo); printf("sysinfo: load1 = %2.2f\n", (float)memInfo.loads[0] / (float)(1 << SI_LOAD_SHIFT) );
No comments :
Post a Comment