diff --git a/examples/first.c b/examples/first.c index fb4226bc..474e4bd4 100644 --- a/examples/first.c +++ b/examples/first.c @@ -278,7 +278,7 @@ main (int argc, char *argv []) glibtop_get_proc_segment (&data.proc_segment, pid); printf ("Proc_Segment PID %5d (0x%08lx): " - "%lu %lu %lu %lu %lu %lu %lu %lu\n", (int) pid, + "%lu %lu %lu %lu %lu 0x%lx 0x%lx 0x%lx\n", (int) pid, (unsigned long) data.proc_segment.flags, (unsigned long) data.proc_segment.text_rss, (unsigned long) data.proc_segment.shlib_rss, @@ -393,7 +393,7 @@ main (int argc, char *argv []) glibtop_get_proc_segment (&data.proc_segment, ppid); printf ("Proc_Segment PPID %5d (0x%08lx): " - "%lu %lu %lu %lu %lu %lu %lu %lu\n", (int) ppid, + "%lu %lu %lu %lu %lu 0x%lx 0x%lx 0x%lx\n", (int) ppid, (unsigned long) data.proc_segment.flags, (unsigned long) data.proc_segment.text_rss, (unsigned long) data.proc_segment.shlib_rss, @@ -508,7 +508,7 @@ main (int argc, char *argv []) glibtop_get_proc_segment (&data.proc_segment, 1); printf ("Proc_Segment INIT %5d (0x%08lx): " - "%lu %lu %lu %lu %lu %lu %lu %lu\n", 1, + "%lu %lu %lu %lu %lu 0x%lx 0x%lx 0x%lx\n", 1, (unsigned long) data.proc_segment.flags, (unsigned long) data.proc_segment.text_rss, (unsigned long) data.proc_segment.shlib_rss, diff --git a/examples/second.c b/examples/second.c index d34ed563..6767ba17 100644 --- a/examples/second.c +++ b/examples/second.c @@ -87,7 +87,7 @@ output (pid_t pid) glibtop_get_proc_segment (&data.proc_segment, pid); printf ("Proc_Segment PID %5d (0x%08lx): " - "%lu %lu %lu %lu %lu %lu %lu %lu\n", (int) pid, + "%lu %lu %lu %lu %lu 0x%lx 0x%lx 0x%lx\n", (int) pid, (unsigned long) data.proc_segment.flags, (unsigned long) data.proc_segment.text_rss, (unsigned long) data.proc_segment.shlib_rss, diff --git a/sysdeps/kernel/procmem.c b/sysdeps/kernel/procmem.c index 550879fe..613b77f3 100644 --- a/sysdeps/kernel/procmem.c +++ b/sysdeps/kernel/procmem.c @@ -86,7 +86,6 @@ glibtop_get_proc_mem_s (glibtop *server, glibtop_proc_mem *buf, buf->size <<= pageshift; buf->resident <<= pageshift; buf->share <<= pageshift; - buf->rss <<= pageshift; buf->flags = _glibtop_sysdeps_proc_mem; } diff --git a/sysdeps/kernel/procsegment.c b/sysdeps/kernel/procsegment.c index 8708f33c..442c7f07 100644 --- a/sysdeps/kernel/procsegment.c +++ b/sysdeps/kernel/procsegment.c @@ -38,13 +38,33 @@ static const unsigned long _glibtop_sysdeps_proc_segment_state = (1 << GLIBTOP_PROC_SEGMENT_END_CODE) + (1 << GLIBTOP_PROC_SEGMENT_START_STACK); +#ifndef LOG1024 +#define LOG1024 10 +#endif + +/* these are for getting the memory statistics */ +static int pageshift; /* log base 2 of the pagesize */ + +/* define pagetok in terms of pageshift */ +#define pagetok(size) ((size) << pageshift) + /* Init function. */ void glibtop_init_proc_segment_s (glibtop *server) { + register int pagesize; + server->sysdeps.proc_segment = _glibtop_sysdeps_proc_segment | _glibtop_sysdeps_proc_segment_state; + + /* get the page size with "getpagesize" and calculate pageshift. */ + pagesize = getpagesize (); + pageshift = 0; + while (pagesize > 1) { + pageshift++; + pagesize >>= 1; + } } /* Provides detailed information about a process. */ @@ -67,6 +87,12 @@ glibtop_get_proc_segment_s (glibtop *server, glibtop_proc_segment *buf, buf->stack_rss = proc_mem.segment.stack; buf->dirty_size = proc_mem.dt; + buf->text_rss <<= pageshift; + buf->shlib_rss <<= pageshift; + buf->data_rss <<= pageshift; + buf->stack_rss <<= pageshift; + buf->dirty_size <<= pageshift; + buf->flags = _glibtop_sysdeps_proc_segment; if (glibtop_get_proc_data_proc_state_s (server, &proc_state, pid))