diff --git a/usr.bin/systat/pigs.c b/usr.bin/systat/pigs.c index cc2f1ececaa1..c0a256317005 100644 --- a/usr.bin/systat/pigs.c +++ b/usr.bin/systat/pigs.c @@ -1,4 +1,4 @@ -/* $NetBSD: pigs.c,v 1.21 2000/12/01 02:19:44 simonb Exp $ */ +/* $NetBSD: pigs.c,v 1.22 2002/05/04 18:44:27 thorpej Exp $ */ /*- * Copyright (c) 1980, 1992, 1993 @@ -38,7 +38,7 @@ #if 0 static char sccsid[] = "@(#)pigs.c 8.2 (Berkeley) 9/23/93"; #endif -__RCSID("$NetBSD: pigs.c,v 1.21 2000/12/01 02:19:44 simonb Exp $"); +__RCSID("$NetBSD: pigs.c,v 1.22 2002/05/04 18:44:27 thorpej Exp $"); #endif /* not lint */ /* @@ -96,7 +96,7 @@ void showpigs(void) { int i, y, k; - struct eproc *ep; + struct kinfo_proc2 *kp; float total; int factor; const char *pname; @@ -127,10 +127,11 @@ showpigs(void) usrstr[0] = '\0'; } else { - ep = &pt[k].pt_kp->kp_eproc; - pname = pt[k].pt_kp->kp_proc.p_comm; - snprintf(pidstr, sizeof(pidstr), "%5d", pt[k].pt_kp->kp_proc.p_pid); - snprintf(usrstr, sizeof(usrstr), "%8s", user_from_uid(ep->e_ucred.cr_uid, 0)); + kp = pt[k].pt_kp; + pname = kp->p_comm; + snprintf(pidstr, sizeof(pidstr), "%5d", kp->p_pid); + snprintf(usrstr, sizeof(usrstr), "%8s", + user_from_uid(kp->p_uid, 0)); } wmove(wnd, y, 0); wclrtoeol(wnd); @@ -183,16 +184,16 @@ fetchpigs(void) { int i; float time; - struct proc *pp; float *pctp; - struct kinfo_proc *kpp; + struct kinfo_proc2 *kpp, *k; u_int64_t ctime[CPUSTATES]; double t; static int lastnproc = 0; if (namelist[X_FIRST].n_type == 0) return; - if ((kpp = kvm_getprocs(kd, KERN_PROC_ALL, 0, &nproc)) == NULL) { + if ((kpp = kvm_getproc2(kd, KERN_PROC_ALL, 0, sizeof(*kpp), + &nproc)) == NULL) { error("%s", kvm_geterr(kd)); if (pt) free(pt); @@ -211,15 +212,15 @@ fetchpigs(void) * calculate %cpu for each proc */ for (i = 0; i < nproc; i++) { - pt[i].pt_kp = &kpp[i]; - pp = &kpp[i].kp_proc; + pt[i].pt_kp = k = &kpp[i]; pctp = &pt[i].pt_pctcpu; - time = pp->p_swtime; - if (P_ZOMBIE(pp) || - time == 0 || (pp->p_flag & P_INMEM) == 0) + time = k->p_swtime; + /* XXX - I don't like this */ + if (k->p_swtime == 0 || (k->p_flag & P_INMEM) == 0 || + k->p_stat == SZOMB || k->p_stat == SDEAD) *pctp = 0; else - *pctp = ((double) pp->p_pctcpu / + *pctp = ((double) k->p_pctcpu / fscale) / (1.0 - exp(time * lccpu)); } /* diff --git a/usr.bin/systat/ps.c b/usr.bin/systat/ps.c index f3a913c4bdef..766094f785ca 100644 --- a/usr.bin/systat/ps.c +++ b/usr.bin/systat/ps.c @@ -1,4 +1,4 @@ -/* $NetBSD: ps.c,v 1.19 2001/07/14 07:09:11 matt Exp $ */ +/* $NetBSD: ps.c,v 1.20 2002/05/04 18:44:27 thorpej Exp $ */ /*- * Copyright (c) 1999 @@ -45,7 +45,7 @@ #include #ifndef lint -__RCSID("$NetBSD: ps.c,v 1.19 2001/07/14 07:09:11 matt Exp $"); +__RCSID("$NetBSD: ps.c,v 1.20 2002/05/04 18:44:27 thorpej Exp $"); #endif /* not lint */ #include @@ -66,14 +66,14 @@ __RCSID("$NetBSD: ps.c,v 1.19 2001/07/14 07:09:11 matt Exp $"); #include "ps.h" int compare_pctcpu_noidle(const void *, const void *); -char *state2str(struct kinfo_proc *); -char *tty2str(struct kinfo_proc *); -int rss2int(struct kinfo_proc *); -int vsz2int(struct kinfo_proc *); -char *comm2str(struct kinfo_proc *); -double pmem2float(struct kinfo_proc *); -char *start2str(struct kinfo_proc *); -char *time2str(struct kinfo_proc *); +char *state2str(struct kinfo_proc2 *); +char *tty2str(struct kinfo_proc2 *); +int rss2int(struct kinfo_proc2 *); +int vsz2int(struct kinfo_proc2 *); +char *comm2str(struct kinfo_proc2 *); +double pmem2float(struct kinfo_proc2 *); +char *start2str(struct kinfo_proc2 *); +char *time2str(struct kinfo_proc2 *); static time_t now; @@ -97,7 +97,7 @@ showps(void) const char *user, *comm, *state, *tty, *start, *time; pid_t pid; double pctcpu, pctmem; - struct eproc *ep; + struct kinfo_proc2 *kp; now = 0; /* force start2str to reget current time */ @@ -111,11 +111,11 @@ showps(void) if (pt[k].pt_kp == NULL) /* We're all the way down to the imaginary idle proc */ break; - ep = &pt[k].pt_kp->kp_eproc; - if (showuser != SHOWUSER_ANY && ep->e_ucred.cr_uid != showuser) + kp = pt[k].pt_kp; + if (showuser != SHOWUSER_ANY && kp->p_uid != showuser) continue; - user = user_from_uid(ep->e_ucred.cr_uid, 0); - pid = pt[k].pt_kp->kp_proc.p_pid; + user = user_from_uid(kp->p_uid, 0); + pid = kp->p_pid; pctcpu = 100.0 * pt[k].pt_pctcpu; pctmem = pmem2float(pt[k].pt_kp); vsz = vsz2int(pt[k].pt_kp); @@ -153,29 +153,24 @@ compare_pctcpu_noidle(const void *a, const void *b) /* from here down adapted from .../src/usr.bin/ps/print.c . Any mistakes are my own, however. */ char * -state2str(struct kinfo_proc *kp) +state2str(struct kinfo_proc2 *kp) { - struct proc *p; - struct eproc *e; int flag; char *cp; char buf[5]; static char statestr[4]; - p = &(kp->kp_proc); - e = &(kp->kp_eproc); - - flag = p->p_flag; + flag = kp->p_flag; cp = buf; - switch (p->p_stat) { + switch (kp->p_stat) { case SSTOP: *cp = 'T'; break; case SSLEEP: if (flag & P_SINTR) /* interuptable (long) */ - *cp = p->p_slptime >= maxslp ? 'I' : 'S'; + *cp = kp->p_slptime >= maxslp ? 'I' : 'S'; else *cp = 'D'; break; @@ -200,21 +195,23 @@ state2str(struct kinfo_proc *kp) if (flag & P_INMEM) { } else *cp++ = 'W'; - if (p->p_nice < NZERO) + if (kp->p_nice < NZERO) *cp++ = '<'; - else if (p->p_nice > NZERO) + else if (kp->p_nice > NZERO) *cp++ = 'N'; if (flag & P_TRACED) *cp++ = 'X'; - if (flag & P_WEXIT && P_ZOMBIE(p) == 0) + if (flag & P_WEXIT && + /* XXX - I don't like this */ + (kp->p_stat == SZOMB || kp->p_stat == SDEAD) == 0) *cp++ = 'E'; if (flag & P_PPWAIT) *cp++ = 'V'; - if ((flag & P_SYSTEM) || p->p_holdcnt) + if ((flag & P_SYSTEM) || kp->p_holdcnt) *cp++ = 'L'; - if (e->e_flag & EPROC_SLEADER) + if (kp->p_eflag & EPROC_SLEADER) *cp++ = 's'; - if ((flag & P_CONTROLT) && e->e_pgid == e->e_tpgid) + if ((flag & P_CONTROLT) && kp->p__pgid == kp->p_tpgid) *cp++ = '+'; *cp = '\0'; snprintf(statestr, sizeof(statestr), "%-s", buf); @@ -223,21 +220,20 @@ state2str(struct kinfo_proc *kp) } char * -tty2str(struct kinfo_proc *kp) +tty2str(struct kinfo_proc2 *kp) { static char ttystr[4]; char *ttyname; - struct eproc *e; - e = &(kp->kp_eproc); - - if (e->e_tdev == NODEV || (ttyname = devname(e->e_tdev, S_IFCHR)) == NULL) + if (kp->p_tdev == NODEV || + (ttyname = devname(kp->p_tdev, S_IFCHR)) == NULL) strcpy(ttystr, "??"); else { if (strncmp(ttyname, "tty", 3) == 0 || strncmp(ttyname, "dty", 3) == 0) ttyname += 3; - snprintf(ttystr, sizeof(ttystr), "%s%c", ttyname, e->e_flag & EPROC_CTTY ? ' ' : '-'); + snprintf(ttystr, sizeof(ttystr), "%s%c", ttyname, + kp->p_eflag & EPROC_CTTY ? ' ' : '-'); } return ttystr; @@ -246,41 +242,35 @@ tty2str(struct kinfo_proc *kp) #define pgtok(a) (((a)*getpagesize())/1024) int -vsz2int(struct kinfo_proc *kp) +vsz2int(struct kinfo_proc2 *kp) { - struct eproc *e; int i; - e = &(kp->kp_eproc); - i = pgtok(e->e_vm.vm_dsize + e->e_vm.vm_ssize + e->e_vm.vm_tsize); + i = pgtok(kp->p_vm_dsize + kp->p_vm_ssize + kp->p_vm_tsize); return ((i < 0) ? 0 : i); -} +} int -rss2int(struct kinfo_proc *kp) +rss2int(struct kinfo_proc2 *kp) { - struct eproc *e; int i; - e = &(kp->kp_eproc); - i = pgtok(e->e_vm.vm_rssize); + i = pgtok(kp->p_vm_rssize); /* XXX don't have info about shared */ return ((i < 0) ? 0 : i); } char * -comm2str(struct kinfo_proc *kp) +comm2str(struct kinfo_proc2 *kp) { char **argv, **pt; static char commstr[41]; - struct proc *p; - p = &(kp->kp_proc); commstr[0]='\0'; - argv = kvm_getargv(kd, kp, 40); + argv = kvm_getargv2(kd, kp, 40); if ((pt = argv) != NULL) { while (*pt) { strcat(commstr, *pt); @@ -290,7 +280,7 @@ comm2str(struct kinfo_proc *kp) } else { commstr[0] = '('; commstr[1] = '\0'; - strncat(commstr, p->p_comm, sizeof(commstr) - 1); + strncat(commstr, kp->p_comm, sizeof(commstr) - 1); strcat(commstr, ")"); } @@ -298,41 +288,33 @@ comm2str(struct kinfo_proc *kp) } double -pmem2float(struct kinfo_proc *kp) +pmem2float(struct kinfo_proc2 *kp) { - struct proc *p; - struct eproc *e; double fracmem; int szptudot = 0; - p = &(kp->kp_proc); - e = &(kp->kp_eproc); - - if ((p->p_flag & P_INMEM) == 0) + /* XXX - I don't like this. */ + if ((kp->p_flag & P_INMEM) == 0) return (0.0); #ifdef USPACE /* XXX want pmap ptpages, segtab, etc. (per architecture) */ szptudot = USPACE/getpagesize(); #endif /* XXX don't have info about shared */ - fracmem = ((double)e->e_vm.vm_rssize + szptudot)/mempages; + fracmem = ((double)kp->p_vm_rssize + szptudot)/mempages; return (fracmem >= 0) ? 100.0 * fracmem : 0; } char * -start2str(struct kinfo_proc *kp) +start2str(struct kinfo_proc2 *kp) { - struct proc *p; - struct pstats pstats; struct timeval u_start; struct tm *tp; time_t startt; static char startstr[10]; - p = &(kp->kp_proc); - - kvm_read(kd, (u_long)&(p->p_addr->u_stats), (char *)&pstats, sizeof(pstats)); - u_start = pstats.p_start; + u_start.tv_sec = kp->p_ustart_sec; + u_start.tv_usec = kp->p_ustart_usec; startt = u_start.tv_sec; tp = localtime(&startt); @@ -353,16 +335,14 @@ start2str(struct kinfo_proc *kp) } char * -time2str(struct kinfo_proc *kp) +time2str(struct kinfo_proc2 *kp) { long secs; long psecs; /* "parts" of a second. first micro, then centi */ static char timestr[10]; - struct proc *p; - p = &(kp->kp_proc); - - if (P_ZOMBIE(p)) { + /* XXX - I don't like this. */ + if (kp->p_stat == SZOMB || kp->p_stat == SDEAD) { secs = 0; psecs = 0; } else { @@ -371,14 +351,16 @@ time2str(struct kinfo_proc *kp) * fix this, but it is not 100% trivial (and interrupt * time fractions only work on the sparc anyway). XXX */ - secs = p->p_rtime.tv_sec; - psecs = p->p_rtime.tv_usec; - /* if (sumrusage) { + secs = kp->p_rtime_sec; + psecs = kp->p_rtime_usec; +#if 0 + if (sumrusage) { secs += k->ki_u.u_cru.ru_utime.tv_sec + k->ki_u.u_cru.ru_stime.tv_sec; psecs += k->ki_u.u_cru.ru_utime.tv_usec + k->ki_u.u_cru.ru_stime.tv_usec; - } */ + } +#endif /* * round and scale to 100's */ @@ -386,7 +368,8 @@ time2str(struct kinfo_proc *kp) secs += psecs / 100; psecs = psecs % 100; } - snprintf(timestr, sizeof(timestr), "%3ld:%02ld.%02ld", secs/60, secs%60, psecs); + snprintf(timestr, sizeof(timestr), "%3ld:%02ld.%02ld", secs/60, + secs%60, psecs); return timestr; } diff --git a/usr.bin/systat/ps.h b/usr.bin/systat/ps.h index 14675eb94b61..6041ecfef2f5 100644 --- a/usr.bin/systat/ps.h +++ b/usr.bin/systat/ps.h @@ -1,4 +1,4 @@ -/* $NetBSD: ps.h,v 1.2 2000/06/04 16:06:26 thorpej Exp $ */ +/* $NetBSD: ps.h,v 1.3 2002/05/04 18:44:27 thorpej Exp $ */ /*- * Copyright (c) 1999 @@ -36,7 +36,7 @@ extern int nproc; extern struct p_times { float pt_pctcpu; - struct kinfo_proc *pt_kp; + struct kinfo_proc2 *pt_kp; } *pt; extern u_int64_t stime[CPUSTATES];