NetBSD/bin/ps/print.c

743 lines
14 KiB
C
Raw Normal View History

1993-03-21 12:45:37 +03:00
/*-
1994-05-09 07:31:07 +04:00
* Copyright (c) 1990, 1993, 1994
* The Regents of the University of California. All rights reserved.
1993-03-21 12:45:37 +03:00
*
* 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
1994-05-09 07:31:07 +04:00
static char sccsid[] = "@(#)print.c 8.6 (Berkeley) 4/16/94";
1993-03-21 12:45:37 +03:00
#endif /* not lint */
#include <sys/param.h>
#include <sys/time.h>
#include <sys/resource.h>
#include <sys/proc.h>
#include <sys/stat.h>
1994-05-05 06:04:10 +04:00
#ifdef P_PPWAIT
1993-03-21 12:45:37 +03:00
#define NEWVM
#endif
#ifdef NEWVM
#include <sys/ucred.h>
1994-05-09 07:31:07 +04:00
#include <sys/sysctl.h>
#include <vm/vm.h>
1993-03-21 12:45:37 +03:00
#else
#include <machine/pte.h>
#include <sys/vmparam.h>
#include <sys/vm.h>
#endif
1994-05-09 07:31:07 +04:00
#include <err.h>
#include <math.h>
#include <nlist.h>
#include <stddef.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <vis.h>
#include <tzfile.h>
#include "ps.h"
void
1993-03-21 12:45:37 +03:00
printheader()
{
1994-05-09 07:31:07 +04:00
VAR *v;
struct varent *vent;
1993-03-21 12:45:37 +03:00
for (vent = vhead; vent; vent = vent->next) {
v = vent->var;
if (v->flag & LJUST) {
if (vent->next == NULL) /* last one */
1994-05-09 07:31:07 +04:00
(void)printf("%s", v->header);
1993-03-21 12:45:37 +03:00
else
1994-05-09 07:31:07 +04:00
(void)printf("%-*s", v->width, v->header);
1993-03-21 12:45:37 +03:00
} else
1994-05-09 07:31:07 +04:00
(void)printf("%*s", v->width, v->header);
1993-03-21 12:45:37 +03:00
if (vent->next != NULL)
1994-05-09 07:31:07 +04:00
(void)putchar(' ');
1993-03-21 12:45:37 +03:00
}
1994-05-09 07:31:07 +04:00
(void)putchar('\n');
1993-03-21 12:45:37 +03:00
}
1994-05-09 07:31:07 +04:00
void
command(k, ve)
1993-03-21 12:45:37 +03:00
KINFO *k;
1994-05-09 07:31:07 +04:00
VARENT *ve;
1993-03-21 12:45:37 +03:00
{
1994-05-09 07:31:07 +04:00
VAR *v;
int left;
char *cp, *vis_env, *vis_args;
1994-05-09 07:31:07 +04:00
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) {
1994-05-09 07:31:07 +04:00
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;
1993-03-21 12:45:37 +03:00
1994-05-09 07:31:07 +04:00
v = ve->var;
if (ve->next == NULL) {
1993-03-21 12:45:37 +03:00
/* last field */
if (termwidth == UNLIMITED) {
if (vis_env)
(void)printf("%s ", vis_env);
1994-05-09 07:31:07 +04:00
(void)printf("%s", vis_args);
} else {
1994-05-09 07:31:07 +04:00
left = termwidth - (totwidth - v->width);
1993-03-21 12:45:37 +03:00
if (left < 1) /* already wrapped, just use std width */
left = v->width;
1994-05-09 07:31:07 +04:00
if ((cp = vis_env) != NULL) {
while (--left >= 0 && *cp)
(void)putchar(*cp++);
if (--left >= 0)
putchar(' ');
}
1994-05-09 07:31:07 +04:00
for (cp = vis_args; --left >= 0 && *cp != '\0';)
(void)putchar(*cp++);
1993-03-21 12:45:37 +03:00
}
} else
1994-05-09 07:31:07 +04:00
/* XXX env? */
(void)printf("%-*.*s", v->width, v->width, vis_args);
free(vis_args);
if (vis_env != NULL)
free(vis_env);
1993-03-21 12:45:37 +03:00
}
1994-05-09 07:31:07 +04:00
void
ucomm(k, ve)
1993-03-21 12:45:37 +03:00
KINFO *k;
1994-05-09 07:31:07 +04:00
VARENT *ve;
1993-03-21 12:45:37 +03:00
{
1994-05-09 07:31:07 +04:00
VAR *v;
v = ve->var;
(void)printf("%-*s", v->width, KI_PROC(k)->p_comm);
1993-03-21 12:45:37 +03:00
}
1994-05-09 07:31:07 +04:00
void
logname(k, ve)
1993-03-21 12:45:37 +03:00
KINFO *k;
1994-05-09 07:31:07 +04:00
VARENT *ve;
1993-03-21 12:45:37 +03:00
{
1994-05-09 07:31:07 +04:00
VAR *v;
v = ve->var;
1993-03-21 12:45:37 +03:00
#ifndef NEWVM
1994-05-09 07:31:07 +04:00
(void)printf("%-*s", v->width, KI_PROC(k)->p_logname);
#else
(void)printf("%-*s", v->width, KI_EPROC(k)->e_login);
#endif
1993-03-21 12:45:37 +03:00
}
1994-05-09 07:31:07 +04:00
void
state(k, ve)
1993-03-21 12:45:37 +03:00
KINFO *k;
1994-05-09 07:31:07 +04:00
VARENT *ve;
1993-03-21 12:45:37 +03:00
{
1994-05-09 07:31:07 +04:00
struct proc *p;
int flag;
char *cp;
VAR *v;
1993-03-21 12:45:37 +03:00
char buf[16];
1994-05-09 07:31:07 +04:00
v = ve->var;
p = KI_PROC(k);
flag = p->p_flag;
cp = buf;
1993-03-21 12:45:37 +03:00
switch (p->p_stat) {
case SSTOP:
*cp = 'T';
break;
case SSLEEP:
1994-05-05 06:04:10 +04:00
if (flag & P_SINTR) /* interuptable (long) */
1993-03-21 12:45:37 +03:00
*cp = p->p_slptime >= MAXSLP ? 'I' : 'S';
else
1994-05-05 06:04:10 +04:00
*cp = 'D';
1993-03-21 12:45:37 +03:00
break;
case SRUN:
case SIDL:
*cp = 'R';
break;
case SZOMB:
*cp = 'Z';
break;
default:
*cp = '?';
}
cp++;
1994-05-05 06:04:10 +04:00
if (flag & P_INMEM) {
1993-03-21 12:45:37 +03:00
#ifndef NEWVM
if (p->p_rssize > p->p_maxrss)
*cp++ = '>';
#endif
} else
*cp++ = 'W';
if (p->p_nice < NZERO)
*cp++ = '<';
else if (p->p_nice > NZERO)
*cp++ = 'N';
#ifndef NEWVM
if (flag & SUANOM)
*cp++ = 'A';
else if (flag & SSEQL)
*cp++ = 'S';
#endif
1994-05-05 06:04:10 +04:00
if (flag & P_TRACED)
1993-03-21 12:45:37 +03:00
*cp++ = 'X';
1994-05-05 06:04:10 +04:00
if (flag & P_WEXIT && p->p_stat != SZOMB)
1993-03-21 12:45:37 +03:00
*cp++ = 'E';
#ifdef NEWVM
1994-05-05 06:04:10 +04:00
if (flag & P_PPWAIT)
1993-03-21 12:45:37 +03:00
#else
if (flag & SVFORK)
#endif
*cp++ = 'V';
#ifdef NEWVM
1994-06-16 23:30:50 +04:00
if ((flag & P_SYSTEM) || p->p_holdcnt)
1993-03-21 12:45:37 +03:00
#else
1994-05-09 07:31:07 +04:00
if (flag & (SSYS|SLOCK|SULOCK|SKEEP|SPHYSIO))
1993-03-21 12:45:37 +03:00
#endif
*cp++ = 'L';
1994-05-09 07:31:07 +04:00
if (KI_EPROC(k)->e_flag & EPROC_SLEADER)
1993-03-21 12:45:37 +03:00
*cp++ = 's';
1994-05-09 07:31:07 +04:00
if ((flag & P_CONTROLT) && KI_EPROC(k)->e_pgid == KI_EPROC(k)->e_tpgid)
1993-03-21 12:45:37 +03:00
*cp++ = '+';
*cp = '\0';
1994-05-09 07:31:07 +04:00
(void)printf("%-*s", v->width, buf);
1993-03-21 12:45:37 +03:00
}
1994-05-09 07:31:07 +04:00
void
pri(k, ve)
1993-03-21 12:45:37 +03:00
KINFO *k;
1994-05-09 07:31:07 +04:00
VARENT *ve;
1993-03-21 12:45:37 +03:00
{
1994-05-09 07:31:07 +04:00
VAR *v;
v = ve->var;
(void)printf("%*d", v->width, KI_PROC(k)->p_priority - PZERO);
1993-03-21 12:45:37 +03:00
}
1994-05-09 07:31:07 +04:00
void
uname(k, ve)
1993-03-21 12:45:37 +03:00
KINFO *k;
1994-05-09 07:31:07 +04:00
VARENT *ve;
1993-03-21 12:45:37 +03:00
{
1994-05-09 07:31:07 +04:00
VAR *v;
v = ve->var;
1993-03-21 12:45:37 +03:00
#ifndef NEWVM
1994-05-09 07:31:07 +04:00
(void)printf("%-*s",
(int)v->width, user_from_uid(KI_PROC(k)->p_uid, 0));
#else
(void)printf("%-*s",
(int)v->width, user_from_uid(KI_EPROC(k)->e_ucred.cr_uid, 0));
#endif
1993-03-21 12:45:37 +03:00
}
1994-05-09 07:31:07 +04:00
void
runame(k, ve)
1993-03-21 12:45:37 +03:00
KINFO *k;
1994-05-09 07:31:07 +04:00
VARENT *ve;
1993-03-21 12:45:37 +03:00
{
1994-05-09 07:31:07 +04:00
VAR *v;
v = ve->var;
1993-03-21 12:45:37 +03:00
#ifndef NEWVM
1994-05-09 07:31:07 +04:00
(void)printf("%-*s",
(int)v->width, user_from_uid(KI_PROC(k)->p_ruid, 0));
#else
(void)printf("%-*s",
(int)v->width, user_from_uid(KI_EPROC(k)->e_pcred.p_ruid, 0));
#endif
1993-03-21 12:45:37 +03:00
}
1994-05-09 07:31:07 +04:00
void
tdev(k, ve)
1993-03-21 12:45:37 +03:00
KINFO *k;
1994-05-09 07:31:07 +04:00
VARENT *ve;
1993-03-21 12:45:37 +03:00
{
1994-05-09 07:31:07 +04:00
VAR *v;
dev_t dev;
char buff[16];
1993-03-21 12:45:37 +03:00
1994-05-09 07:31:07 +04:00
v = ve->var;
dev = KI_EPROC(k)->e_tdev;
1993-03-21 12:45:37 +03:00
if (dev == NODEV)
1994-05-09 07:31:07 +04:00
(void)printf("%*s", v->width, "??");
1993-03-21 12:45:37 +03:00
else {
1994-05-09 07:31:07 +04:00
(void)snprintf(buff, sizeof(buff),
"%d/%d", major(dev), minor(dev));
(void)printf("%*s", v->width, buff);
1993-03-21 12:45:37 +03:00
}
}
1994-05-09 07:31:07 +04:00
void
tname(k, ve)
1993-03-21 12:45:37 +03:00
KINFO *k;
1994-05-09 07:31:07 +04:00
VARENT *ve;
1993-03-21 12:45:37 +03:00
{
1994-05-09 07:31:07 +04:00
VAR *v;
1993-03-21 12:45:37 +03:00
dev_t dev;
1994-05-09 07:31:07 +04:00
char *ttname;
1993-03-21 12:45:37 +03:00
1994-05-09 07:31:07 +04:00
v = ve->var;
dev = KI_EPROC(k)->e_tdev;
1993-03-21 12:45:37 +03:00
if (dev == NODEV || (ttname = devname(dev, S_IFCHR)) == NULL)
1994-05-09 07:31:07 +04:00
(void)printf("%-*s", v->width, "??");
1993-03-21 12:45:37 +03:00
else {
if (strncmp(ttname, "tty", 3) == 0)
ttname += 3;
1994-05-09 07:31:07 +04:00
(void)printf("%*.*s%c", v->width-1, v->width-1, ttname,
KI_EPROC(k)->e_flag & EPROC_CTTY ? ' ' : '-');
1993-03-21 12:45:37 +03:00
}
}
1994-05-09 07:31:07 +04:00
void
longtname(k, ve)
1993-03-21 12:45:37 +03:00
KINFO *k;
1994-05-09 07:31:07 +04:00
VARENT *ve;
1993-03-21 12:45:37 +03:00
{
1994-05-09 07:31:07 +04:00
VAR *v;
1993-03-21 12:45:37 +03:00
dev_t dev;
1994-05-09 07:31:07 +04:00
char *ttname;
1993-03-21 12:45:37 +03:00
1994-05-09 07:31:07 +04:00
v = ve->var;
dev = KI_EPROC(k)->e_tdev;
1993-03-21 12:45:37 +03:00
if (dev == NODEV || (ttname = devname(dev, S_IFCHR)) == NULL)
1994-05-09 07:31:07 +04:00
(void)printf("%-*s", v->width, "??");
1993-03-21 12:45:37 +03:00
else
1994-05-09 07:31:07 +04:00
(void)printf("%-*s", v->width, ttname);
1993-03-21 12:45:37 +03:00
}
1994-05-09 07:31:07 +04:00
void
started(k, ve)
1993-03-21 12:45:37 +03:00
KINFO *k;
1994-05-09 07:31:07 +04:00
VARENT *ve;
1993-03-21 12:45:37 +03:00
{
1994-05-09 07:31:07 +04:00
VAR *v;
1993-03-21 12:45:37 +03:00
static time_t now;
struct tm *tp;
char buf[100];
1994-05-09 07:31:07 +04:00
v = ve->var;
if (!k->ki_u.u_valid) {
(void)printf("%-*s", v->width, "-");
1993-03-21 12:45:37 +03:00
return;
}
1994-05-09 07:31:07 +04:00
tp = localtime(&k->ki_u.u_start.tv_sec);
1993-03-21 12:45:37 +03:00
if (!now)
(void)time(&now);
1994-05-09 07:31:07 +04:00
if (now - k->ki_u.u_start.tv_sec < 24 * SECSPERHOUR) {
/* 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 * SECSPERDAY) {
/* I *hate* SCCS... */
static char fmt[] = __CONCAT("%a%", "I%p");
(void)strftime(buf, sizeof(buf) - 1, fmt, tp);
1993-03-21 12:45:37 +03:00
} else
1994-05-09 07:31:07 +04:00
(void)strftime(buf, sizeof(buf) - 1, "%e%b%y", tp);
(void)printf("%-*s", v->width, buf);
1993-03-21 12:45:37 +03:00
}
1994-05-09 07:31:07 +04:00
void
lstarted(k, ve)
1993-03-21 12:45:37 +03:00
KINFO *k;
1994-05-09 07:31:07 +04:00
VARENT *ve;
1993-03-21 12:45:37 +03:00
{
1994-05-09 07:31:07 +04:00
VAR *v;
1993-03-21 12:45:37 +03:00
char buf[100];
1994-05-09 07:31:07 +04:00
v = ve->var;
if (!k->ki_u.u_valid) {
(void)printf("%-*s", v->width, "-");
1993-03-21 12:45:37 +03:00
return;
}
1994-05-09 07:31:07 +04:00
(void)strftime(buf, sizeof(buf) -1, "%C",
localtime(&k->ki_u.u_start.tv_sec));
(void)printf("%-*s", v->width, buf);
1993-03-21 12:45:37 +03:00
}
1994-05-09 07:31:07 +04:00
void
wchan(k, ve)
1993-03-21 12:45:37 +03:00
KINFO *k;
1994-05-09 07:31:07 +04:00
VARENT *ve;
1993-03-21 12:45:37 +03:00
{
1994-05-09 07:31:07 +04:00
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);
1993-03-21 12:45:37 +03:00
else
1994-05-09 07:31:07 +04:00
(void)printf("%-*x", v->width,
(int)KI_PROC(k)->p_wchan &~ KERNBASE);
1993-03-21 12:45:37 +03:00
} else
1994-05-09 07:31:07 +04:00
(void)printf("%-*s", v->width, "-");
1993-03-21 12:45:37 +03:00
}
1994-09-15 06:00:34 +04:00
#define pgtok(a) (((a)*getpagesize())/1024)
1993-03-21 12:45:37 +03:00
1994-05-09 07:31:07 +04:00
void
vsize(k, ve)
1993-03-21 12:45:37 +03:00
KINFO *k;
1994-05-09 07:31:07 +04:00
VARENT *ve;
1993-03-21 12:45:37 +03:00
{
1994-05-09 07:31:07 +04:00
VAR *v;
v = ve->var;
(void)printf("%*d", v->width,
1993-03-21 12:45:37 +03:00
#ifndef NEWVM
1994-05-09 07:31:07 +04:00
pgtok(KI_PROC(k)->p_dsize +
KI_PROC(k)->p_ssize + KI_EPROC(k)->e_xsize));
#else
pgtok(KI_EPROC(k)->e_vm.vm_dsize + KI_EPROC(k)->e_vm.vm_ssize +
KI_EPROC(k)->e_vm.vm_tsize));
#endif
1993-03-21 12:45:37 +03:00
}
1994-05-09 07:31:07 +04:00
void
rssize(k, ve)
1993-03-21 12:45:37 +03:00
KINFO *k;
1994-05-09 07:31:07 +04:00
VARENT *ve;
1993-03-21 12:45:37 +03:00
{
1994-05-09 07:31:07 +04:00
VAR *v;
v = ve->var;
1993-03-21 12:45:37 +03:00
#ifndef NEWVM
1994-05-09 07:31:07 +04:00
(void)printf("%*d", v->width,
pgtok(KI_PROC(k)->p_rssize + (KI_EPROC(k)->e_xccount ?
(KI_EPROC(k)->e_xrssize / KI_EPROC(k)->e_xccount) : 0)));
#else
1993-03-21 12:45:37 +03:00
/* XXX don't have info about shared */
1994-05-09 07:31:07 +04:00
(void)printf("%*d", v->width, pgtok(KI_EPROC(k)->e_vm.vm_rssize));
#endif
1993-03-21 12:45:37 +03:00
}
1994-05-09 07:31:07 +04:00
void
p_rssize(k, ve) /* doesn't account for text */
1993-03-21 12:45:37 +03:00
KINFO *k;
1994-05-09 07:31:07 +04:00
VARENT *ve;
1993-03-21 12:45:37 +03:00
{
1994-05-09 07:31:07 +04:00
VAR *v;
v = ve->var;
1993-03-21 12:45:37 +03:00
#ifndef NEWVM
1994-05-09 07:31:07 +04:00
(void)printf("%*d", v->width, pgtok(KI_PROC(k)->p_rssize));
#else
(void)printf("%*d", v->width, pgtok(KI_EPROC(k)->e_vm.vm_rssize));
#endif
1993-03-21 12:45:37 +03:00
}
1994-05-09 07:31:07 +04:00
void
cputime(k, ve)
1993-03-21 12:45:37 +03:00
KINFO *k;
1994-05-09 07:31:07 +04:00
VARENT *ve;
1993-03-21 12:45:37 +03:00
{
1994-05-09 07:31:07 +04:00
VAR *v;
1993-03-21 12:45:37 +03:00
long secs;
long psecs; /* "parts" of a second. first micro, then centi */
char obuff[128];
1994-05-09 07:31:07 +04:00
v = ve->var;
if (KI_PROC(k)->p_stat == SZOMB || !k->ki_u.u_valid) {
1993-03-21 12:45:37 +03:00
secs = 0;
psecs = 0;
} else {
1994-05-09 07:31:07 +04:00
/*
* 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_rtime.tv_sec;
psecs = KI_PROC(k)->p_rtime.tv_usec;
1993-03-21 12:45:37 +03:00
if (sumrusage) {
1994-05-09 07:31:07 +04:00
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;
1993-03-21 12:45:37 +03:00
}
/*
* round and scale to 100's
*/
psecs = (psecs + 5000) / 10000;
secs += psecs / 100;
psecs = psecs % 100;
}
1994-05-09 07:31:07 +04:00
(void)snprintf(obuff, sizeof(obuff),
"%3ld:%02ld.%02ld", secs/60, secs%60, psecs);
(void)printf("%*s", v->width, obuff);
1993-03-21 12:45:37 +03:00
}
double
getpcpu(k)
KINFO *k;
{
struct proc *p;
static int failure;
if (!nlistread)
failure = donlist();
if (failure)
return (0.0);
1994-05-09 07:31:07 +04:00
p = KI_PROC(k);
1993-03-21 12:45:37 +03:00
#define fxtofl(fixpt) ((double)(fixpt) / fscale)
/* XXX - I don't like this */
1994-05-09 07:31:07 +04:00
if (p->p_swtime == 0 || (p->p_flag & P_INMEM) == 0)
1993-03-21 12:45:37 +03:00
return (0.0);
if (rawcpu)
return (100.0 * fxtofl(p->p_pctcpu));
return (100.0 * fxtofl(p->p_pctcpu) /
1994-05-05 10:44:24 +04:00
(1.0 - exp(p->p_swtime * log(fxtofl(ccpu)))));
1993-03-21 12:45:37 +03:00
}
1994-05-09 07:31:07 +04:00
void
pcpu(k, ve)
1993-03-21 12:45:37 +03:00
KINFO *k;
1994-05-09 07:31:07 +04:00
VARENT *ve;
1993-03-21 12:45:37 +03:00
{
1994-05-09 07:31:07 +04:00
VAR *v;
v = ve->var;
(void)printf("%*.1f", v->width, getpcpu(k));
1993-03-21 12:45:37 +03:00
}
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);
1994-05-09 07:31:07 +04:00
p = KI_PROC(k);
e = KI_EPROC(k);
if ((p->p_flag & P_INMEM) == 0)
1993-03-21 12:45:37 +03:00
return (0.0);
#ifndef NEWVM
1994-11-03 07:33:17 +03:00
szptudot = USPACE/getpagesize() +
clrnd(ctopt(p->p_dsize + p->p_ssize + e->e_xsize));
1993-03-21 12:45:37 +03:00
fracmem = ((float)p->p_rssize + szptudot)/CLSIZE/mempages;
if (p->p_textp && e->e_xccount)
fracmem += ((float)e->e_xrssize)/CLSIZE/e->e_xccount/mempages;
1994-05-09 07:31:07 +04:00
#else
1993-03-21 12:45:37 +03:00
/* XXX want pmap ptpages, segtab, etc. (per architecture) */
1994-11-03 07:33:17 +03:00
szptudot = USPACE/getpagesize();
1993-03-21 12:45:37 +03:00
/* XXX don't have info about shared */
fracmem = ((float)e->e_vm.vm_rssize + szptudot)/CLSIZE/mempages;
1994-05-09 07:31:07 +04:00
#endif
1993-03-21 12:45:37 +03:00
return (100.0 * fracmem);
}
1994-05-09 07:31:07 +04:00
void
pmem(k, ve)
1993-03-21 12:45:37 +03:00
KINFO *k;
1994-05-09 07:31:07 +04:00
VARENT *ve;
1993-03-21 12:45:37 +03:00
{
1994-05-09 07:31:07 +04:00
VAR *v;
v = ve->var;
(void)printf("%*.1f", v->width, getpmem(k));
1993-03-21 12:45:37 +03:00
}
1994-05-09 07:31:07 +04:00
void
pagein(k, ve)
1993-03-21 12:45:37 +03:00
KINFO *k;
1994-05-09 07:31:07 +04:00
VARENT *ve;
1993-03-21 12:45:37 +03:00
{
1994-05-09 07:31:07 +04:00
VAR *v;
v = ve->var;
(void)printf("%*d", v->width,
k->ki_u.u_valid ? k->ki_u.u_ru.ru_majflt : 0);
1993-03-21 12:45:37 +03:00
}
1994-05-09 07:31:07 +04:00
void
maxrss(k, ve)
1993-03-21 12:45:37 +03:00
KINFO *k;
1994-05-09 07:31:07 +04:00
VARENT *ve;
1993-03-21 12:45:37 +03:00
{
1994-05-09 07:31:07 +04:00
VAR *v;
v = ve->var;
1993-03-21 12:45:37 +03:00
#ifndef NEWVM /* not yet */
1994-09-15 06:00:34 +04:00
if (KI_PROC(k)->p_maxrss != (RLIM_INFINITY/getpagesize()))
1994-05-09 07:31:07 +04:00
(void)printf("%*d", v->width, pgtok(KI_PROC(k)->p_maxrss));
1993-03-21 12:45:37 +03:00
else
1994-05-09 07:31:07 +04:00
#endif
(void)printf("%*s", v->width, "-");
1993-03-21 12:45:37 +03:00
}
1994-05-09 07:31:07 +04:00
void
tsize(k, ve)
1993-03-21 12:45:37 +03:00
KINFO *k;
1994-05-09 07:31:07 +04:00
VARENT *ve;
1993-03-21 12:45:37 +03:00
{
1994-05-09 07:31:07 +04:00
VAR *v;
v = ve->var;
1993-03-21 12:45:37 +03:00
#ifndef NEWVM
1994-05-09 07:31:07 +04:00
(void)printf("%*d", v->width, pgtok(KI_EPROC(k)->e_xsize));
#else
(void)printf("%*d", v->width, pgtok(KI_EPROC(k)->e_vm.vm_tsize));
#endif
1993-03-21 12:45:37 +03:00
}
#ifndef NEWVM
1994-05-09 07:31:07 +04:00
void
trss(k, ve)
1993-03-21 12:45:37 +03:00
KINFO *k;
1994-05-09 07:31:07 +04:00
VARENT *ve;
1993-03-21 12:45:37 +03:00
{
1994-05-09 07:31:07 +04:00
VAR *v;
v = ve->var;
(void)printf("%*d", v->width, pgtok(KI_EPROC(k)->e_xrssize));
1993-03-21 12:45:37 +03:00
}
1994-05-09 07:31:07 +04:00
#endif
1993-03-21 12:45:37 +03:00
/*
* Generic output routines. Print fields from various prototype
* structures.
*/
1994-05-09 07:31:07 +04:00
static void
1993-03-21 12:45:37 +03:00
printval(bp, v)
char *bp;
VAR *v;
{
static char ofmt[32] = "%";
1994-05-09 07:31:07 +04:00
char *fcp, *cp;
1993-03-21 12:45:37 +03:00
1994-05-09 07:31:07 +04:00
cp = ofmt + 1;
fcp = v->fmt;
1993-03-21 12:45:37 +03:00
if (v->flag & LJUST)
*cp++ = '-';
*cp++ = '*';
while (*cp++ = *fcp++);
switch (v->type) {
case CHAR:
1994-05-09 07:31:07 +04:00
(void)printf(ofmt, v->width, *(char *)bp);
1993-03-21 12:45:37 +03:00
break;
case UCHAR:
1994-05-09 07:31:07 +04:00
(void)printf(ofmt, v->width, *(u_char *)bp);
1993-03-21 12:45:37 +03:00
break;
case SHORT:
1994-05-09 07:31:07 +04:00
(void)printf(ofmt, v->width, *(short *)bp);
1993-03-21 12:45:37 +03:00
break;
case USHORT:
1994-05-09 07:31:07 +04:00
(void)printf(ofmt, v->width, *(u_short *)bp);
1993-03-21 12:45:37 +03:00
break;
case LONG:
1994-05-09 07:31:07 +04:00
(void)printf(ofmt, v->width, *(long *)bp);
1993-03-21 12:45:37 +03:00
break;
case ULONG:
1994-05-09 07:31:07 +04:00
(void)printf(ofmt, v->width, *(u_long *)bp);
1993-03-21 12:45:37 +03:00
break;
case KPTR:
1994-05-09 07:31:07 +04:00
(void)printf(ofmt, v->width, *(u_long *)bp &~ KERNBASE);
1993-03-21 12:45:37 +03:00
break;
default:
1994-05-09 07:31:07 +04:00
errx(1, "unknown type %d", v->type);
1993-03-21 12:45:37 +03:00
}
}
1994-05-09 07:31:07 +04:00
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, "-");
}