Index: stable/4/bin/ps/keyword.c =================================================================== --- stable/4/bin/ps/keyword.c (revision 83753) +++ stable/4/bin/ps/keyword.c (revision 83754) @@ -1,283 +1,283 @@ /*- * Copyright (c) 1990, 1993, 1994 * The Regents of the University of California. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. All advertising materials mentioning features or use of this software * must display the following acknowledgement: * This product includes software developed by the University of * California, Berkeley and its contributors. * 4. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */ #ifndef lint #if 0 static char sccsid[] = "@(#)keyword.c 8.5 (Berkeley) 4/2/94"; #else static const char rcsid[] = "$FreeBSD$"; #endif #endif /* not lint */ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include "ps.h" static VAR *findvar __P((char *)); static int vcmp __P((const void *, const void *)); #ifdef NOTINUSE int utime(), stime(), ixrss(), idrss(), isrss(); {{"utime"}, "UTIME", USER, utime, NULL, 4}, {{"stime"}, "STIME", USER, stime, NULL, 4}, {{"ixrss"}, "IXRSS", USER, ixrss, NULL, 4}, {{"idrss"}, "IDRSS", USER, idrss, NULL, 4}, {{"isrss"}, "ISRSS", USER, isrss, NULL, 4}, #endif /* Compute offset in common structures. */ #define POFF(x) offsetof(struct proc, x) #define EOFF(x) offsetof(struct eproc, x) #define UOFF(x) offsetof(struct usave, x) #define ROFF(x) offsetof(struct rusage, x) #define UIDFMT "u" #define UIDLEN 5 #define PIDFMT "d" #define PIDLEN 5 #define USERLEN UT_NAMESIZE VAR var[] = { {"%cpu", "%CPU", NULL, 0, pcpu, NULL, 4}, {"%mem", "%MEM", NULL, 0, pmem, NULL, 4}, {"acflag", "ACFLG", NULL, 0, pvar, NULL, 3, POFF(p_acflag), USHORT, "x"}, {"acflg", "", "acflag"}, {"blocked", "", "sigmask"}, {"caught", "", "sigcatch"}, {"command", "COMMAND", NULL, COMM|LJUST|USER, command, NULL, 16}, {"cpu", "CPU", NULL, 0, pvar, NULL, 3, POFF(p_estcpu), UINT, "d"}, {"cputime", "", "time"}, {"f", "F", NULL, 0, pvar, NULL, 7, POFF(p_flag), INT, "x"}, {"flags", "", "f"}, {"ignored", "", "sigignore"}, {"inblk", "INBLK", NULL, USER, rvar, NULL, 4, ROFF(ru_inblock), LONG, "ld"}, {"inblock", "", "inblk"}, {"jobc", "JOBC", NULL, 0, evar, NULL, 4, EOFF(e_jobc), SHORT, "d"}, {"ktrace", "KTRACE", NULL, 0, pvar, NULL, 8, POFF(p_traceflag), INT, "x"}, {"ktracep", "KTRACEP", NULL, 0, pvar, NULL, 8, POFF(p_tracep), LONG, "lx"}, {"lim", "LIM", NULL, 0, maxrss, NULL, 5}, {"login", "LOGIN", NULL, LJUST, logname, NULL, MAXLOGNAME-1}, {"logname", "", "login"}, {"lstart", "STARTED", NULL, LJUST|USER, lstarted, NULL, 28}, {"majflt", "MAJFLT", NULL, USER, rvar, NULL, 4, ROFF(ru_majflt), LONG, "ld"}, {"minflt", "MINFLT", NULL, USER, rvar, NULL, 4, ROFF(ru_minflt), LONG, "ld"}, {"msgrcv", "MSGRCV", NULL, USER, rvar, NULL, 4, ROFF(ru_msgrcv), LONG, "ld"}, {"msgsnd", "MSGSND", NULL, USER, rvar, NULL, 4, ROFF(ru_msgsnd), LONG, "ld"}, {"ni", "", "nice"}, {"nice", "NI", NULL, 0, pvar, NULL, 2, POFF(p_nice), CHAR, "d"}, {"nivcsw", "NIVCSW", NULL, USER, rvar, NULL, 5, ROFF(ru_nivcsw), LONG, "ld"}, {"nsignals", "", "nsigs"}, {"nsigs", "NSIGS", NULL, USER, rvar, NULL, 4, ROFF(ru_nsignals), LONG, "ld"}, {"nswap", "NSWAP", NULL, USER, rvar, NULL, 4, ROFF(ru_nswap), LONG, "ld"}, {"nvcsw", "NVCSW", NULL, USER, rvar, NULL, 5, ROFF(ru_nvcsw), LONG, "ld"}, - {"nwchan", "WCHAN", NULL, 0, pvar, NULL, 6, POFF(p_wchan), KPTR, "lx"}, + {"nwchan", "WCHAN", NULL, 0, pvar, NULL, 8, POFF(p_wchan), KPTR, "lx"}, {"oublk", "OUBLK", NULL, USER, rvar, NULL, 4, ROFF(ru_oublock), LONG, "ld"}, {"oublock", "", "oublk"}, {"p_ru", "P_RU", NULL, 0, pvar, NULL, 6, POFF(p_ru), KPTR, "lx"}, - {"paddr", "PADDR", NULL, 0, evar, NULL, 6, EOFF(e_paddr), KPTR, "lx"}, + {"paddr", "PADDR", NULL, 0, evar, NULL, 8, EOFF(e_paddr), KPTR, "lx"}, {"pagein", "PAGEIN", NULL, USER, pagein, NULL, 6}, {"pcpu", "", "%cpu"}, {"pending", "", "sig"}, {"pgid", "PGID", NULL, 0, evar, NULL, PIDLEN, EOFF(e_pgid), UINT, PIDFMT}, {"pid", "PID", NULL, 0, pvar, NULL, PIDLEN, POFF(p_pid), UINT, PIDFMT}, {"pmem", "", "%mem"}, {"ppid", "PPID", NULL, 0, evar, NULL, PIDLEN, EOFF(e_ppid), UINT, PIDFMT}, {"pri", "PRI", NULL, 0, pri, NULL, 3}, {"re", "RE", NULL, 0, pvar, NULL, 3, POFF(p_swtime), UINT, "d"}, {"rgid", "RGID", NULL, 0, evar, NULL, UIDLEN, EOFF(e_pcred.p_rgid), UINT, UIDFMT}, {"rlink", "RLINK", NULL, 0, pvar, NULL, 8, POFF(p_procq.tqe_prev), KPTR, "lx"}, {"rss", "RSS", NULL, 0, p_rssize, NULL, 4}, {"rssize", "", "rsz"}, {"rsz", "RSZ", NULL, 0, rssize, NULL, 4}, {"rtprio", "RTPRIO", NULL, 0, rtprior, NULL, 7, POFF(p_rtprio)}, {"ruid", "RUID", NULL, 0, evar, NULL, UIDLEN, EOFF(e_pcred.p_ruid), UINT, UIDFMT}, {"ruser", "RUSER", NULL, LJUST|DSIZ, runame, s_runame, USERLEN}, {"sess", "SESS", NULL, 0, evar, NULL, 6, EOFF(e_sess), KPTR, "lx"}, {"sig", "PENDING", NULL, 0, pvar, NULL, 8, POFF(p_siglist), INT, "x"}, {"sigcatch", "CAUGHT", NULL, 0, evar, NULL, 8, EOFF(e_procsig.ps_sigcatch), UINT, "x"}, {"sigignore", "IGNORED", NULL, 0, evar, NULL, 8, EOFF(e_procsig.ps_sigignore), UINT, "x"}, {"sigmask", "BLOCKED", NULL, 0, pvar, NULL, 8, POFF(p_sigmask), UINT, "x"}, {"sl", "SL", NULL, 0, pvar, NULL, 3, POFF(p_slptime), UINT, "d"}, {"start", "STARTED", NULL, LJUST|USER, started, NULL, 7}, {"stat", "", "state"}, {"state", "STAT", NULL, 0, state, NULL, 4}, {"svgid", "SVGID", NULL, 0, evar, NULL, UIDLEN, EOFF(e_pcred.p_svgid), UINT, UIDFMT}, {"svuid", "SVUID", NULL, 0, evar, NULL, UIDLEN, EOFF(e_pcred.p_svuid), UINT, UIDFMT}, {"tdev", "TDEV", NULL, 0, tdev, NULL, 4}, {"time", "TIME", NULL, USER, cputime, NULL, 9}, {"tpgid", "TPGID", NULL, 0, evar, NULL, 4, EOFF(e_tpgid), UINT, PIDFMT}, {"tsess", "TSESS", NULL, 0, evar, NULL, 6, EOFF(e_tsess), KPTR, "lx"}, {"tsiz", "TSIZ", NULL, 0, tsize, NULL, 4}, {"tt", "TT ", NULL, 0, tname, NULL, 4}, {"tty", "TTY", NULL, LJUST, longtname, NULL, 8}, {"ucomm", "UCOMM", NULL, LJUST, ucomm, NULL, MAXCOMLEN}, {"uid", "UID", NULL, 0, evar, NULL, UIDLEN, EOFF(e_ucred.cr_uid), UINT, UIDFMT}, {"upr", "UPR", NULL, 0, pvar, NULL, 3, POFF(p_usrpri), CHAR, "d"}, {"user", "USER", NULL, LJUST|DSIZ, uname, s_uname, USERLEN}, {"usrpri", "", "upr"}, {"vsize", "", "vsz"}, {"vsz", "VSZ", NULL, 0, vsize, NULL, 5}, {"wchan", "WCHAN", NULL, LJUST, wchan, NULL, 6}, {"xstat", "XSTAT", NULL, 0, pvar, NULL, 4, POFF(p_xstat), USHORT, "x"}, {""}, }; void showkey() { VAR *v; int i; char *p, *sep; i = 0; sep = ""; for (v = var; *(p = v->name); ++v) { int len = strlen(p); if (termwidth && (i += len + 1) > termwidth) { i = len; sep = "\n"; } (void) printf("%s%s", sep, p); sep = " "; } (void) printf("\n"); } void parsefmt(p) char *p; { static struct varent *vtail; #define FMTSEP " \t,\n" while (p && *p) { char *cp; VAR *v; struct varent *vent; while ((cp = strsep(&p, FMTSEP)) != NULL && *cp == '\0') /* void */; if (cp == NULL || !(v = findvar(cp))) continue; if ((vent = malloc(sizeof(struct varent))) == NULL) err(1, NULL); vent->var = v; vent->next = NULL; if (vhead == NULL) vhead = vtail = vent; else { vtail->next = vent; vtail = vent; } } if (!vhead) errx(1, "no valid keywords"); } static VAR * findvar(p) char *p; { VAR *v, key; char *hp; int vcmp(); hp = strchr(p, '='); if (hp) *hp++ = '\0'; key.name = p; v = bsearch(&key, var, sizeof(var)/sizeof(VAR) - 1, sizeof(VAR), vcmp); if (v && v->alias) { if (hp) { warnx("%s: illegal keyword specification", p); eval = 1; } parsefmt(v->alias); return ((VAR *)NULL); } if (!v) { warnx("%s: keyword not found", p); eval = 1; } else if (hp) v->header = hp; return (v); } static int vcmp(a, b) const void *a, *b; { return (strcmp(((VAR *)a)->name, ((VAR *)b)->name)); } Index: stable/4/bin/ps/print.c =================================================================== --- stable/4/bin/ps/print.c (revision 83753) +++ stable/4/bin/ps/print.c (revision 83754) @@ -1,730 +1,730 @@ /*- * Copyright (c) 1990, 1993, 1994 * The Regents of the University of California. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. All advertising materials mentioning features or use of this software * must display the following acknowledgement: * This product includes software developed by the University of * California, Berkeley and its contributors. * 4. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */ #ifndef lint #if 0 static char sccsid[] = "@(#)print.c 8.6 (Berkeley) 4/16/94"; #endif static const char rcsid[] = "$FreeBSD$"; #endif /* not lint */ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include "ps.h" void printheader() { VAR *v; struct varent *vent; for (vent = vhead; vent; vent = vent->next) { v = vent->var; if (v->flag & LJUST) { if (vent->next == NULL) /* last one */ (void)printf("%s", v->header); else (void)printf("%-*s", v->width, v->header); } else (void)printf("%*s", v->width, v->header); if (vent->next != NULL) (void)putchar(' '); } (void)putchar('\n'); } void command(k, ve) KINFO *k; VARENT *ve; { VAR *v; int left; char *cp, *vis_env, *vis_args; v = ve->var; if (cflag) { if (ve->next == NULL) /* last field, don't pad */ (void)printf("%s", KI_PROC(k)->p_comm); else (void)printf("%-*s", v->width, KI_PROC(k)->p_comm); return; } if ((vis_args = malloc(strlen(k->ki_args) * 4 + 1)) == NULL) err(1, NULL); strvis(vis_args, k->ki_args, VIS_TAB | VIS_NL | VIS_NOSLASH); if (k->ki_env) { if ((vis_env = malloc(strlen(k->ki_env) * 4 + 1)) == NULL) err(1, NULL); strvis(vis_env, k->ki_env, VIS_TAB | VIS_NL | VIS_NOSLASH); } else vis_env = NULL; if (ve->next == NULL) { /* last field */ if (termwidth == UNLIMITED) { if (vis_env) (void)printf("%s ", vis_env); (void)printf("%s", vis_args); } else { left = termwidth - (totwidth - v->width); if (left < 1) /* already wrapped, just use std width */ left = v->width; if ((cp = vis_env) != NULL) { while (--left >= 0 && *cp) (void)putchar(*cp++); if (--left >= 0) putchar(' '); } for (cp = vis_args; --left >= 0 && *cp != '\0';) (void)putchar(*cp++); } } else /* XXX env? */ (void)printf("%-*.*s", v->width, v->width, vis_args); free(vis_args); if (vis_env != NULL) free(vis_env); } void ucomm(k, ve) KINFO *k; VARENT *ve; { VAR *v; v = ve->var; (void)printf("%-*s", v->width, KI_PROC(k)->p_comm); } void logname(k, ve) KINFO *k; VARENT *ve; { VAR *v; char *s; v = ve->var; (void)printf("%-*s", v->width, (s = KI_EPROC(k)->e_login, *s) ? s : "-"); } void state(k, ve) KINFO *k; VARENT *ve; { struct proc *p; int flag; char *cp; VAR *v; char buf[16]; v = ve->var; p = KI_PROC(k); flag = p->p_flag; cp = buf; switch (p->p_stat) { case SSTOP: *cp = 'T'; break; case SSLEEP: if (flag & P_SINTR) /* interruptable (long) */ *cp = p->p_slptime >= MAXSLP ? 'I' : 'S'; else *cp = 'D'; break; case SRUN: case SIDL: *cp = 'R'; break; case SZOMB: *cp = 'Z'; break; default: *cp = '?'; } cp++; if (!(flag & P_INMEM)) *cp++ = 'W'; if (p->p_nice < NZERO) *cp++ = '<'; else if (p->p_nice > NZERO) *cp++ = 'N'; if (flag & P_TRACED) *cp++ = 'X'; if (flag & P_WEXIT && p->p_stat != SZOMB) *cp++ = 'E'; if (flag & P_PPWAIT) *cp++ = 'V'; if ((flag & P_SYSTEM) || p->p_lock > 0) *cp++ = 'L'; if (KI_EPROC(k)->e_flag & EPROC_SLEADER) *cp++ = 's'; if ((flag & P_CONTROLT) && KI_EPROC(k)->e_pgid == KI_EPROC(k)->e_tpgid) *cp++ = '+'; if (flag & P_JAILED) *cp++ = 'J'; *cp = '\0'; (void)printf("%-*s", v->width, buf); } void pri(k, ve) KINFO *k; VARENT *ve; { VAR *v; v = ve->var; (void)printf("%*d", v->width, KI_PROC(k)->p_priority - PZERO); } void uname(k, ve) KINFO *k; VARENT *ve; { VAR *v; v = ve->var; (void)printf("%-*s", (int)v->width, user_from_uid(KI_EPROC(k)->e_ucred.cr_uid, 0)); } int s_uname(k) KINFO *k; { return (strlen(user_from_uid(KI_EPROC(k)->e_ucred.cr_uid, 0))); } void runame(k, ve) KINFO *k; VARENT *ve; { VAR *v; v = ve->var; (void)printf("%-*s", (int)v->width, user_from_uid(KI_EPROC(k)->e_pcred.p_ruid, 0)); } int s_runame(k) KINFO *k; { return (strlen(user_from_uid(KI_EPROC(k)->e_pcred.p_ruid, 0))); } void tdev(k, ve) KINFO *k; VARENT *ve; { VAR *v; dev_t dev; char buff[16]; v = ve->var; dev = KI_EPROC(k)->e_tdev; if (dev == NODEV) (void)printf("%*s", v->width, "??"); else { (void)snprintf(buff, sizeof(buff), "%d/%d", major(dev), minor(dev)); (void)printf("%*s", v->width, buff); } } void tname(k, ve) KINFO *k; VARENT *ve; { VAR *v; dev_t dev; char *ttname; v = ve->var; dev = KI_EPROC(k)->e_tdev; if (dev == NODEV || (ttname = devname(dev, S_IFCHR)) == NULL) (void)printf("%*s ", v->width-1, "??"); else { if (strncmp(ttname, "tty", 3) == 0 || strncmp(ttname, "cua", 3) == 0) ttname += 3; (void)printf("%*.*s%c", v->width-1, v->width-1, ttname, KI_EPROC(k)->e_flag & EPROC_CTTY ? ' ' : '-'); } } void longtname(k, ve) KINFO *k; VARENT *ve; { VAR *v; dev_t dev; char *ttname; v = ve->var; dev = KI_EPROC(k)->e_tdev; if (dev == NODEV || (ttname = devname(dev, S_IFCHR)) == NULL) (void)printf("%-*s", v->width, "??"); else (void)printf("%-*s", v->width, ttname); } void started(k, ve) KINFO *k; VARENT *ve; { VAR *v; static time_t now; time_t then; struct tm *tp; char buf[100]; v = ve->var; if (!k->ki_u.u_valid) { (void)printf("%-*s", v->width, "-"); return; } then = k->ki_u.u_start.tv_sec; tp = localtime(&then); if (!now) (void)time(&now); if (now - k->ki_u.u_start.tv_sec < 24 * 3600) { /* I *hate* SCCS... */ static char fmt[] = __CONCAT("%l:%", "M%p"); (void)strftime(buf, sizeof(buf) - 1, fmt, tp); } else if (now - k->ki_u.u_start.tv_sec < 7 * 86400) { /* I *hate* SCCS... */ static char fmt[] = __CONCAT("%a%", "I%p"); (void)strftime(buf, sizeof(buf) - 1, fmt, tp); } else (void)strftime(buf, sizeof(buf) - 1, "%e%b%y", tp); (void)printf("%-*s", v->width, buf); } void lstarted(k, ve) KINFO *k; VARENT *ve; { VAR *v; time_t then; char buf[100]; v = ve->var; if (!k->ki_u.u_valid) { (void)printf("%-*s", v->width, "-"); return; } then = k->ki_u.u_start.tv_sec; (void)strftime(buf, sizeof(buf) -1, "%c", localtime(&then)); (void)printf("%-*s", v->width, buf); } void wchan(k, ve) KINFO *k; VARENT *ve; { VAR *v; v = ve->var; if (KI_PROC(k)->p_wchan) { if (KI_PROC(k)->p_wmesg) (void)printf("%-*.*s", v->width, v->width, KI_EPROC(k)->e_wmesg); else (void)printf("%-*lx", v->width, - (long)KI_PROC(k)->p_wchan &~ KERNBASE); + (long)KI_PROC(k)->p_wchan); } else (void)printf("%-*s", v->width, "-"); } #ifndef pgtok #define pgtok(a) (((a)*getpagesize())/1024) #endif void vsize(k, ve) KINFO *k; VARENT *ve; { VAR *v; v = ve->var; (void)printf("%*d", v->width, (KI_EPROC(k)->e_vm.vm_map.size/1024)); } void rssize(k, ve) KINFO *k; VARENT *ve; { VAR *v; v = ve->var; /* XXX don't have info about shared */ (void)printf("%*lu", v->width, (u_long)pgtok(KI_EPROC(k)->e_vm.vm_rssize)); } void p_rssize(k, ve) /* doesn't account for text */ KINFO *k; VARENT *ve; { VAR *v; v = ve->var; (void)printf("%*ld", v->width, (long)pgtok(KI_EPROC(k)->e_vm.vm_rssize)); } void cputime(k, ve) KINFO *k; VARENT *ve; { VAR *v; long secs; long psecs; /* "parts" of a second. first micro, then centi */ char obuff[128]; v = ve->var; if (KI_PROC(k)->p_stat == SZOMB || !k->ki_u.u_valid) { secs = 0; psecs = 0; } else { /* * This counts time spent handling interrupts. We could * fix this, but it is not 100% trivial (and interrupt * time fractions only work on the sparc anyway). XXX */ secs = KI_PROC(k)->p_runtime / 1000000; psecs = KI_PROC(k)->p_runtime % 1000000; 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; } /* * round and scale to 100's */ psecs = (psecs + 5000) / 10000; secs += psecs / 100; psecs = psecs % 100; } (void)snprintf(obuff, sizeof(obuff), "%3ld:%02ld.%02ld", secs/60, secs%60, psecs); (void)printf("%*s", v->width, obuff); } double getpcpu(k) KINFO *k; { struct proc *p; static int failure; if (!nlistread) failure = donlist(); if (failure) return (0.0); p = KI_PROC(k); #define fxtofl(fixpt) ((double)(fixpt) / fscale) /* XXX - I don't like this */ if (p->p_swtime == 0 || (p->p_flag & P_INMEM) == 0) return (0.0); if (rawcpu) return (100.0 * fxtofl(p->p_pctcpu)); return (100.0 * fxtofl(p->p_pctcpu) / (1.0 - exp(p->p_swtime * log(fxtofl(ccpu))))); } void pcpu(k, ve) KINFO *k; VARENT *ve; { VAR *v; v = ve->var; (void)printf("%*.1f", v->width, getpcpu(k)); } double getpmem(k) KINFO *k; { static int failure; struct proc *p; struct eproc *e; double fracmem; int szptudot; if (!nlistread) failure = donlist(); if (failure) return (0.0); p = KI_PROC(k); e = KI_EPROC(k); if ((p->p_flag & P_INMEM) == 0) return (0.0); /* XXX want pmap ptpages, segtab, etc. (per architecture) */ szptudot = UPAGES; /* XXX don't have info about shared */ fracmem = ((float)e->e_vm.vm_rssize + szptudot)/mempages; return (100.0 * fracmem); } void pmem(k, ve) KINFO *k; VARENT *ve; { VAR *v; v = ve->var; (void)printf("%*.1f", v->width, getpmem(k)); } void pagein(k, ve) KINFO *k; VARENT *ve; { VAR *v; v = ve->var; (void)printf("%*ld", v->width, k->ki_u.u_valid ? k->ki_u.u_ru.ru_majflt : 0); } void maxrss(k, ve) KINFO *k; VARENT *ve; { VAR *v; v = ve->var; /* XXX not yet */ (void)printf("%*s", v->width, "-"); } void tsize(k, ve) KINFO *k; VARENT *ve; { VAR *v; v = ve->var; (void)printf("%*ld", v->width, (long)pgtok(KI_EPROC(k)->e_vm.vm_tsize)); } void rtprior(k, ve) KINFO *k; VARENT *ve; { VAR *v; struct rtprio *prtp; char str[8]; unsigned prio, type; v = ve->var; prtp = (struct rtprio *) ((char *)KI_PROC(k) + v->off); prio = prtp->prio; type = prtp->type; switch (type) { case RTP_PRIO_REALTIME: snprintf(str, sizeof(str), "real:%u", prio); break; case RTP_PRIO_NORMAL: strncpy(str, "normal", sizeof(str)); break; case RTP_PRIO_IDLE: snprintf(str, sizeof(str), "idle:%u", prio); break; default: snprintf(str, sizeof(str), "%u:%u", type, prio); break; } str[sizeof(str) - 1] = '\0'; (void)printf("%*s", v->width, str); } /* * Generic output routines. Print fields from various prototype * structures. */ static void printval(bp, v) char *bp; VAR *v; { static char ofmt[32] = "%"; char *fcp, *cp; cp = ofmt + 1; fcp = v->fmt; if (v->flag & LJUST) *cp++ = '-'; *cp++ = '*'; while ((*cp++ = *fcp++)); switch (v->type) { case CHAR: (void)printf(ofmt, v->width, *(char *)bp); break; case UCHAR: (void)printf(ofmt, v->width, *(u_char *)bp); break; case SHORT: (void)printf(ofmt, v->width, *(short *)bp); break; case USHORT: (void)printf(ofmt, v->width, *(u_short *)bp); break; case INT: (void)printf(ofmt, v->width, *(int *)bp); break; case UINT: (void)printf(ofmt, v->width, *(u_int *)bp); break; case LONG: (void)printf(ofmt, v->width, *(long *)bp); break; case ULONG: (void)printf(ofmt, v->width, *(u_long *)bp); break; case KPTR: - (void)printf(ofmt, v->width, *(u_long *)bp &~ KERNBASE); + (void)printf(ofmt, v->width, *(u_long *)bp); break; default: errx(1, "unknown type %d", v->type); } } void pvar(k, ve) KINFO *k; VARENT *ve; { VAR *v; v = ve->var; printval((char *)((char *)KI_PROC(k) + v->off), v); } void evar(k, ve) KINFO *k; VARENT *ve; { VAR *v; v = ve->var; printval((char *)((char *)KI_EPROC(k) + v->off), v); } void uvar(k, ve) KINFO *k; VARENT *ve; { VAR *v; v = ve->var; if (k->ki_u.u_valid) printval((char *)((char *)&k->ki_u + v->off), v); else (void)printf("%*s", v->width, "-"); } void rvar(k, ve) KINFO *k; VARENT *ve; { VAR *v; v = ve->var; if (k->ki_u.u_valid) printval((char *)((char *)(&k->ki_u.u_ru) + v->off), v); else (void)printf("%*s", v->width, "-"); }