summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBenoit Dejean <bdejean@gmail.com>2015-07-18 15:08:08 +0200
committerBenoit Dejean <bdejean@gmail.com>2015-07-18 15:46:26 +0200
commit3bd720ad81a3132e9cff973330dddb78fd01a4bb (patch)
tree92f08e0e22e0506da09810409cfd3024b581038b
parent6acebf416dd8bc5da49aed1bd020afd656fdade2 (diff)
downloadlibgtop-3bd720ad81a3132e9cff973330dddb78fd01a4bb.tar.gz
Do the math correctly to avoid loss of precision for rtime.
I've noticed this with system-monitor where all processes got a perfectly round CPU time to the second.
-rw-r--r--sysdeps/freebsd/proctime.c4
1 files changed, 1 insertions, 3 deletions
diff --git a/sysdeps/freebsd/proctime.c b/sysdeps/freebsd/proctime.c
index 3928ab5c..be880402 100644
--- a/sysdeps/freebsd/proctime.c
+++ b/sysdeps/freebsd/proctime.c
@@ -80,7 +80,6 @@ glibtop_get_proc_time_p (glibtop *server, glibtop_proc_time *buf,
glibtop_suid_leave (server);
- buf->rtime = pinfo [0].ki_runtime * 1e-6;
len = sizeof (ci);
if (sysctlbyname ("kern.clockrate", &ci, &len, NULL, 0)) {
@@ -90,10 +89,9 @@ glibtop_get_proc_time_p (glibtop *server, glibtop_proc_time *buf,
}
buf->frequency = (ci.stathz ? ci.stathz : ci.hz);
+ buf->rtime = pinfo [0].ki_runtime * buf->frequency / 1000000;
buf->flags = _glibtop_sysdeps_proc_time;
- buf->rtime *= buf->frequency;
-
if ((pinfo [0].ki_flag & PS_INMEM)) {
buf->utime = (pinfo [0].ki_runtime * 1e-6) * buf->frequency;
buf->stime = tv2sec (pinfo [0].ki_rusage.ru_stime) * buf->frequency;