diff options
-rw-r--r-- | kernel/sysctl/libgtop.c | 12 | ||||
-rw-r--r-- | kernel/sysctl/libgtop.h | 3 | ||||
-rw-r--r-- | kernel/sysctl/libgtop_syms.c | 5 | ||||
-rw-r--r-- | sysdeps/kernel/glibtop_private.h | 3 | ||||
-rw-r--r-- | sysdeps/kernel/procdata.c | 16 | ||||
-rw-r--r-- | sysdeps/kernel/proclist.c | 6 | ||||
-rw-r--r-- | sysdeps/kernel/procmem.c | 50 | ||||
-rw-r--r-- | sysdeps/kernel/procsegment.c | 40 |
8 files changed, 129 insertions, 6 deletions
diff --git a/kernel/sysctl/libgtop.c b/kernel/sysctl/libgtop.c index ef0ade5e..401fd883 100644 --- a/kernel/sysctl/libgtop.c +++ b/kernel/sysctl/libgtop.c @@ -289,9 +289,11 @@ task_mem (struct task_struct *p, libgtop_proc_segment_t *proc_segment) struct vm_area_struct * vma = mm->mmap; unsigned long data = 0, stack = 0; unsigned long exec = 0, lib = 0; + unsigned long vsize = 0; for (vma = mm->mmap; vma; vma = vma->vm_next) { unsigned long len = (vma->vm_end - vma->vm_start) >> 10; + vsize += len; if (!vma->vm_file) { data += len; if (vma->vm_flags & VM_GROWSDOWN) @@ -308,6 +310,7 @@ task_mem (struct task_struct *p, libgtop_proc_segment_t *proc_segment) } } + proc_segment->vsize = vsize; proc_segment->data = data; proc_segment->stack = stack; proc_segment->exec = exec; @@ -398,6 +401,7 @@ get_statm (struct task_struct *tsk, libgtop_proc_mem_t *proc_mem) { int size=0, resident=0, share=0, trs=0, lrs=0, drs=0, dt=0; unsigned long data=0, stack=0, exec=0, lib=0; + unsigned long vsize = 0; if (tsk->mm && tsk->mm != &init_mm) { struct vm_area_struct * vma = tsk->mm->mmap; @@ -407,6 +411,8 @@ get_statm (struct task_struct *tsk, libgtop_proc_mem_t *proc_mem) pgd_t *pgd = pgd_offset(tsk->mm, vma->vm_start); int pages = 0, shared = 0, dirty = 0, total = 0; + vsize += len; + statm_pgd_range (pgd, vma->vm_start, vma->vm_end, &pages, &shared, &dirty, &total); resident += pages; @@ -445,7 +451,8 @@ get_statm (struct task_struct *tsk, libgtop_proc_mem_t *proc_mem) vma = vma->vm_next; } } - + + proc_mem->segment.vsize = vsize; proc_mem->segment.data = data; proc_mem->segment.stack = stack; proc_mem->segment.exec = exec; @@ -725,6 +732,9 @@ libgtop_sysctl_proc (ctl_table *table, int nlen, int *name, memset (proc_mem, 0, sizeof (libgtop_proc_mem_t)); get_statm (tsk, proc_mem); + /* Use LIBGTOP_PROC_STAT if you only want rss and rlim. */ + proc_mem->rss = tsk->mm->rss << PAGE_SHIFT; + proc_mem->rlim = tsk->rlim ? tsk->rlim[RLIMIT_RSS].rlim_cur : 0; break; default: return -EINVAL; diff --git a/kernel/sysctl/libgtop.h b/kernel/sysctl/libgtop.h index e91c1c77..2f7db28e 100644 --- a/kernel/sysctl/libgtop.h +++ b/kernel/sysctl/libgtop.h @@ -128,13 +128,14 @@ struct libgtop_proc_kernel struct libgtop_proc_segment { - unsigned long data, exec, stack, lib; + unsigned long vsize, data, exec, stack, lib; }; struct libgtop_proc_mem { libgtop_proc_segment_t segment; int size, resident, share, trs, lrs, drs, dt; + unsigned long rss, rlim; }; #endif diff --git a/kernel/sysctl/libgtop_syms.c b/kernel/sysctl/libgtop_syms.c index e3c27401..ddffc3f7 100644 --- a/kernel/sysctl/libgtop_syms.c +++ b/kernel/sysctl/libgtop_syms.c @@ -15,6 +15,7 @@ extern unsigned long total_forks; EXPORT_SYMBOL(task); +EXPORT_SYMBOL(init_mm); EXPORT_SYMBOL(pidhash); EXPORT_SYMBOL(avenrun); EXPORT_SYMBOL(nr_running); @@ -23,3 +24,7 @@ EXPORT_SYMBOL(last_pid); EXPORT_SYMBOL(total_forks); EXPORT_SYMBOL(si_swapinfo); +extern void scheduling_functions_start_here(void); +extern void scheduling_functions_end_here(void); +EXPORT_SYMBOL(scheduling_functions_start_here); +EXPORT_SYMBOL(scheduling_functions_end_here); diff --git a/sysdeps/kernel/glibtop_private.h b/sysdeps/kernel/glibtop_private.h index 39bdef60..b2f291ad 100644 --- a/sysdeps/kernel/glibtop_private.h +++ b/sysdeps/kernel/glibtop_private.h @@ -44,6 +44,9 @@ int glibtop_get_proc_data_proclist_s (glibtop *server, int glibtop_get_proc_data_proc_state_s (glibtop *server, libgtop_proc_state_t *proc_state, pid_t pid); +int glibtop_get_proc_data_proc_mem_s (glibtop *server, + libgtop_proc_mem_t *proc_mem, + pid_t pid); int glibtop_get_proc_data_proc_kernel_s (glibtop *server, libgtop_proc_kernel_t *proc_kernel, pid_t pid); diff --git a/sysdeps/kernel/procdata.c b/sysdeps/kernel/procdata.c index ab7476a2..4307f23e 100644 --- a/sysdeps/kernel/procdata.c +++ b/sysdeps/kernel/procdata.c @@ -100,6 +100,22 @@ glibtop_get_proc_data_proc_state_s (glibtop *server, } int +glibtop_get_proc_data_proc_mem_s (glibtop *server, + libgtop_proc_mem_t *proc_mem, + pid_t pid) +{ + int name [3] = { CTL_LIBGTOP, LIBGTOP_PROC_MEM, pid }; + size_t size = sizeof (libgtop_proc_mem_t); + + if (sysctl (name, 3, proc_mem, &size, NULL, 0)) { + glibtop_warn_io_r (server, "sysctl (libgtop/proc_mem)"); + return -1; + } + + return 0; +} + +int glibtop_get_proc_data_proc_kernel_s (glibtop *server, libgtop_proc_kernel_t *proc_kernel, pid_t pid) diff --git a/sysdeps/kernel/proclist.c b/sysdeps/kernel/proclist.c index b89d2a25..ecc8d648 100644 --- a/sysdeps/kernel/proclist.c +++ b/sysdeps/kernel/proclist.c @@ -29,7 +29,9 @@ #define GLIBTOP_PROCLIST_FLAGS 3 -static const unsigned long _glibtop_sysdeps_proclist = 0; +static const unsigned long _glibtop_sysdeps_proclist = +(1 << GLIBTOP_PROCLIST_NUMBER) + (1 << GLIBTOP_PROCLIST_SIZE) + +(1 << GLIBTOP_PROCLIST_TOTAL); /* Init function. */ @@ -68,5 +70,7 @@ glibtop_get_proclist_s (glibtop *server, glibtop_proclist *buf, for (i = 0; i < proclist.count; i++) ret [i] = proclist.pids [i]; + buf->flags |= _glibtop_sysdeps_proclist; + return ret; } diff --git a/sysdeps/kernel/procmem.c b/sysdeps/kernel/procmem.c index 6cb01200..550879fe 100644 --- a/sysdeps/kernel/procmem.c +++ b/sysdeps/kernel/procmem.c @@ -24,14 +24,39 @@ #include <glibtop.h> #include <glibtop/procmem.h> -static const unsigned long _glibtop_sysdeps_proc_mem = 0; +#include <glibtop_private.h> + +static const unsigned long _glibtop_sysdeps_proc_mem = +(1 << GLIBTOP_PROC_MEM_VSIZE) + (1 << GLIBTOP_PROC_MEM_SIZE) + +(1 << GLIBTOP_PROC_MEM_RESIDENT) + (1 << GLIBTOP_PROC_MEM_SHARE) + +(1 << GLIBTOP_PROC_MEM_RSS) + (1 << GLIBTOP_PROC_MEM_RSS_RLIM); + +#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_mem_s (glibtop *server) { + register int pagesize; + server->sysdeps.proc_mem = _glibtop_sysdeps_proc_mem; + + /* 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. */ @@ -40,5 +65,28 @@ void glibtop_get_proc_mem_s (glibtop *server, glibtop_proc_mem *buf, pid_t pid) { + libgtop_proc_mem_t proc_mem; + memset (buf, 0, sizeof (glibtop_proc_mem)); + + if (glibtop_get_proc_data_proc_mem_s (server, &proc_mem, pid)) + return; + + buf->vsize = proc_mem.segment.vsize; + + buf->size = proc_mem.size; + buf->resident = proc_mem.resident; + buf->share = proc_mem.share; + + buf->rss = proc_mem.rss; + buf->rss_rlim = proc_mem.rlim; + + buf->vsize <<= pageshift; + + 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 6bf41f6d..8708f33c 100644 --- a/sysdeps/kernel/procsegment.c +++ b/sysdeps/kernel/procsegment.c @@ -24,14 +24,27 @@ #include <glibtop.h> #include <glibtop/procsegment.h> -static const unsigned long _glibtop_sysdeps_proc_segment = 0; +#include <glibtop_private.h> + +static const unsigned long _glibtop_sysdeps_proc_segment = +(1 << GLIBTOP_PROC_SEGMENT_TEXT_RSS) + +(1 << GLIBTOP_PROC_SEGMENT_SHLIB_RSS) + +(1 << GLIBTOP_PROC_SEGMENT_DATA_RSS) + +(1 << GLIBTOP_PROC_SEGMENT_STACK_RSS) + +(1 << GLIBTOP_PROC_SEGMENT_DIRTY_SIZE); + +static const unsigned long _glibtop_sysdeps_proc_segment_state = +(1 << GLIBTOP_PROC_SEGMENT_START_CODE) + +(1 << GLIBTOP_PROC_SEGMENT_END_CODE) + +(1 << GLIBTOP_PROC_SEGMENT_START_STACK); /* Init function. */ void glibtop_init_proc_segment_s (glibtop *server) { - server->sysdeps.proc_segment = _glibtop_sysdeps_proc_segment; + server->sysdeps.proc_segment = _glibtop_sysdeps_proc_segment | + _glibtop_sysdeps_proc_segment_state; } /* Provides detailed information about a process. */ @@ -40,5 +53,28 @@ void glibtop_get_proc_segment_s (glibtop *server, glibtop_proc_segment *buf, pid_t pid) { + libgtop_proc_mem_t proc_mem; + libgtop_proc_state_t proc_state; + memset (buf, 0, sizeof (glibtop_proc_segment)); + + if (glibtop_get_proc_data_proc_mem_s (server, &proc_mem, pid)) + return; + + buf->text_rss = proc_mem.trs; + buf->shlib_rss = proc_mem.lrs; + buf->data_rss = proc_mem.drs; + buf->stack_rss = proc_mem.segment.stack; + buf->dirty_size = proc_mem.dt; + + buf->flags = _glibtop_sysdeps_proc_segment; + + if (glibtop_get_proc_data_proc_state_s (server, &proc_state, pid)) + return; + + buf->start_code = proc_state.start_code; + buf->end_code = proc_state.end_code; + buf->start_stack = proc_state.start_stack; + + buf->flags |= _glibtop_sysdeps_proc_segment_state; } |