**** Merged from HEAD ****
Merged everything from HEAD for the upcoming release.
This commit is contained in:
@@ -1,3 +1,17 @@
|
||||
1999-05-26 Martin Baulig <martin@home-of-linux.org>
|
||||
|
||||
More NetBSD 1.4 fixes.
|
||||
|
||||
* mem.c, procmap.c, procmem.c: Make this work with the new UVM code.
|
||||
|
||||
[FIXME: This following most likely works on all BSD systems, but
|
||||
this needs to be tested; I made it conditional to NetBSD 1.4 at
|
||||
the moment. Please extend the conditionals to any other systems
|
||||
where this works ...]
|
||||
|
||||
* procstate.c: Added `ruid' and `rgid' for LibGTop >= 1.1.0.
|
||||
* procuid.c: Added `ngroups' and `groups' for LibGTop >= 1.1.0.
|
||||
|
||||
1999-05-25 Martin Baulig <martin@home-of-linux.org>
|
||||
|
||||
* ppp.c: Make this work on NetBSD.
|
||||
|
@@ -31,6 +31,10 @@
|
||||
#include <sys/vmmeter.h>
|
||||
#include <vm/vm_param.h>
|
||||
|
||||
#if defined(__NetBSD__) && (__NetBSD_Version__ >= 104000000)
|
||||
#include <uvm/uvm_extern.h>
|
||||
#endif
|
||||
|
||||
static const unsigned long _glibtop_sysdeps_mem =
|
||||
(1L << GLIBTOP_MEM_TOTAL) + (1L << GLIBTOP_MEM_USED) +
|
||||
(1L << GLIBTOP_MEM_FREE) +
|
||||
@@ -53,7 +57,10 @@ static int pageshift; /* log base 2 of the pagesize */
|
||||
|
||||
/* nlist structure for kernel access */
|
||||
static struct nlist nlst [] = {
|
||||
{ "_cnt" },
|
||||
#if defined(__NetBSD__) && (__NetBSD_Version__ >= 104000000)
|
||||
{ "_bufpages" },
|
||||
{ 0 }
|
||||
#else
|
||||
#if defined(__bsdi__)
|
||||
{ "_bufcachemem" },
|
||||
#elif defined(__FreeBSD__)
|
||||
@@ -61,7 +68,9 @@ static struct nlist nlst [] = {
|
||||
#else
|
||||
{ "_bufpages" },
|
||||
#endif
|
||||
{ "_cnt" },
|
||||
{ 0 }
|
||||
#endif
|
||||
};
|
||||
|
||||
/* MIB array for sysctl */
|
||||
@@ -72,6 +81,10 @@ static int mib [] = { CTL_VM, VM_TOTAL };
|
||||
static int mib [] = { CTL_VM, VM_METER };
|
||||
#endif
|
||||
|
||||
#if defined(__NetBSD__) && (__NetBSD_Version__ >= 104000000)
|
||||
static int mib_uvmexp [] = { CTL_VM, VM_UVMEXP };
|
||||
#endif
|
||||
|
||||
/* Init function. */
|
||||
|
||||
void
|
||||
@@ -104,9 +117,15 @@ glibtop_get_mem_p (glibtop *server, glibtop_mem *buf)
|
||||
{
|
||||
struct vmtotal vmt;
|
||||
size_t length_vmt;
|
||||
#if defined(__NetBSD__) && (__NetBSD_Version__ >= 104000000)
|
||||
struct uvmexp uvmexp;
|
||||
size_t length_uvmexp;
|
||||
#else
|
||||
struct vmmeter vmm;
|
||||
#endif
|
||||
u_int v_used_count;
|
||||
u_int v_total_count;
|
||||
u_int v_free_count;
|
||||
int bufspace;
|
||||
|
||||
glibtop_init_p (server, (1L << GLIBTOP_SYSDEPS_MEM), 0);
|
||||
@@ -123,18 +142,26 @@ glibtop_get_mem_p (glibtop *server, glibtop_mem *buf)
|
||||
/* Get the data from sysctl */
|
||||
length_vmt = sizeof (vmt);
|
||||
if (sysctl (mib, 2, &vmt, &length_vmt, NULL, 0)) {
|
||||
glibtop_warn_io_r (server, "sysctl");
|
||||
glibtop_warn_io_r (server, "sysctl (vmt)");
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
#if defined(__NetBSD__) && (__NetBSD_Version__ >= 104000000)
|
||||
length_uvmexp = sizeof (uvmexp);
|
||||
if (sysctl (mib_uvmexp, 2, &uvmexp, &length_uvmexp, NULL, 0)) {
|
||||
glibtop_warn_io_r (server, "sysctl (uvmexp)");
|
||||
return;
|
||||
}
|
||||
#else
|
||||
/* Get the data from kvm_* */
|
||||
if (kvm_read (server->machine.kd, nlst[0].n_value,
|
||||
if (kvm_read (server->machine.kd, nlst[1].n_value,
|
||||
&vmm, sizeof (vmm)) != sizeof (vmm)) {
|
||||
glibtop_warn_io_r (server, "kvm_read (cnt)");
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
|
||||
if (kvm_read (server->machine.kd, nlst[1].n_value,
|
||||
if (kvm_read (server->machine.kd, nlst[0].n_value,
|
||||
&bufspace, sizeof (bufspace)) != sizeof (bufspace)) {
|
||||
glibtop_warn_io_r (server, "kvm_read (bufspace)");
|
||||
return;
|
||||
@@ -144,23 +171,41 @@ glibtop_get_mem_p (glibtop *server, glibtop_mem *buf)
|
||||
|
||||
#if defined(__FreeBSD__)
|
||||
v_total_count = vmm.v_page_count;
|
||||
#else
|
||||
#if defined(__NetBSD__) && (__NetBSD_Version__ >= 104000000)
|
||||
v_total_count = uvmexp.reserve_kernel +
|
||||
uvmexp.reserve_pagedaemon +
|
||||
uvmexp.free + uvmexp.wired + uvmexp.active +
|
||||
uvmexp.inactive;
|
||||
#else
|
||||
v_total_count = vmm.v_kernel_pages +
|
||||
vmm.v_free_count + vmm.v_wire_count +
|
||||
vmm.v_active_count + vmm.v_inactive_count;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if defined(__NetBSD__) && (__NetBSD_Version__ >= 104000000)
|
||||
v_used_count = uvmexp.active + uvmexp.inactive;
|
||||
v_free_count = uvmexp.free;
|
||||
#else
|
||||
v_used_count = vmm.v_active_count + vmm.v_inactive_count;
|
||||
v_free_count = vmm.v_free_count;
|
||||
#endif
|
||||
|
||||
buf->total = (u_int64_t) pagetok (v_total_count) << LOG1024;
|
||||
buf->used = (u_int64_t) pagetok (v_used_count) << LOG1024;
|
||||
buf->free = (u_int64_t) pagetok (vmm.v_free_count) << LOG1024;
|
||||
buf->free = (u_int64_t) pagetok (v_free_count) << LOG1024;
|
||||
|
||||
#ifdef __FreeBSD__
|
||||
buf->cached = (u_int64_t) pagetok (vmm.v_cache_count) << LOG1024;
|
||||
#endif
|
||||
|
||||
#if defined(__NetBSD__) && (__NetBSD_Version__ >= 104000000)
|
||||
buf->locked = (u_int64_t) pagetok (uvmexp.wired) << LOG1024;
|
||||
#else
|
||||
buf->locked = (u_int64_t) pagetok (vmm.v_wire_count) << LOG1024;
|
||||
#endif
|
||||
|
||||
buf->shared = (u_int64_t) pagetok (vmt.t_rmshr) << LOG1024;
|
||||
|
||||
#if __FreeBSD__
|
||||
|
@@ -48,6 +48,14 @@
|
||||
#include <sys/sysctl.h>
|
||||
#include <vm/vm.h>
|
||||
|
||||
#if defined(__NetBSD__) && (__NetBSD_Version__ >= 104000000)
|
||||
/* Fixme ... */
|
||||
#undef _KERNEL
|
||||
#define _UVM_UVM_AMAP_I_H_ 1
|
||||
#define _UVM_UVM_MAP_I_H_ 1
|
||||
#include <uvm/uvm.h>
|
||||
#endif
|
||||
|
||||
static const unsigned long _glibtop_sysdeps_proc_map =
|
||||
(1L << GLIBTOP_PROC_MAP_TOTAL) + (1L << GLIBTOP_PROC_MAP_NUMBER) +
|
||||
(1L << GLIBTOP_PROC_MAP_SIZE);
|
||||
@@ -74,11 +82,18 @@ glibtop_get_proc_map_p (glibtop *server, glibtop_proc_map *buf,
|
||||
struct kinfo_proc *pinfo;
|
||||
struct vm_map_entry entry, *first;
|
||||
struct vmspace vmspace;
|
||||
#if defined(__NetBSD__) && (__NetBSD_Version__ >= 104000000)
|
||||
struct vnode vnode;
|
||||
struct inode inode;
|
||||
#else
|
||||
struct vm_object object;
|
||||
#endif
|
||||
glibtop_map_entry *maps;
|
||||
#if defined __FreeBSD__
|
||||
struct vnode vnode;
|
||||
struct inode inode;
|
||||
struct mount mount;
|
||||
#endif
|
||||
int count, i = 0;
|
||||
int update = 0;
|
||||
|
||||
@@ -147,9 +162,14 @@ glibtop_get_proc_map_p (glibtop *server, glibtop_proc_map *buf,
|
||||
if (entry.eflags & (MAP_ENTRY_IS_A_MAP|MAP_ENTRY_IS_SUB_MAP))
|
||||
continue;
|
||||
#endif
|
||||
#else
|
||||
#if defined(__NetBSD__) && (__NetBSD_Version__ >= 104000000)
|
||||
if (UVM_ET_ISSUBMAP (&entry))
|
||||
continue;
|
||||
#else
|
||||
if (entry.is_a_map || entry.is_sub_map)
|
||||
continue;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
maps [i].flags = _glibtop_sysdeps_map_entry;
|
||||
@@ -169,6 +189,19 @@ glibtop_get_proc_map_p (glibtop *server, glibtop_proc_map *buf,
|
||||
|
||||
i++;
|
||||
|
||||
#if defined(__NetBSD__) && (__NetBSD_Version__ >= 104000000)
|
||||
if (!entry.object.uvm_obj)
|
||||
continue;
|
||||
|
||||
/* We're only interested in vnodes */
|
||||
|
||||
if (kvm_read (server->machine.kd,
|
||||
(unsigned long) entry.object.uvm_obj,
|
||||
&vnode, sizeof (vnode)) != sizeof (vnode)) {
|
||||
glibtop_warn_io_r (server, "kvm_read (vnode)");
|
||||
return NULL;
|
||||
}
|
||||
#else
|
||||
if (!entry.object.vm_object)
|
||||
continue;
|
||||
|
||||
@@ -178,6 +211,24 @@ glibtop_get_proc_map_p (glibtop *server, glibtop_proc_map *buf,
|
||||
(unsigned long) entry.object.vm_object,
|
||||
&object, sizeof (object)) != sizeof (object))
|
||||
glibtop_error_io_r (server, "kvm_read (object)");
|
||||
#endif
|
||||
|
||||
#if defined(__NetBSD__) && (__NetBSD_Version__ >= 104000000)
|
||||
if (!vnode.v_uvm.u_flags & UVM_VNODE_VALID)
|
||||
continue;
|
||||
|
||||
if ((vnode.v_type != VREG) || (vnode.v_tag != VT_UFS) ||
|
||||
!vnode.v_data) continue;
|
||||
|
||||
if (kvm_read (server->machine.kd,
|
||||
(unsigned long) vnode.v_data,
|
||||
&inode, sizeof (inode)) != sizeof (inode))
|
||||
glibtop_error_io_r (server, "kvm_read (inode)");
|
||||
|
||||
maps [i-1].inode = inode.i_number;
|
||||
maps [i-1].device = inode.i_dev;
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef __FreeBSD__
|
||||
/* If the object is of type vnode, add its size */
|
||||
|
@@ -45,14 +45,30 @@
|
||||
#include <sys/sysctl.h>
|
||||
#include <vm/vm.h>
|
||||
|
||||
#if defined(__NetBSD__) && (__NetBSD_Version__ >= 104000000)
|
||||
/* Fixme ... */
|
||||
#undef _KERNEL
|
||||
#define _UVM_UVM_AMAP_I_H_ 1
|
||||
#define _UVM_UVM_MAP_I_H_ 1
|
||||
#include <uvm/uvm.h>
|
||||
#endif
|
||||
|
||||
static const unsigned long _glibtop_sysdeps_proc_mem =
|
||||
(1L << GLIBTOP_PROC_MEM_SIZE) +
|
||||
(1L << GLIBTOP_PROC_MEM_VSIZE) +
|
||||
(1L << GLIBTOP_PROC_MEM_SHARE) +
|
||||
(1L << GLIBTOP_PROC_MEM_RESIDENT) +
|
||||
(1L << GLIBTOP_PROC_MEM_RSS) +
|
||||
(1L << GLIBTOP_PROC_MEM_RSS_RLIM);
|
||||
|
||||
static const unsigned long _glibtop_sysdeps_proc_mem_share =
|
||||
#if defined(__NetBSD__) && (__NetBSD_Version__ >= 104000000)
|
||||
(1L << GLIBTOP_PROC_MEM_SHARE);
|
||||
#elif defined(__FreeBSD__)
|
||||
(1L << GLIBTOP_PROC_MEM_SHARE);
|
||||
#else
|
||||
0;
|
||||
#endif
|
||||
|
||||
#ifndef LOG1024
|
||||
#define LOG1024 10
|
||||
#endif
|
||||
@@ -82,7 +98,8 @@ glibtop_init_proc_mem_p (glibtop *server)
|
||||
/* we only need the amount of log(2)1024 for our conversion */
|
||||
pageshift -= LOG1024;
|
||||
|
||||
server->sysdeps.proc_mem = _glibtop_sysdeps_proc_mem;
|
||||
server->sysdeps.proc_mem = _glibtop_sysdeps_proc_mem |
|
||||
_glibtop_sysdeps_proc_mem_share;
|
||||
}
|
||||
|
||||
/* Provides detailed information about a process. */
|
||||
@@ -94,7 +111,12 @@ glibtop_get_proc_mem_p (glibtop *server, glibtop_proc_mem *buf,
|
||||
struct kinfo_proc *pinfo;
|
||||
struct vm_map_entry entry, *first;
|
||||
struct vmspace *vms, vmspace;
|
||||
#if defined(__NetBSD__) && (__NetBSD_Version__ >= 104000000)
|
||||
struct vnode vnode;
|
||||
struct inode inode;
|
||||
#else
|
||||
struct vm_object object;
|
||||
#endif
|
||||
struct plimit plimit;
|
||||
int count;
|
||||
|
||||
@@ -173,11 +195,29 @@ glibtop_get_proc_mem_p (glibtop *server, glibtop_proc_mem *buf,
|
||||
if (entry.eflags & (MAP_ENTRY_IS_A_MAP|MAP_ENTRY_IS_SUB_MAP))
|
||||
continue;
|
||||
#endif
|
||||
#else
|
||||
#if defined(__NetBSD__) && (__NetBSD_Version__ >= 104000000)
|
||||
if (UVM_ET_ISSUBMAP (&entry))
|
||||
continue;
|
||||
#else
|
||||
if (entry.is_a_map || entry.is_sub_map)
|
||||
continue;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if defined(__NetBSD__) && (__NetBSD_Version__ >= 104000000)
|
||||
if (!entry.object.uvm_obj)
|
||||
continue;
|
||||
|
||||
/* We're only interested in vnodes */
|
||||
|
||||
if (kvm_read (server->machine.kd,
|
||||
(unsigned long) entry.object.uvm_obj,
|
||||
&vnode, sizeof (vnode)) != sizeof (vnode)) {
|
||||
glibtop_warn_io_r (server, "kvm_read (vnode)");
|
||||
return;
|
||||
}
|
||||
#else
|
||||
if (!entry.object.vm_object)
|
||||
continue;
|
||||
|
||||
@@ -189,18 +229,31 @@ glibtop_get_proc_mem_p (glibtop *server, glibtop_proc_mem *buf,
|
||||
glibtop_warn_io_r (server, "kvm_read (object)");
|
||||
return;
|
||||
}
|
||||
|
||||
#endif
|
||||
/* If the object is of type vnode, add its size */
|
||||
|
||||
#if defined(__NetBSD__) && (__NetBSD_Version__ >= 104000000)
|
||||
if (!vnode.v_uvm.u_flags & UVM_VNODE_VALID)
|
||||
continue;
|
||||
|
||||
if ((vnode.v_type != VREG) || (vnode.v_tag != VT_UFS) ||
|
||||
!vnode.v_data) continue;
|
||||
|
||||
/* Reference count must be at least two. */
|
||||
if (vnode.v_uvm.u_obj.uo_refs <= 1)
|
||||
continue;
|
||||
|
||||
buf->share += pagetok (vnode.v_uvm.u_obj.uo_npages) << LOG1024;
|
||||
#endif
|
||||
|
||||
#ifdef __FreeBSD__
|
||||
if (object.type != OBJT_VNODE)
|
||||
continue;
|
||||
|
||||
buf->share += object.un_pager.vnp.vnp_size;
|
||||
#else
|
||||
buf->share += object.size;
|
||||
#endif
|
||||
}
|
||||
|
||||
buf->flags = _glibtop_sysdeps_proc_mem;
|
||||
buf->flags = _glibtop_sysdeps_proc_mem |
|
||||
_glibtop_sysdeps_proc_mem_share;
|
||||
}
|
||||
|
@@ -36,12 +36,20 @@ static const unsigned long _glibtop_sysdeps_proc_state =
|
||||
(1L << GLIBTOP_PROC_STATE_CMD) + (1L << GLIBTOP_PROC_STATE_UID) +
|
||||
(1L << GLIBTOP_PROC_STATE_GID);
|
||||
|
||||
static const unsigned long _glibtop_sysdeps_proc_state_new =
|
||||
#if LIBGTOP_VERSION_CODE >= 1001000
|
||||
(1L << GLIBTOP_PROC_STATE_RUID) + (1L << GLIBTOP_PROC_STATE_RGID);
|
||||
#else
|
||||
0;
|
||||
#endif
|
||||
|
||||
/* Init function. */
|
||||
|
||||
void
|
||||
glibtop_init_proc_state_p (glibtop *server)
|
||||
{
|
||||
server->sysdeps.proc_state = _glibtop_sysdeps_proc_state;
|
||||
server->sysdeps.proc_state = _glibtop_sysdeps_proc_state |
|
||||
_glibtop_sysdeps_proc_state_new;
|
||||
}
|
||||
|
||||
/* Provides detailed information about a process. */
|
||||
@@ -74,8 +82,14 @@ glibtop_get_proc_state_p (glibtop *server,
|
||||
buf->uid = pinfo [0].kp_eproc.e_pcred.p_svuid;
|
||||
buf->gid = pinfo [0].kp_eproc.e_pcred.p_svgid;
|
||||
|
||||
#if LIBGTOP_VERSION_CODE >= 1001000
|
||||
buf->ruid = pinfo [0].kp_eproc.e_pcred.p_ruid;
|
||||
buf->rgid = pinfo [0].kp_eproc.e_pcred.p_rgid;
|
||||
#endif
|
||||
|
||||
/* Set the flags for the data we're about to return*/
|
||||
buf->flags = _glibtop_sysdeps_proc_state;
|
||||
buf->flags = _glibtop_sysdeps_proc_state |
|
||||
_glibtop_sysdeps_proc_state_new;
|
||||
|
||||
switch (pinfo [0].kp_proc.p_stat) {
|
||||
case SIDL:
|
||||
|
@@ -36,7 +36,8 @@ static const unsigned long _glibtop_sysdeps_proc_time =
|
||||
|
||||
static const unsigned long _glibtop_sysdeps_proc_time_user =
|
||||
(1L << GLIBTOP_PROC_TIME_UTIME) + (1L << GLIBTOP_PROC_TIME_STIME) +
|
||||
(1L << GLIBTOP_PROC_TIME_CUTIME) + (1L << GLIBTOP_PROC_TIME_CSTIME);
|
||||
(1L << GLIBTOP_PROC_TIME_CUTIME) + (1L << GLIBTOP_PROC_TIME_CSTIME) +
|
||||
(1L << GLIBTOP_PROC_TIME_START_TIME);
|
||||
|
||||
#define tv2sec(tv) (((u_int64_t) tv.tv_sec * 1000000) + (u_int64_t) tv.tv_usec)
|
||||
|
||||
@@ -123,7 +124,11 @@ glibtop_get_proc_time_p (glibtop *server, glibtop_proc_time *buf,
|
||||
pid_t pid)
|
||||
{
|
||||
struct kinfo_proc *pinfo;
|
||||
#if defined(__NetBSD__) && (__NetBSD_Version__ >= 104000000)
|
||||
register struct rusage *rup;
|
||||
#else
|
||||
struct user *u_addr = (struct user *)USRSTACK;
|
||||
#endif
|
||||
struct pstats pstats;
|
||||
int count;
|
||||
|
||||
@@ -134,15 +139,17 @@ glibtop_get_proc_time_p (glibtop *server, glibtop_proc_time *buf,
|
||||
|
||||
memset (buf, 0, sizeof (glibtop_proc_time));
|
||||
|
||||
if (server->sysdeps.proc_time == 0)
|
||||
return;
|
||||
|
||||
/* It does not work for the swapper task. */
|
||||
if (pid == 0) return;
|
||||
|
||||
#if !(defined(__NetBSD__) && (__NetBSD_Version__ >= 104000000))
|
||||
if (server->sysdeps.proc_time == 0)
|
||||
return;
|
||||
|
||||
#ifndef __bsdi__
|
||||
sprintf (filename, "/proc/%d/mem", (int) pid);
|
||||
if (stat (filename, &statb)) return;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/* Get the process information */
|
||||
@@ -150,6 +157,41 @@ glibtop_get_proc_time_p (glibtop *server, glibtop_proc_time *buf,
|
||||
if ((pinfo == NULL) || (count != 1))
|
||||
glibtop_error_io_r (server, "kvm_getprocs (%d)", pid);
|
||||
|
||||
#if (defined __FreeBSD__) && (__FreeBSD_version >= 300003)
|
||||
buf->rtime = pinfo [0].kp_proc.p_runtime;
|
||||
#else
|
||||
buf->rtime = tv2sec (pinfo [0].kp_proc.p_rtime);
|
||||
#endif
|
||||
|
||||
buf->frequency = 1000000;
|
||||
buf->flags = _glibtop_sysdeps_proc_time;
|
||||
|
||||
#if defined(__NetBSD__) && (__NetBSD_Version__ >= 104000000)
|
||||
glibtop_suid_enter (server);
|
||||
|
||||
if (kvm_read (server->machine.kd,
|
||||
(unsigned long) pinfo [0].kp_proc.p_stats,
|
||||
&pstats, sizeof (pstats)) != sizeof (pstats)) {
|
||||
glibtop_warn_io_r (server, "kvm_read (pstats)");
|
||||
return;
|
||||
}
|
||||
|
||||
glibtop_suid_leave (server);
|
||||
|
||||
rup = &pstats.p_ru;
|
||||
calcru(&(pinfo [0]).kp_proc,
|
||||
&rup->ru_utime, &rup->ru_stime, NULL);
|
||||
|
||||
buf->utime = tv2sec (pstats.p_ru.ru_utime);
|
||||
buf->stime = tv2sec (pstats.p_ru.ru_stime);
|
||||
|
||||
buf->cutime = tv2sec (pstats.p_cru.ru_utime);
|
||||
buf->cstime = tv2sec (pstats.p_cru.ru_stime);
|
||||
|
||||
buf->start_time = tv2sec (pstats.p_start);
|
||||
|
||||
buf->flags |= _glibtop_sysdeps_proc_time_user;
|
||||
#else
|
||||
glibtop_suid_enter (server);
|
||||
|
||||
if ((pinfo [0].kp_proc.p_flag & P_INMEM) &&
|
||||
@@ -182,15 +224,6 @@ glibtop_get_proc_time_p (glibtop *server, glibtop_proc_time *buf,
|
||||
}
|
||||
|
||||
glibtop_suid_leave (server);
|
||||
|
||||
#if (defined __FreeBSD__) && (__FreeBSD_version >= 300003)
|
||||
buf->rtime = pinfo [0].kp_proc.p_runtime;
|
||||
#else
|
||||
buf->rtime = tv2sec (pinfo [0].kp_proc.p_rtime);
|
||||
#endif
|
||||
|
||||
buf->frequency = 1000000;
|
||||
|
||||
buf->flags |= _glibtop_sysdeps_proc_time;
|
||||
}
|
||||
|
||||
|
@@ -34,12 +34,22 @@ static const unsigned long _glibtop_sysdeps_proc_uid =
|
||||
(1L << GLIBTOP_PROC_UID_TPGID) + (1L << GLIBTOP_PROC_UID_PRIORITY) +
|
||||
(1L << GLIBTOP_PROC_UID_NICE);
|
||||
|
||||
static const unsigned long _glibtop_sysdeps_proc_uid_groups =
|
||||
#if LIBGTOP_VERSION_CODE >= 1001000
|
||||
#if defined(__NetBSD__) && (__NetBSD_Version__ >= 104000000)
|
||||
(1L << GLIBTOP_PROC_UID_NGROUPS) + (1L << GLIBTOP_PROC_UID_GROUPS);
|
||||
#endif
|
||||
#else
|
||||
0;
|
||||
#endif
|
||||
|
||||
/* Init function. */
|
||||
|
||||
void
|
||||
glibtop_init_proc_uid_p (glibtop *server)
|
||||
{
|
||||
server->sysdeps.proc_uid = _glibtop_sysdeps_proc_uid;
|
||||
server->sysdeps.proc_uid = _glibtop_sysdeps_proc_uid |
|
||||
_glibtop_sysdeps_proc_uid_groups;
|
||||
}
|
||||
|
||||
/* Provides detailed information about a process. */
|
||||
@@ -51,6 +61,13 @@ glibtop_get_proc_uid_p (glibtop *server, glibtop_proc_uid *buf,
|
||||
struct kinfo_proc *pinfo;
|
||||
int count = 0;
|
||||
|
||||
#if LIBGTOP_VERSION_CODE >= 1001000
|
||||
#if defined(__NetBSD__) && (__NetBSD_Version__ >= 104000000)
|
||||
struct ucred ucred;
|
||||
void *ucred_ptr;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
glibtop_init_p (server, (1L << GLIBTOP_SYSDEPS_PROC_UID), 0);
|
||||
|
||||
memset (buf, 0, sizeof (glibtop_proc_uid));
|
||||
@@ -80,4 +97,30 @@ glibtop_get_proc_uid_p (glibtop *server, glibtop_proc_uid *buf,
|
||||
/* Set the flags for the data we're about to return*/
|
||||
buf->flags = _glibtop_sysdeps_proc_uid;
|
||||
|
||||
/* Use LibGTop conditionals here so we can more easily merge this
|
||||
* code into the LIBGTOP_STABLE_1_0 branch. */
|
||||
#if LIBGTOP_VERSION_CODE >= 1001000
|
||||
/* This probably also works with other versions, but not yet
|
||||
* tested. Please remove the conditional if this is true. */
|
||||
#if defined(__NetBSD__) && (__NetBSD_Version__ >= 104000000)
|
||||
ucred_ptr = (void *) pinfo [0].kp_eproc.e_pcred.pc_ucred;
|
||||
|
||||
if (ucred_ptr) {
|
||||
if (kvm_read (server->machine.kd, (unsigned long) ucred_ptr,
|
||||
&ucred, sizeof (ucred)) != sizeof (ucred)) {
|
||||
glibtop_warn_io_r (server, "kvm_read (ucred)");
|
||||
} else {
|
||||
int count = (ucred.cr_ngroups < GLIBTOP_MAX_GROUPS) ?
|
||||
ucred.cr_ngroups : GLIBTOP_MAX_GROUPS;
|
||||
int i;
|
||||
|
||||
for (i = 0; i < count; i++)
|
||||
buf->groups [i] = ucred.cr_groups [i];
|
||||
buf->ngroups = count;
|
||||
|
||||
buf->flags |= _glibtop_sysdeps_proc_uid_groups;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
|
@@ -69,15 +69,24 @@ static struct nlist nlst [] = {
|
||||
|
||||
#elif defined(__NetBSD__)
|
||||
|
||||
#if (__NetBSD_Version__ >= 104000000)
|
||||
#include <uvm/uvm_extern.h>
|
||||
#include <sys/swap.h>
|
||||
#else
|
||||
#include <vm/vm_swap.h>
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
#if defined(__NetBSD__) && (__NetBSD_Version__ >= 104000000)
|
||||
static int mib_uvmexp [] = { CTL_VM, VM_UVMEXP };
|
||||
#else
|
||||
/* nlist structure for kernel access */
|
||||
static struct nlist nlst2 [] = {
|
||||
{ "_cnt" },
|
||||
{ 0 }
|
||||
};
|
||||
#endif
|
||||
|
||||
/* Init function. */
|
||||
|
||||
@@ -100,10 +109,12 @@ glibtop_init_swap_p (glibtop *server)
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if !(defined(__NetBSD__) && (__NetBSD_Version__ >= 104000000))
|
||||
if (kvm_nlist (server->machine.kd, nlst2) != 0) {
|
||||
glibtop_warn_io_r (server, "kvm_nlist (cnt)");
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
|
||||
server->sysdeps.swap = _glibtop_sysdeps_swap;
|
||||
}
|
||||
@@ -145,8 +156,13 @@ glibtop_get_swap_p (glibtop *server, glibtop_swap *buf)
|
||||
int nswap, i;
|
||||
int avail = 0, inuse = 0;
|
||||
|
||||
#if defined(__NetBSD__) && (__NetBSD_Version__ >= 104000000)
|
||||
struct uvmexp uvmexp;
|
||||
size_t length_uvmexp;
|
||||
#else
|
||||
/* To get `pagein' and `pageout'. */
|
||||
struct vmmeter vmm;
|
||||
#endif
|
||||
static int swappgsin = -1;
|
||||
static int swappgsout = -1;
|
||||
|
||||
@@ -157,6 +173,13 @@ glibtop_get_swap_p (glibtop *server, glibtop_swap *buf)
|
||||
if (server->sysdeps.swap == 0)
|
||||
return;
|
||||
|
||||
#if defined(__NetBSD__) && (__NetBSD_Version__ >= 104000000)
|
||||
length_uvmexp = sizeof (uvmexp);
|
||||
if (sysctl (mib_uvmexp, 2, &uvmexp, &length_uvmexp, NULL, 0)) {
|
||||
glibtop_warn_io_r (server, "sysctl (uvmexp)");
|
||||
return;
|
||||
}
|
||||
#else
|
||||
/* This is used to get the `pagein' and `pageout' members. */
|
||||
|
||||
if (kvm_read (server->machine.kd, nlst2[0].n_value,
|
||||
@@ -164,6 +187,7 @@ glibtop_get_swap_p (glibtop *server, glibtop_swap *buf)
|
||||
glibtop_warn_io_r (server, "kvm_read (cnt)");
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
|
||||
if (swappgsin < 0) {
|
||||
buf->pagein = 0;
|
||||
@@ -172,19 +196,29 @@ glibtop_get_swap_p (glibtop *server, glibtop_swap *buf)
|
||||
#ifdef __FreeBSD__
|
||||
buf->pagein = vmm.v_swappgsin - swappgsin;
|
||||
buf->pageout = vmm.v_swappgsout - swappgsout;
|
||||
#else
|
||||
#if defined(__NetBSD__) && (__NetBSD_Version__ >= 104000000)
|
||||
buf->pagein = uvmexp.swapins - swappgsin;
|
||||
buf->pageout = uvmexp.swapouts - swappgsout;
|
||||
#else
|
||||
buf->pagein = vmm.v_swpin - swappgsin;
|
||||
buf->pageout = vmm.v_swpout - swappgsout;
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
|
||||
#ifdef __FreeBSD__
|
||||
swappgsin = vmm.v_swappgsin;
|
||||
swappgsout = vmm.v_swappgsout;
|
||||
#else
|
||||
#if defined(__NetBSD__) && (__NetBSD_Version__ >= 104000000)
|
||||
swappgsin = uvmexp.swapins;
|
||||
swappgsout = uvmexp.swapouts;
|
||||
#else
|
||||
swappgsin = vmm.v_swpin;
|
||||
swappgsout = vmm.v_swpout;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if defined(__FreeBSD__)
|
||||
|
||||
|
Reference in New Issue
Block a user