version 1.9, 2001/11/19 19:02:16 |
version 1.10, 2001/11/23 22:20:06 |
|
|
|
|
#include <sys/param.h> |
#include <sys/param.h> |
#include <sys/dkstat.h> |
#include <sys/dkstat.h> |
|
#include <sys/resource.h> |
#include <sys/dir.h> |
#include <sys/dir.h> |
#include <sys/time.h> |
#include <sys/time.h> |
#include <sys/proc.h> |
#include <sys/proc.h> |
|
|
|
|
#include <curses.h> |
#include <curses.h> |
#include <math.h> |
#include <math.h> |
#include <nlist.h> |
|
#include <pwd.h> |
#include <pwd.h> |
#include <err.h> |
#include <err.h> |
#include <stdlib.h> |
#include <stdlib.h> |
|
|
} *pt; |
} *pt; |
|
|
static long stime[CPUSTATES]; |
static long stime[CPUSTATES]; |
static int fscale; |
|
static double lccpu; |
static double lccpu; |
|
|
WINDOW * |
WINDOW * |
|
|
total = 1.0; |
total = 1.0; |
factor = 50.0/total; |
factor = 50.0/total; |
|
|
qsort(pt, nproc + 1, sizeof (struct p_times), compar); |
qsort(pt, nproc + 1, sizeof (struct p_times), compar); |
y = 1; |
y = 1; |
i = nproc + 1; |
i = nproc + 1; |
if (i > wnd->_maxy-1) |
if (i > wnd->_maxy-1) |
|
|
if (pt[k].pt_kp == NULL) { |
if (pt[k].pt_kp == NULL) { |
uname = ""; |
uname = ""; |
pname = "<idle>"; |
pname = "<idle>"; |
} |
} else { |
else { |
|
ep = &pt[k].pt_kp->kp_eproc; |
ep = &pt[k].pt_kp->kp_eproc; |
uname = user_from_uid(ep->e_ucred.cr_uid, 0); |
uname = user_from_uid(ep->e_ucred.cr_uid, 0); |
pname = pt[k].pt_kp->kp_proc.p_comm; |
pname = pt[k].pt_kp->kp_proc.p_comm; |
|
|
wmove(wnd, y, 0); wclrtobot(wnd); |
wmove(wnd, y, 0); wclrtobot(wnd); |
} |
} |
|
|
static struct nlist namelist[] = { |
struct loadavg sysload; |
#define X_FIRST 0 |
|
#define X_CPTIME 0 |
|
{ "_cp_time" }, |
|
#define X_CCPU 1 |
|
{ "_ccpu" }, |
|
#define X_FSCALE 2 |
|
{ "_fscale" }, |
|
|
|
{ "" } |
|
}; |
|
|
|
int |
int |
initpigs() |
initpigs() |
{ |
{ |
|
static int sysload_mib[] = {CTL_VM, VM_LOADAVG}; |
|
static int cp_time_mib[] = { CTL_KERN, KERN_CPTIME }; |
|
static int ccpu_mib[] = { CTL_KERN, KERN_CCPU }; |
|
size_t size; |
fixpt_t ccpu; |
fixpt_t ccpu; |
int ret; |
|
|
|
if (namelist[X_FIRST].n_type == 0) { |
size = sizeof(stime); |
if ((ret = kvm_nlist(kd, namelist)) == -1) |
(void) sysctl(cp_time_mib, 2, &stime, &size, NULL, 0); |
errx(1, "%s", kvm_geterr(kd)); |
|
else if (ret) |
|
nlisterr(namelist); |
|
if (namelist[X_FIRST].n_type == 0) { |
|
error("namelist failed"); |
|
return(0); |
|
} |
|
} |
|
KREAD(NPTR(X_CPTIME), stime, sizeof (stime)); |
|
NREAD(X_CCPU, &ccpu, LONG); |
|
NREAD(X_FSCALE, &fscale, LONG); |
|
lccpu = log((double) ccpu / fscale); |
|
|
|
|
size = sizeof(sysload); |
|
(void) sysctl(sysload_mib, 2, &sysload, &size, NULL, 0); |
|
|
|
size = sizeof(ccpu); |
|
(void) sysctl(ccpu_mib, 2, &ccpu, &size, NULL, 0); |
|
|
|
lccpu = log((double) ccpu / sysload.fscale); |
|
|
return(1); |
return(1); |
} |
} |
|
|
void |
void |
fetchpigs() |
fetchpigs() |
{ |
{ |
int i; |
static int cp_time_mib[] = { CTL_KERN, KERN_CPTIME }; |
float time; |
static int lastnproc = 0; |
struct proc *pp; |
|
float *pctp; |
|
struct kinfo_proc *kpp; |
struct kinfo_proc *kpp; |
long ctime[CPUSTATES]; |
long ctime[CPUSTATES]; |
|
float time; |
double t; |
double t; |
static int lastnproc = 0; |
int i; |
|
size_t size; |
|
struct proc *pp; |
|
float *pctp; |
|
|
if (namelist[X_FIRST].n_type == 0) |
|
return; |
|
if ((kpp = kvm_getprocs(kd, KERN_PROC_KTHREAD, 0, &nproc)) == NULL) { |
if ((kpp = kvm_getprocs(kd, KERN_PROC_KTHREAD, 0, &nproc)) == NULL) { |
error("%s", kvm_geterr(kd)); |
error("%s", kvm_geterr(kd)); |
if (pt) |
if (pt) |
|
|
if ((pt = |
if ((pt = |
malloc((nproc + 1) * sizeof(struct p_times))) == NULL) { |
malloc((nproc + 1) * sizeof(struct p_times))) == NULL) { |
error("Out of memory"); |
error("Out of memory"); |
die(0); |
die(); |
} |
} |
} |
} |
lastnproc = nproc; |
lastnproc = nproc; |
|
|
if (time == 0 || (pp->p_flag & P_INMEM) == 0) |
if (time == 0 || (pp->p_flag & P_INMEM) == 0) |
*pctp = 0; |
*pctp = 0; |
else |
else |
*pctp = ((double) pp->p_pctcpu / |
*pctp = ((double) pp->p_pctcpu / |
fscale) / (1.0 - exp(time * lccpu)); |
sysload.fscale) / (1.0 - exp(time * lccpu)); |
} |
} |
/* |
/* |
* and for the imaginary "idle" process |
* and for the imaginary "idle" process |
*/ |
*/ |
KREAD(NPTR(X_CPTIME), ctime, sizeof (ctime)); |
size = sizeof(ctime); |
|
(void) sysctl(cp_time_mib, 2, &ctime, &size, NULL, 0); |
|
|
t = 0; |
t = 0; |
for (i = 0; i < CPUSTATES; i++) |
for (i = 0; i < CPUSTATES; i++) |
t += ctime[i] - stime[i]; |
t += ctime[i] - stime[i]; |