[libgtop] openbsd: bring glibtop_get_proc_segment from FreeBSD



commit 02b55313f32cae7e53c73ee02f701b9fc5e29ed9
Author: Antoine Jacoutot <ajacoutot gnome org>
Date:   Sat Feb 8 11:54:07 2014 +0100

    openbsd: bring glibtop_get_proc_segment from FreeBSD

 sysdeps/openbsd/procsegment.c |   46 ++++++++++++++++++----------------------
 1 files changed, 21 insertions(+), 25 deletions(-)
---
diff --git a/sysdeps/openbsd/procsegment.c b/sysdeps/openbsd/procsegment.c
index 2a629c1..eee4159 100644
--- a/sysdeps/openbsd/procsegment.c
+++ b/sysdeps/openbsd/procsegment.c
@@ -30,13 +30,18 @@
 #include <sys/param.h>
 #include <sys/sysctl.h>
 
-static const unsigned long _glibtop_sysdeps_proc_segment = 0;
+static const unsigned long _glibtop_sysdeps_proc_segment =
+(1L << GLIBTOP_PROC_SEGMENT_TEXT_RSS) +
+(1L << GLIBTOP_PROC_SEGMENT_DATA_RSS);
+
+static int pagesize;
 
 /* Init function. */
 
 void
 _glibtop_init_proc_segment_p (glibtop *server)
 {
+       pagesize = getpagesize ();
        server->sysdeps.proc_segment = _glibtop_sysdeps_proc_segment;
 }
 
@@ -47,35 +52,26 @@ glibtop_get_proc_segment_p (glibtop *server,
                            glibtop_proc_segment *buf,
                            pid_t pid)
 {
+       struct kinfo_proc *pinfo;
+       int count = 0;
+
        glibtop_init_p (server, (1L << GLIBTOP_SYSDEPS_PROC_SEGMENT), 0);
 
        memset (buf, 0, sizeof (glibtop_proc_segment));
 
-#if 0
+       /* It does not work for the swapper task. */
+       if (pid == 0) return;
+
        /* Get the process info from the kernel */
-       kvm_getprocs (server->machine.kd, KERN_PROC_PID, pid, count);
-       if (*count != 1) {
-               return; /* the zeroed-out buffer indicating no data */
+       pinfo = kvm_getprocs (server->machine.kd, KERN_PROC_PID, pid,
+                             sizeof (*pinfo), &count);
+       if (pinfo == NULL) {
+               glibtop_warn_io_r (server, "kvm_getprocs (%d)", pid);
+               return;
        }
 
-       /* trs: text resident set size
-          pinfo[0]->kp_eproc.e_xrssize;
-       */
-       /* buf->trs = pinfo[0]->kp_eproc.e_xrssize; */
-       /* lrs: shared-lib resident set size
-          ?  */
-       /* drs: data resident set size
-          pinfo[0]->kp_eproc.e_vm.vm_map.vm_dsize;
-       */
-       /* dt: dirty pages
-        */
-       /* start_code: address of beginning of code segment
-
-        */
-       /* end_code: address of end of code segment
-        */
-       /* start_stack: address of the bottom of stack segment
-        */
-#endif
-}
+       buf->text_rss = pinfo[0].p_vm_tsize * pagesize;
+       buf->data_rss = pinfo[0].p_vm_dsize * pagesize;
 
+       buf->flags = _glibtop_sysdeps_proc_segment;
+}


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