From 3bd720ad81a3132e9cff973330dddb78fd01a4bb Mon Sep 17 00:00:00 2001 From: Benoit Dejean Date: Sat, 18 Jul 2015 15:08:08 +0200 Subject: [PATCH] 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. --- sysdeps/freebsd/proctime.c | 4 +--- 1 file changed, 1 insertion(+), 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;