[libgtop] Fix utime/stime/cutime/cstime computation.



commit 1dbe133a240bf13e31de81c3c33eeb7ece40659a
Author: Benoit Dejean <bdejean gmail com>
Date:   Sat Jul 18 20:46:07 2015 +0200

    Fix utime/stime/cutime/cstime computation.

 sysdeps/freebsd/proctime.c |   23 ++++++++++++++++-------
 1 files changed, 16 insertions(+), 7 deletions(-)
---
diff --git a/sysdeps/freebsd/proctime.c b/sysdeps/freebsd/proctime.c
index be88040..ae9ab95 100644
--- a/sysdeps/freebsd/proctime.c
+++ b/sysdeps/freebsd/proctime.c
@@ -37,7 +37,12 @@ static const unsigned long _glibtop_sysdeps_proc_time_user =
 (1L << GLIBTOP_PROC_TIME_CUTIME) + (1L << GLIBTOP_PROC_TIME_CSTIME) +
 (1L << GLIBTOP_PROC_TIME_START_TIME);
 
-#define tv2sec(tv)     (((guint64) tv.tv_sec * 1000000) + (guint64) tv.tv_usec)
+static guint64 tv2sec_freq(struct timeval tv, guint64 freq)
+{
+       return tv.tv_sec * freq + tv.tv_usec * freq / 1000000;
+}
+
+#define tv2sec(tv)     tv2sec_freq(tv, 1)
 
 /* Init function. */
 
@@ -92,16 +97,20 @@ glibtop_get_proc_time_p (glibtop *server, glibtop_proc_time *buf,
        buf->rtime = pinfo [0].ki_runtime * buf->frequency / 1000000;
        buf->flags = _glibtop_sysdeps_proc_time;
 
-       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;
-           buf->cutime = tv2sec (pinfo [0].ki_childtime) * buf->frequency;
+       /*
+         All the following used to be 'if (pinfo [0].ki_flag & PS_INMEM)'
+         but it was never entered.
+         I have no idea what this PS_INMEM is, but it works perfectly
+         without this check.
+        */
+       buf->utime = tv2sec_freq (pinfo [0].ki_rusage.ru_utime, buf->frequency);
+       buf->stime = tv2sec_freq (pinfo [0].ki_rusage.ru_stime, buf->frequency);
+       buf->cutime = tv2sec_freq (pinfo [0].ki_childtime, buf->frequency);
 #if (__FreeBSD_version >= 600006) || defined(__FreeBSD_kernel__)
-          buf->cstime = tv2sec (pinfo [0].ki_rusage_ch.ru_stime) * buf->frequency;
+       buf->cstime = tv2sec_freq (pinfo [0].ki_rusage_ch.ru_stime, buf->frequency);
 #else
           buf->cstime = 0;
 #endif
            buf->start_time = tv2sec (pinfo [0].ki_start);
            buf->flags |= _glibtop_sysdeps_proc_time_user;
-       }
 }


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]