summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBenoit Dejean <bdejean@gmail.com>2015-07-18 20:46:07 +0200
committerBenoit Dejean <bdejean@gmail.com>2015-07-18 20:46:07 +0200
commit1dbe133a240bf13e31de81c3c33eeb7ece40659a (patch)
treecdedc436d34589514528259050db380fc8debe62
parent5ee8d4cb58a6a3f41aa2a83a517fe5beca208fa9 (diff)
downloadlibgtop-1dbe133a240bf13e31de81c3c33eeb7ece40659a.tar.gz
Fix utime/stime/cutime/cstime computation.
-rw-r--r--sysdeps/freebsd/proctime.c23
1 files changed, 16 insertions, 7 deletions
diff --git a/sysdeps/freebsd/proctime.c b/sysdeps/freebsd/proctime.c
index be880402..ae9ab958 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;
- }
}