Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/usr.bin/systat Use kinfo_proc2.
details: https://anonhg.NetBSD.org/src/rev/c77f40e1051d
branches: trunk
changeset: 526494:c77f40e1051d
user: thorpej <thorpej%NetBSD.org@localhost>
date: Sat May 04 18:44:27 2002 +0000
description:
Use kinfo_proc2.
diffstat:
usr.bin/systat/pigs.c | 33 ++++++------
usr.bin/systat/ps.c | 133 +++++++++++++++++++++----------------------------
usr.bin/systat/ps.h | 4 +-
3 files changed, 77 insertions(+), 93 deletions(-)
diffs (truncated from 418 to 300 lines):
diff -r a33c65163ec9 -r c77f40e1051d usr.bin/systat/pigs.c
--- a/usr.bin/systat/pigs.c Sat May 04 18:43:22 2002 +0000
+++ b/usr.bin/systat/pigs.c Sat May 04 18:44:27 2002 +0000
@@ -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 @@
showpigs(void)
{
int i, y, k;
- struct eproc *ep;
+ struct kinfo_proc2 *kp;
float total;
int factor;
const char *pname;
@@ -127,10 +127,11 @@
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 @@
{
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 @@
* 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 -r a33c65163ec9 -r c77f40e1051d usr.bin/systat/ps.c
--- a/usr.bin/systat/ps.c Sat May 04 18:43:22 2002 +0000
+++ b/usr.bin/systat/ps.c Sat May 04 18:44:27 2002 +0000
@@ -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 <sys/cdefs.h>
#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 <sys/param.h>
@@ -66,14 +66,14 @@
#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 @@
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 @@
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 @@
/* 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 @@
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 @@
}
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 @@
#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 @@
} else {
commstr[0] = '(';
commstr[1] = '\0';
- strncat(commstr, p->p_comm, sizeof(commstr) - 1);
+ strncat(commstr, kp->p_comm, sizeof(commstr) - 1);
strcat(commstr, ")");
}
Home |
Main Index |
Thread Index |
Old Index