use new ttylist to get tty stats.

This commit is contained in:
mrg 1996-05-30 05:45:45 +00:00
parent 601c0013e0
commit 956fd533da
1 changed files with 29 additions and 188 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: pstat.c,v 1.19 1996/05/02 00:13:19 cgd Exp $ */
/* $NetBSD: pstat.c,v 1.20 1996/05/30 05:45:45 mrg Exp $ */
/*-
* Copyright (c) 1980, 1991, 1993
@ -43,7 +43,7 @@ static char copyright[] =
#if 0
from: static char sccsid[] = "@(#)pstat.c 8.9 (Berkeley) 2/16/94";
#else
static char *rcsid = "$NetBSD: pstat.c,v 1.19 1996/05/02 00:13:19 cgd Exp $";
static char *rcsid = "$NetBSD: pstat.c,v 1.20 1996/05/30 05:45:45 mrg Exp $";
#endif
#endif /* not lint */
@ -101,76 +101,15 @@ struct nlist nl[] = {
{"_nfiles"},
#define FNL_MAXFILE 9
{"_maxfiles"},
#define NLMANDATORY FNL_MAXFILE /* names up to here are mandatory */
#define TTY_NTTY 10
{"_tty_count"},
#define TTY_TTYLIST 11
{"_ttylist"},
#define NLMANDATORY TTY_TTYLIST /* names up to here are mandatory */
#define VM_NISWAP NLMANDATORY + 1
{ "_niswap" },
#define VM_NISWDEV NLMANDATORY + 2
{ "_niswdev" },
#define SCONS NLMANDATORY + 3
{ "_constty" },
#define SPTY NLMANDATORY + 4
{ "_pt_tty" },
#define SNPTY NLMANDATORY + 5
{ "_npty" },
#ifdef sparc
#define SZS (SNPTY+1)
{ "_zs_tty" },
#define SCZS (SNPTY+2)
{ "_zscd" },
#endif
#ifdef hp300
#define SDCA (SNPTY+1)
{ "_dca_tty" },
#define SNDCA (SNPTY+2)
{ "_ndca" },
#define SDCM (SNPTY+3)
{ "_dcm_tty" },
#define SNDCM (SNPTY+4)
{ "_ndcm" },
#define SDCL (SNPTY+5)
{ "_dcl_tty" },
#define SNDCL (SNPTY+6)
{ "_ndcl" },
#define SITE (SNPTY+7)
{ "_ite_tty" },
#define SNITE (SNPTY+8)
{ "_nite" },
#endif
#ifdef mips
#define SDC (SNPTY+1)
{ "_dc_tty" },
#define SNDC (SNPTY+2)
{ "_dc_cnt" },
#endif
#ifdef i386
#define SPC (SNPTY+1)
{ "_pc_tty" },
#define SCPC (SNPTY+2)
{ "_pccd" },
#define SCOM (SNPTY+3)
{ "_com_tty" },
#define SCCOM (SNPTY+4)
{ "_comcd" },
#endif
#ifdef amiga
#define SSER (SNPTY + 1)
{ "_ser_tty" },
#define SCSER (SNPTY + 2)
{ "_sercd" },
#define SITE (SNPTY + 3)
{ "_ite_tty" },
#define SCITE (SNPTY + 4)
{ "_itecd" },
#define SMFCS (SNPTY + 5)
{ "_mfcs_tty" },
#define SCMFCS (SNPTY + 6)
{ "_mfcscd" },
#endif
{ "" }
};
@ -208,10 +147,7 @@ void nfs_header __P((void));
int nfs_print __P((struct vnode *));
void swapmode __P((void));
void ttymode __P((void));
void ttyprt __P((struct tty *, int));
void ttytype __P((char *, int, int));
void ttytype_newcf __P((char *, int, int));
void ttytype_oldcf __P((char *, int, int));
void ttyprt __P((struct tty *));
void ufs_header __P((void));
int ufs_print __P((struct vnode *));
void usage __P((void));
@ -737,108 +673,18 @@ char hdr[]=" LINE RAW CAN OUT HWT LWT COL STATE SESS PGID DISC\n";
void
ttymode()
{
int ntty, i;
struct ttylist_head tty_head;
struct tty *tp, tty;
#ifdef sparc
ttytype("console", SCONS, 1);
ttytype_newcf("zs", SZS, SCZS);
#endif
#ifdef vax
/* May fill in this later */
#endif
#ifdef tahoe
if (nl[SNVX].n_type != 0)
ttytype_oldcf("vx", SVX, SNVX);
if (nl[SNMP].n_type != 0)
ttytype_oldcf("mp", SMP, SNMP);
#endif
#ifdef hp300
if (nl[SNITE].n_type != 0)
ttytype_oldcf("ite", SITE, SNITE);
if (nl[SNDCA].n_type != 0)
ttytype_oldcf("dca", SDCA, SNDCA);
if (nl[SNDCM].n_type != 0)
ttytype_oldcf("dcm", SDCM, SNDCM);
if (nl[SNDCL].n_type != 0)
ttytype_oldcf("dcl", SDCL, SNDCL);
#endif
#ifdef mips
if (nl[SNDC].n_type != 0)
ttytype_oldcf("dc", SDC, SNDC);
#endif
#ifdef i386
if (nl[SCPC].n_type != 0)
ttytype_newcf("pc", SPC, SCPC);
if (nl[SCCOM].n_type != 0)
ttytype_newcf("com", SCOM, SCCOM);
#endif
#ifdef amiga
if (nl[SCSER].n_type != 0)
ttytype_newcf("ser", SSER, SCSER);
if (nl[SCITE].n_type != 0)
ttytype_newcf("ite", SITE, SCITE);
if (nl[SCMFCS].n_type != 0)
ttytype_newcf("mfcs", SMFCS, SCMFCS);
#endif
if (nl[SNPTY].n_type != 0)
ttytype_oldcf("pty", SPTY, SNPTY);
}
void
ttytype_oldcf(name, type, number)
char *name;
int type, number;
{
int ntty;
KGET(number, ntty);
ttytype(name, type, ntty);
}
void
ttytype_newcf(name, type, config)
char *name;
int type, config;
{
struct cfdriver cf;
void **cd;
int i;
KGET(config, cf);
cd = malloc(cf.cd_ndevs * sizeof(void *));
if (!cd)
return;
KGET2(cf.cd_devs, cd, cf.cd_ndevs * sizeof(void *), "cfdevicep");
for (i = cf.cd_ndevs - 1; i >= 0; --i)
if (cd[i])
break;
free(cd);
ttytype(name, type, i + 1);
}
void
ttytype(name, type, number)
char *name;
int type, number;
{
static struct tty **ttyp;
static int nttyp;
static struct tty tty;
int ntty = number, i;
(void)printf("%d %s %s\n", ntty, name, (ntty == 1) ? "line" : "lines");
if (ntty > nttyp) {
nttyp = ntty;
if ((ttyp = realloc(ttyp, nttyp * sizeof(*ttyp))) == 0)
err(1, NULL);
}
KGET1(type, ttyp, nttyp * sizeof(*ttyp), "tty pointers");
(void)printf(hdr);
for (i = 0; i < ntty; i++) {
if (ttyp[i] == NULL)
continue;
KGET2(ttyp[i], &tty, sizeof(struct tty), "tty struct");
ttyprt(&tty, i);
KGET(TTY_NTTY, ntty);
(void)printf("%d terminal device%s\n", ntty, ntty == 1 ? "" : "s");
KGET(TTY_TTYLIST, tty_head);
for (tp = tty_head.tqh_first; tp; tp = tty.tty_link.tqe_next) {
if (tp == NULL)
return;
KGET2(tp, &tty, sizeof tty, "tty struct");
ttyprt(&tty);
}
}
@ -866,17 +712,15 @@ struct {
};
void
ttyprt(tp, line)
ttyprt(tp)
register struct tty *tp;
int line;
{
register int i, j;
pid_t pgid;
char *name, state[20];
if (usenumflag || tp->t_dev == 0 ||
(name = devname(tp->t_dev, S_IFCHR)) == NULL)
(void)printf("%7d ", line);
if (usenumflag || (name = devname(tp->t_dev, S_IFCHR)) == NULL)
(void)printf("0x%3x:%1x ", major(tp->t_dev), minor(tp->t_dev));
else
(void)printf("%-7s ", name);
(void)printf("%3d %4d ", tp->t_rawq.c_cc, tp->t_canq.c_cc);
@ -1119,21 +963,18 @@ swapmode()
for (i = 0; i < nswdev; i++) {
int xsize, xfree;
/*
* Don't report statistics for partitions which have not
* yet been activated via swapon(8).
*/
if (!(sw[i].sw_flags & SW_FREED))
continue;
if (!totalflag)
(void)printf("/dev/%-6s %*d ",
devname(sw[i].sw_dev, S_IFBLK),
hlen, sw[i].sw_nblks / div);
/*
* Don't report statistics for partitions which have not
* yet been activated via swapon(8).
*/
if (!(sw[i].sw_flags & SW_FREED)) {
if (totalflag)
continue;
(void)printf(" *** not available for swapping ***\n");
continue;
}
xsize = sw[i].sw_nblks;
xfree = perdev[i];
used = xsize - xfree;