summaryrefslogtreecommitdiff
path: root/sysdeps
diff options
context:
space:
mode:
authorBenoit Dejean <bdejean@gmail.com>2015-06-21 20:23:27 +0200
committerBenoit Dejean <bdejean@gmail.com>2015-07-15 18:38:27 +0200
commitca6cabe41dcaaf74a344e27b4438a20e6f5a2a4f (patch)
treeb6a23fb011167bdb1d58c6c3844ba2d35b81f06a /sysdeps
parent4fb241097fd30204ac9a9a661c04618a0a844ace (diff)
downloadlibgtop-ca6cabe41dcaaf74a344e27b4438a20e6f5a2a4f.tar.gz
For processes with threads, only reports the pid once.
On my system, this brings proclist's output from +300 to 72.
Diffstat (limited to 'sysdeps')
-rw-r--r--sysdeps/freebsd/proclist.c12
1 files changed, 12 insertions, 0 deletions
diff --git a/sysdeps/freebsd/proclist.c b/sysdeps/freebsd/proclist.c
index 975c7e29..19fae167 100644
--- a/sysdeps/freebsd/proclist.c
+++ b/sysdeps/freebsd/proclist.c
@@ -70,6 +70,7 @@ glibtop_get_proclist_p (glibtop *server, glibtop_proclist *buf,
glibtop_proc_state procstate;
size_t len;
unsigned int i;
+ pid_t prev;
glibtop_init_p (server, (1L << GLIBTOP_SYSDEPS_PROCLIST), 0);
@@ -97,6 +98,17 @@ glibtop_get_proclist_p (glibtop *server, glibtop_proclist *buf,
pid = (pid_t) pinfo[i].ki_pid;
+ /* If a process has many threads, kern.proc.all reports multiple
+ times the same pid. So don't look twice at the same pid.
+ FIXME?: not sure that kern.proc.all reports a partially sorted
+ list (all pid/threads grouped).
+ */
+ if (i > 0 && pid == prev) {
+ continue;
+ }
+
+ prev = pid;
+
switch (which & GLIBTOP_KERN_PROC_MASK) {
case GLIBTOP_KERN_PROC_ALL:
break;