Some more work here.
This commit is contained in:
@@ -75,6 +75,8 @@ glibtop_get_proc_kernel_p (glibtop *server,
|
|||||||
|
|
||||||
memset (buf, 0, sizeof (glibtop_proc_kernel));
|
memset (buf, 0, sizeof (glibtop_proc_kernel));
|
||||||
|
|
||||||
|
glibtop_suid_enter (server);
|
||||||
|
|
||||||
/* Get the process information */
|
/* Get the process information */
|
||||||
pinfo = kvm_getprocs (server->machine.kd, KERN_PROC_PID, pid, &count);
|
pinfo = kvm_getprocs (server->machine.kd, KERN_PROC_PID, pid, &count);
|
||||||
if ((pinfo == NULL) || (count != 1))
|
if ((pinfo == NULL) || (count != 1))
|
||||||
@@ -126,6 +128,8 @@ glibtop_get_proc_kernel_p (glibtop *server,
|
|||||||
|
|
||||||
/* Taken from `wchan ()' in `/usr/src/bin/ps/print.c'. */
|
/* Taken from `wchan ()' in `/usr/src/bin/ps/print.c'. */
|
||||||
|
|
||||||
|
glibtop_suid_leave (server);
|
||||||
|
|
||||||
buf->nwchan = (u_int64_t) pinfo [0].kp_proc.p_wchan &~ KERNBASE;
|
buf->nwchan = (u_int64_t) pinfo [0].kp_proc.p_wchan &~ KERNBASE;
|
||||||
|
|
||||||
if (pinfo [0].kp_proc.p_wchan && pinfo [0].kp_proc.p_wmesg) {
|
if (pinfo [0].kp_proc.p_wchan && pinfo [0].kp_proc.p_wmesg) {
|
||||||
|
@@ -69,8 +69,17 @@ glibtop_get_proclist_p (glibtop *server, glibtop_proclist *buf,
|
|||||||
|
|
||||||
memset (buf, 0, sizeof (glibtop_proclist));
|
memset (buf, 0, sizeof (glibtop_proclist));
|
||||||
|
|
||||||
|
glibtop_suid_enter (server);
|
||||||
|
|
||||||
/* Get the process data */
|
/* Get the process data */
|
||||||
pinfo = kvm_getprocs (server->machine.kd, which, arg, &count);
|
pinfo = kvm_getprocs (server->machine.kd, which, arg, &count);
|
||||||
|
if ((pinfo == NULL) || (count < 1))
|
||||||
|
glibtop_error_io_r (server, "kvm_getprocs (proclist)");
|
||||||
|
|
||||||
|
glibtop_suid_leave (server);
|
||||||
|
|
||||||
|
count--;
|
||||||
|
|
||||||
/* Allocate count objects in the pids_chain array
|
/* Allocate count objects in the pids_chain array
|
||||||
* Same as malloc is pids is NULL, which it is. */
|
* Same as malloc is pids is NULL, which it is. */
|
||||||
pids = glibtop_realloc_r (server, pids, count * sizeof (unsigned));
|
pids = glibtop_realloc_r (server, pids, count * sizeof (unsigned));
|
||||||
|
@@ -27,27 +27,52 @@
|
|||||||
|
|
||||||
#include <kvm.h>
|
#include <kvm.h>
|
||||||
#include <sys/param.h>
|
#include <sys/param.h>
|
||||||
#include <sys/sysctl.h>
|
|
||||||
#include <sys/user.h>
|
|
||||||
#include <sys/proc.h>
|
#include <sys/proc.h>
|
||||||
#include <sys/resource.h>
|
#include <sys/resource.h>
|
||||||
#include <vm/vm_map.h>
|
#include <vm/vm_map.h>
|
||||||
#include <machine/pmap.h>
|
|
||||||
|
#include <sys/ucred.h>
|
||||||
|
#include <sys/user.h>
|
||||||
|
#include <sys/sysctl.h>
|
||||||
|
#include <vm/vm.h>
|
||||||
|
|
||||||
static const unsigned long _glibtop_sysdeps_proc_mem =
|
static const unsigned long _glibtop_sysdeps_proc_mem =
|
||||||
(1 << GLIBTOP_PROC_MEM_SIZE) +
|
(1 << GLIBTOP_PROC_MEM_SIZE) +
|
||||||
(1 << GLIBTOP_PROC_MEM_VSIZE) +
|
(1 << GLIBTOP_PROC_MEM_VSIZE) +
|
||||||
(1 << GLIBTOP_PROC_MEM_RESIDENT) +
|
(1 << GLIBTOP_PROC_MEM_RESIDENT) +
|
||||||
/* (1 << GLIBTOP_PROC_MEM_SHARE) + */
|
|
||||||
(1 << GLIBTOP_PROC_MEM_RSS) +
|
(1 << GLIBTOP_PROC_MEM_RSS) +
|
||||||
(1 << GLIBTOP_PROC_MEM_RSS_RLIM);
|
(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. */
|
/* Init function. */
|
||||||
|
|
||||||
void
|
void
|
||||||
glibtop_init_proc_mem_p (glibtop *server)
|
glibtop_init_proc_mem_p (glibtop *server)
|
||||||
{
|
{
|
||||||
|
register int pagesize;
|
||||||
|
|
||||||
server->sysdeps.proc_mem = _glibtop_sysdeps_proc_mem;
|
server->sysdeps.proc_mem = _glibtop_sysdeps_proc_mem;
|
||||||
|
|
||||||
|
/* get the page size with "getpagesize" and calculate pageshift
|
||||||
|
* from it */
|
||||||
|
pagesize = getpagesize ();
|
||||||
|
pageshift = 0;
|
||||||
|
while (pagesize > 1) {
|
||||||
|
pageshift++;
|
||||||
|
pagesize >>= 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* we only need the amount of log(2)1024 for our conversion */
|
||||||
|
pageshift -= LOG1024;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Provides detailed information about a process. */
|
/* Provides detailed information about a process. */
|
||||||
@@ -56,73 +81,36 @@ void
|
|||||||
glibtop_get_proc_mem_p (glibtop *server, glibtop_proc_mem *buf,
|
glibtop_get_proc_mem_p (glibtop *server, glibtop_proc_mem *buf,
|
||||||
pid_t pid)
|
pid_t pid)
|
||||||
{
|
{
|
||||||
#if 0
|
|
||||||
struct kinfo_proc *pinfo;
|
struct kinfo_proc *pinfo;
|
||||||
struct vmspace vms;
|
struct user *u_addr = (struct user *)USRSTACK;
|
||||||
struct vm_map vmm;
|
struct plimit plimit;
|
||||||
struct pstats ps;
|
struct vmspace *vms;
|
||||||
int count, f;
|
int count;
|
||||||
|
|
||||||
glibtop_init_p (server, GLIBTOP_SYSDEPS_PROC_MEM, 0);
|
glibtop_suid_enter (server);
|
||||||
|
|
||||||
memset (buf, 0, sizeof (glibtop_proc_mem));
|
/* Get the process data */
|
||||||
|
pinfo = kvm_getprocs (server->machine.kd, KERN_PROC_PID, pid, &count);
|
||||||
|
if ((pinfo == NULL) || (count < 1))
|
||||||
|
glibtop_error_io_r (server, "kvm_getprocs (proclist)");
|
||||||
|
|
||||||
f = open ("/dev/kmem", O_RDONLY, NULL);
|
if (kvm_read (server->machine.kd,
|
||||||
if (f == NULL)
|
(unsigned long) pinfo [0].kp_proc.p_limit,
|
||||||
glibtop_error_io_r (server, "open (/dev/kmem)");
|
(char *) &plimit, sizeof (plimit)) != sizeof (plimit))
|
||||||
|
glibtop_error_io_r (server, "kvm_read (plimit)");
|
||||||
|
|
||||||
/* Read the vmspace from kernel memeory */
|
buf->rss_rlim = (u_int64_t)
|
||||||
lseek (f, (long)pinfo[0].kp_proc.p_vmspace, SEEK_SET);
|
(plimit.pl_rlimit [RLIMIT_RSS].rlim_cur);
|
||||||
if (read (f, &vms, sizeof (struct vmspace)) < 0)
|
|
||||||
glibtop_error_io_r (server, "read");
|
|
||||||
/* Read the vm_map from kernel memeory */
|
|
||||||
/* [FIXME: ] lseek (f, (long) vms.vm_map, SEEK_SET); */
|
|
||||||
if (read (f, &vmm, sizeof (struct vm_map)) < 0)
|
|
||||||
glibtop_error_io_r (server, "read");
|
|
||||||
/* Read the pstats [for the RSS rlimit] from kernel memory. */
|
|
||||||
lseek (f, (long)pinfo[0].kp_proc.p_stats, SEEK_SET);
|
|
||||||
if (read (f, &ps, sizeof (struct pstats)) < 0)
|
|
||||||
glibtop_error_io_r (server, "read");
|
|
||||||
close (f);
|
|
||||||
|
|
||||||
/* Get the process information */
|
glibtop_suid_leave (server);
|
||||||
kvm_getprocs (server->machine.kd, KERN_PROC_PID, pid, &count);
|
|
||||||
if (count != 1) {
|
|
||||||
/* Return no information */
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* size: total # of pages in memory
|
vms = &pinfo [0].kp_eproc.e_vm;
|
||||||
(segsz_t)pinfo[0].kp_proc.p_vmspace.(vm_tsize + vm_dsize + vm_ssize)
|
|
||||||
*/
|
|
||||||
buf->size = (u_int64_t) (vms.vm_tsize + vms.vm_dsize + vms.vm_ssize);
|
|
||||||
/* vsize: number of pages of VM
|
|
||||||
(vm_size_t)pinfo[0].kp_proc.p_vmspace.vm_map.size
|
|
||||||
*/
|
|
||||||
buf->vsize = (u_int64_t) vmm.size;
|
|
||||||
|
|
||||||
/* resident: number of resident (non-swapped) pages [4k]
|
buf->vsize = buf->size = (u_int64_t) pagetok
|
||||||
(long)pmap_resident_count(pinfo[0]->kp_proc.p_vmspace.vm_map.pmap);
|
(vms->vm_tsize + vms->vm_dsize + vms->vm_ssize) << LOG1024;
|
||||||
*/
|
|
||||||
buf->resident = (u_int64_t) pmap_resident_count (vmm.pmap);
|
|
||||||
|
|
||||||
/* share: number of pages shared (mmap'd) memory
|
buf->resident = buf->rss = (u_int64_t) pagetok
|
||||||
??? vm_object has this info, but how to get it?
|
(vms->vm_rssize) << LOG1024;
|
||||||
Even if we could, it's not reachable information.
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
/* rss: resident set size
|
|
||||||
(segsz_t)kp_proc.p_vmspace.vm_rssize
|
|
||||||
*/
|
|
||||||
buf->rss = (u_int64_t) vms.vm_rssize;
|
|
||||||
/* rss_rlim: current rss limit [bytes]
|
|
||||||
(rlim_t)kp_proc.p_limit.pl_rlimit[RLIMIT_RSS].rlim_cur
|
|
||||||
or
|
|
||||||
(long)kp_proc.p_stats->p_ru.ru_maxrss */
|
|
||||||
buf->rss_rlim = ps.p_ru.ru_maxrss;
|
|
||||||
|
|
||||||
/* Set the flags */
|
|
||||||
buf->flags = _glibtop_sysdeps_proc_mem;
|
buf->flags = _glibtop_sysdeps_proc_mem;
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
@@ -51,11 +51,15 @@ glibtop_get_proc_signal_p (glibtop *server,
|
|||||||
|
|
||||||
memset (buf, 0, sizeof (glibtop_proc_signal));
|
memset (buf, 0, sizeof (glibtop_proc_signal));
|
||||||
|
|
||||||
|
glibtop_suid_enter (server);
|
||||||
|
|
||||||
/* Get the process information */
|
/* Get the process information */
|
||||||
pinfo = kvm_getprocs (server->machine.kd, KERN_PROC_PID, pid, &count);
|
pinfo = kvm_getprocs (server->machine.kd, KERN_PROC_PID, pid, &count);
|
||||||
if ((pinfo == NULL) || (count != 1))
|
if ((pinfo == NULL) || (count != 1))
|
||||||
glibtop_error_io_r (server, "kvm_getprocs (%d)", pid);
|
glibtop_error_io_r (server, "kvm_getprocs (%d)", pid);
|
||||||
|
|
||||||
|
glibtop_suid_leave (server);
|
||||||
|
|
||||||
/* signal: mask of pending signals.
|
/* signal: mask of pending signals.
|
||||||
* pinfo [0].kp_proc.p_siglist
|
* pinfo [0].kp_proc.p_siglist
|
||||||
*/
|
*/
|
||||||
|
@@ -53,11 +53,15 @@ glibtop_get_proc_state_p (glibtop *server,
|
|||||||
|
|
||||||
memset (buf, 0, sizeof (glibtop_proc_state));
|
memset (buf, 0, sizeof (glibtop_proc_state));
|
||||||
|
|
||||||
|
glibtop_suid_enter (server);
|
||||||
|
|
||||||
/* Get the process information */
|
/* Get the process information */
|
||||||
pinfo = kvm_getprocs (server->machine.kd, KERN_PROC_PID, pid, &count);
|
pinfo = kvm_getprocs (server->machine.kd, KERN_PROC_PID, pid, &count);
|
||||||
if ((pinfo == NULL) || (count != 1))
|
if ((pinfo == NULL) || (count != 1))
|
||||||
glibtop_error_io_r (server, "kvm_getprocs (%d)", pid);
|
glibtop_error_io_r (server, "kvm_getprocs (%d)", pid);
|
||||||
|
|
||||||
|
glibtop_suid_leave (server);
|
||||||
|
|
||||||
strncpy (buf->cmd, pinfo [0].kp_proc.p_comm, sizeof (buf->cmd)-1);
|
strncpy (buf->cmd, pinfo [0].kp_proc.p_comm, sizeof (buf->cmd)-1);
|
||||||
buf->cmd [sizeof (buf->cmd)-1] = 0;
|
buf->cmd [sizeof (buf->cmd)-1] = 0;
|
||||||
|
|
||||||
|
@@ -26,10 +26,11 @@
|
|||||||
#include <glibtop_suid.h>
|
#include <glibtop_suid.h>
|
||||||
|
|
||||||
static const unsigned long _glibtop_sysdeps_proc_time =
|
static const unsigned long _glibtop_sysdeps_proc_time =
|
||||||
(1 << GLIBTOP_PROC_TIME_START_TIME) + (1 << GLIBTOP_PROC_TIME_UTIME) +
|
(1 << GLIBTOP_PROC_TIME_RTIME) + (1 << GLIBTOP_PROC_TIME_FREQUENCY);
|
||||||
(1 << GLIBTOP_PROC_TIME_STIME) + (1 << GLIBTOP_PROC_TIME_CUTIME) +
|
|
||||||
(1 << GLIBTOP_PROC_TIME_CSTIME) + (1 << GLIBTOP_PROC_TIME_TIMEOUT) +
|
static const unsigned long _glibtop_sysdeps_proc_time_user =
|
||||||
(1 << GLIBTOP_PROC_TIME_IT_REAL_VALUE);
|
(1 << GLIBTOP_PROC_TIME_UTIME) + (1 << GLIBTOP_PROC_TIME_STIME) +
|
||||||
|
(1 << GLIBTOP_PROC_TIME_CUTIME) + (1 << GLIBTOP_PROC_TIME_CSTIME);
|
||||||
|
|
||||||
#define tv2sec(tv) (((u_int64_t) tv.tv_sec * 1000000) + (u_int64_t) tv.tv_usec)
|
#define tv2sec(tv) (((u_int64_t) tv.tv_sec * 1000000) + (u_int64_t) tv.tv_usec)
|
||||||
|
|
||||||
@@ -38,7 +39,8 @@ static const unsigned long _glibtop_sysdeps_proc_time =
|
|||||||
void
|
void
|
||||||
glibtop_init_proc_time_p (glibtop *server)
|
glibtop_init_proc_time_p (glibtop *server)
|
||||||
{
|
{
|
||||||
server->sysdeps.proc_time = _glibtop_sysdeps_proc_time;
|
server->sysdeps.proc_time = _glibtop_sysdeps_proc_time |
|
||||||
|
_glibtop_sysdeps_proc_time_user;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Taken from /usr/src/sys/kern/kern_resource.c */
|
/* Taken from /usr/src/sys/kern/kern_resource.c */
|
||||||
@@ -111,6 +113,8 @@ glibtop_get_proc_time_p (glibtop *server, glibtop_proc_time *buf,
|
|||||||
|
|
||||||
memset (buf, 0, sizeof (glibtop_proc_time));
|
memset (buf, 0, sizeof (glibtop_proc_time));
|
||||||
|
|
||||||
|
glibtop_suid_enter (server);
|
||||||
|
|
||||||
/* Get the process information */
|
/* Get the process information */
|
||||||
pinfo = kvm_getprocs (server->machine.kd, KERN_PROC_PID, pid, &count);
|
pinfo = kvm_getprocs (server->machine.kd, KERN_PROC_PID, pid, &count);
|
||||||
if ((pinfo == NULL) || (count != 1))
|
if ((pinfo == NULL) || (count != 1))
|
||||||
@@ -128,6 +132,8 @@ glibtop_get_proc_time_p (glibtop *server, glibtop_proc_time *buf,
|
|||||||
|
|
||||||
register struct rusage *rup;
|
register struct rusage *rup;
|
||||||
|
|
||||||
|
glibtop_suid_leave (server);
|
||||||
|
|
||||||
rup = &pstats.p_ru;
|
rup = &pstats.p_ru;
|
||||||
calcru(&(pinfo [0]).kp_proc,
|
calcru(&(pinfo [0]).kp_proc,
|
||||||
&rup->ru_utime, &rup->ru_stime, NULL);
|
&rup->ru_utime, &rup->ru_stime, NULL);
|
||||||
@@ -139,21 +145,16 @@ glibtop_get_proc_time_p (glibtop *server, glibtop_proc_time *buf,
|
|||||||
buf->cstime = tv2sec (pstats.p_cru.ru_stime);
|
buf->cstime = tv2sec (pstats.p_cru.ru_stime);
|
||||||
|
|
||||||
buf->start_time = tv2sec (pstats.p_start);
|
buf->start_time = tv2sec (pstats.p_start);
|
||||||
|
|
||||||
|
buf->flags = _glibtop_sysdeps_proc_time_user;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if 0
|
glibtop_suid_leave (server);
|
||||||
fprintf (stderr, "TIME: (%ld, %ld) - %ld (%ld, %ld) - %d (%d, %d, %d)\n",
|
|
||||||
(long) pinfo [0].kp_proc.p_rtime.tv_sec,
|
buf->rtime = tv2sec (pinfo [0].kp_proc.p_rtime);
|
||||||
(long) pinfo [0].kp_proc.p_rtime.tv_usec,
|
|
||||||
(unsigned long) (buf->utime + buf->stime),
|
buf->frequency = 1000000;
|
||||||
(unsigned long) buf->utime,
|
|
||||||
(unsigned long) buf->stime,
|
buf->flags |= _glibtop_sysdeps_proc_time;
|
||||||
(int) pinfo [0].kp_proc.p_uticks +
|
|
||||||
(int) pinfo [0].kp_proc.p_sticks +
|
|
||||||
(int) pinfo [0].kp_proc.p_iticks,
|
|
||||||
(int) pinfo [0].kp_proc.p_uticks,
|
|
||||||
(int) pinfo [0].kp_proc.p_sticks,
|
|
||||||
(int) pinfo [0].kp_proc.p_iticks);
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -53,11 +53,15 @@ glibtop_get_proc_uid_p (glibtop *server, glibtop_proc_uid *buf,
|
|||||||
|
|
||||||
memset (buf, 0, sizeof (glibtop_proc_uid));
|
memset (buf, 0, sizeof (glibtop_proc_uid));
|
||||||
|
|
||||||
|
glibtop_suid_enter (server);
|
||||||
|
|
||||||
/* Get the process information */
|
/* Get the process information */
|
||||||
pinfo = kvm_getprocs (server->machine.kd, KERN_PROC_PID, pid, &count);
|
pinfo = kvm_getprocs (server->machine.kd, KERN_PROC_PID, pid, &count);
|
||||||
if ((pinfo == NULL) || (count != 1))
|
if ((pinfo == NULL) || (count != 1))
|
||||||
glibtop_error_io_r (server, "kvm_getprocs (%d)", pid);
|
glibtop_error_io_r (server, "kvm_getprocs (%d)", pid);
|
||||||
|
|
||||||
|
glibtop_suid_leave (server);
|
||||||
|
|
||||||
buf->uid = pinfo [0].kp_eproc.e_pcred.p_ruid;
|
buf->uid = pinfo [0].kp_eproc.e_pcred.p_ruid;
|
||||||
buf->euid = pinfo [0].kp_eproc.e_pcred.p_svuid;
|
buf->euid = pinfo [0].kp_eproc.e_pcred.p_svuid;
|
||||||
buf->gid = pinfo [0].kp_eproc.e_pcred.p_rgid;
|
buf->gid = pinfo [0].kp_eproc.e_pcred.p_rgid;
|
||||||
|
Reference in New Issue
Block a user