Use err(3). Add some %d to %ld changes.

This commit is contained in:
Philippe Charnier 1997-08-25 06:40:05 +00:00
parent d9be0ac773
commit 495aecea76
2 changed files with 39 additions and 48 deletions

View File

@ -30,7 +30,7 @@
.\" SUCH DAMAGE. .\" SUCH DAMAGE.
.\" .\"
.\" @(#)vmstat.8 8.1 (Berkeley) 6/6/93 .\" @(#)vmstat.8 8.1 (Berkeley) 6/6/93
.\" $Id$ .\" $Id: vmstat.8,v 1.8 1997/08/23 21:42:46 steve Exp $
.\" .\"
.Dd June 6, 1996 .Dd June 6, 1996
.Dt VMSTAT 8 .Dt VMSTAT 8
@ -104,7 +104,7 @@ is specified, the default is infinity.
.El .El
.Pp .Pp
By default, By default,
.Nm vmstat .Nm
displays the following information: displays the following information:
.Pp .Pp
.Bl -tag -width indent .Bl -tag -width indent
@ -159,10 +159,10 @@ Typically paging will be split across the available drives.
The header of the field is the first character of the disk name and The header of the field is the first character of the disk name and
the unit number. the unit number.
If more than four disk drives are configured in the system, If more than four disk drives are configured in the system,
.Nm vmstat .Nm
displays only the first four drives. displays only the first four drives.
To force To force
.Nm vmstat .Nm
to display specific drives, their names may be supplied on the command line. to display specific drives, their names may be supplied on the command line.
.It faults .It faults
Trap/interrupt rate averages per second over last 5 seconds. Trap/interrupt rate averages per second over last 5 seconds.

View File

@ -32,13 +32,17 @@
*/ */
#ifndef lint #ifndef lint
static char copyright[] = static const char copyright[] =
"@(#) Copyright (c) 1980, 1986, 1991, 1993\n\ "@(#) Copyright (c) 1980, 1986, 1991, 1993\n\
The Regents of the University of California. All rights reserved.\n"; The Regents of the University of California. All rights reserved.\n";
#endif /* not lint */ #endif /* not lint */
#ifndef lint #ifndef lint
#if 0
static char sccsid[] = "@(#)vmstat.c 8.1 (Berkeley) 6/6/93"; static char sccsid[] = "@(#)vmstat.c 8.1 (Berkeley) 6/6/93";
#endif
static const char rcsid[] =
"$Id$";
#endif /* not lint */ #endif /* not lint */
#include <sys/param.h> #include <sys/param.h>
@ -57,17 +61,18 @@ static char sccsid[] = "@(#)vmstat.c 8.1 (Berkeley) 6/6/93";
#include <vm/vm_param.h> #include <vm/vm_param.h>
#include <time.h>
#include <nlist.h>
#include <kvm.h>
#include <errno.h>
#include <unistd.h>
#include <stdio.h>
#include <ctype.h> #include <ctype.h>
#include <err.h>
#include <errno.h>
#include <kvm.h>
#include <limits.h>
#include <nlist.h>
#include <paths.h>
#include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <paths.h> #include <time.h>
#include <limits.h> #include <unistd.h>
struct nlist namelist[] = { struct nlist namelist[] = {
#define X_CPTIME 0 #define X_CPTIME 0
@ -169,13 +174,13 @@ void dovmstat(), kread(), usage();
#ifdef notdef #ifdef notdef
void dotimes(), doforkst(); void dotimes(), doforkst();
#endif #endif
void printhdr __P((void));
int
main(argc, argv) main(argc, argv)
register int argc; register int argc;
register char **argv; register char **argv;
{ {
extern int optind;
extern char *optarg;
register int c, todo; register int c, todo;
u_int interval; u_int interval;
int reps; int reps;
@ -235,17 +240,13 @@ main(argc, argv)
if (nlistf != NULL || memf != NULL) if (nlistf != NULL || memf != NULL)
setgid(getgid()); setgid(getgid());
kd = kvm_openfiles(nlistf, memf, NULL, O_RDONLY, errbuf); kd = kvm_openfiles(nlistf, memf, NULL, O_RDONLY, errbuf);
if (kd == 0) { if (kd == 0)
(void)fprintf(stderr, errx(1, "kvm_openfiles: %s", errbuf);
"vmstat: kvm_openfiles: %s\n", errbuf);
exit(1);
}
if ((c = kvm_nlist(kd, namelist)) != 0) { if ((c = kvm_nlist(kd, namelist)) != 0) {
if (c > 0) { if (c > 0) {
(void)fprintf(stderr, warnx("undefined symbols:");
"vmstat: undefined symbols:");
for (c = 0; for (c = 0;
c < sizeof(namelist)/sizeof(namelist[0]); c++) c < sizeof(namelist)/sizeof(namelist[0]); c++)
if (namelist[c].n_type == 0) if (namelist[c].n_type == 0)
@ -253,8 +254,7 @@ main(argc, argv)
namelist[c].n_name); namelist[c].n_name);
(void)fputc('\n', stderr); (void)fputc('\n', stderr);
} else } else
(void)fprintf(stderr, "vmstat: kvm_nlist: %s\n", warnx("kvm_nlist: %s", kvm_geterr(kd));
kvm_geterr(kd));
exit(1); exit(1);
} }
@ -313,10 +313,8 @@ getdrivedata(argv)
char buf[30]; char buf[30];
kread(X_DK_NDRIVE, &dk_ndrive, sizeof(dk_ndrive)); kread(X_DK_NDRIVE, &dk_ndrive, sizeof(dk_ndrive));
if (dk_ndrive < 0) { if (dk_ndrive < 0)
(void)fprintf(stderr, "vmstat: dk_ndrive %d\n", dk_ndrive); errx(1, "dk_ndrive %d", dk_ndrive);
exit(1);
}
dr_select = calloc((size_t)dk_ndrive, sizeof(int)); dr_select = calloc((size_t)dk_ndrive, sizeof(int));
dr_name = calloc((size_t)dk_ndrive, sizeof(char *)); dr_name = calloc((size_t)dk_ndrive, sizeof(char *));
for (i = 0; i < dk_ndrive; i++) for (i = 0; i < dk_ndrive; i++)
@ -380,11 +378,8 @@ getuptime()
kread(X_BOOTTIME, &boottime, sizeof(boottime)); kread(X_BOOTTIME, &boottime, sizeof(boottime));
(void)time(&now); (void)time(&now);
uptime = now - boottime; uptime = now - boottime;
if (uptime <= 0 || uptime > 60*60*24*365*10) { if (uptime <= 0 || uptime > 60*60*24*365*10)
(void)fprintf(stderr, errx(1, "time makes no sense; namelist must be wrong");
"vmstat: time makes no sense; namelist must be wrong.\n");
exit(1);
}
return(uptime); return(uptime);
} }
@ -427,7 +422,7 @@ dovmstat(interval, reps)
#define pgtok(a) ((a) * sum.v_page_size >> 10) #define pgtok(a) ((a) * sum.v_page_size >> 10)
#define rate(x) (((x) + halfuptime) / uptime) /* round */ #define rate(x) (((x) + halfuptime) / uptime) /* round */
(void)printf("%8ld%6ld ", (void)printf("%8ld%6ld ",
pgtok(total.t_avm), pgtok(total.t_free)); (long)pgtok(total.t_avm), (long)pgtok(total.t_free));
(void)printf("%4lu ", rate(sum.v_vm_faults - osum.v_vm_faults)); (void)printf("%4lu ", rate(sum.v_vm_faults - osum.v_vm_faults));
(void)printf("%3lu ", (void)printf("%3lu ",
rate(sum.v_reactivated - osum.v_reactivated)); rate(sum.v_reactivated - osum.v_reactivated));
@ -461,6 +456,7 @@ dovmstat(interval, reps)
} }
} }
void
printhdr() printhdr()
{ {
register int i; register int i;
@ -510,6 +506,7 @@ dotimes()
} }
#endif #endif
long
pct(top, bot) pct(top, bot)
long top, bot; long top, bot;
{ {
@ -575,11 +572,11 @@ dosum()
nchstats.ncs_miss + nchstats.ncs_long; nchstats.ncs_miss + nchstats.ncs_long;
(void)printf("%9ld total name lookups\n", nchtotal); (void)printf("%9ld total name lookups\n", nchtotal);
(void)printf( (void)printf(
"%9s cache hits (%d%% pos + %d%% neg) system %d%% per-directory\n", "%9s cache hits (%ld%% pos + %ld%% neg) system %ld%% per-directory\n",
"", PCT(nchstats.ncs_goodhits, nchtotal), "", PCT(nchstats.ncs_goodhits, nchtotal),
PCT(nchstats.ncs_neghits, nchtotal), PCT(nchstats.ncs_neghits, nchtotal),
PCT(nchstats.ncs_pass2, nchtotal)); PCT(nchstats.ncs_pass2, nchtotal));
(void)printf("%9s deletions %d%%, falsehits %d%%, toolong %d%%\n", "", (void)printf("%9s deletions %ld%%, falsehits %ld%%, toolong %ld%%\n", "",
PCT(nchstats.ncs_badhits, nchtotal), PCT(nchstats.ncs_badhits, nchtotal),
PCT(nchstats.ncs_falsehits, nchtotal), PCT(nchstats.ncs_falsehits, nchtotal),
PCT(nchstats.ncs_long, nchtotal)); PCT(nchstats.ncs_long, nchtotal));
@ -675,10 +672,8 @@ dointr()
namelist[X_EINTRNAMES].n_value - namelist[X_INTRNAMES].n_value; namelist[X_EINTRNAMES].n_value - namelist[X_INTRNAMES].n_value;
intrcnt = malloc((size_t)nintr); intrcnt = malloc((size_t)nintr);
intrname = malloc((size_t)inamlen); intrname = malloc((size_t)inamlen);
if (intrcnt == NULL || intrname == NULL) { if (intrcnt == NULL || intrname == NULL)
(void)fprintf(stderr, "vmstat: %s.\n", strerror(errno)); errx(1, "malloc");
exit(1);
}
kread(X_INTRCNT, intrcnt, (size_t)nintr); kread(X_INTRCNT, intrcnt, (size_t)nintr);
kread(X_INTRNAMES, intrname, (size_t)inamlen); kread(X_INTRNAMES, intrname, (size_t)inamlen);
(void)printf("interrupt total rate\n"); (void)printf("interrupt total rate\n");
@ -814,16 +809,13 @@ kread(nlx, addr, size)
sym = namelist[nlx].n_name; sym = namelist[nlx].n_name;
if (*sym == '_') if (*sym == '_')
++sym; ++sym;
(void)fprintf(stderr, errx(1, "symbol %s not defined", sym);
"vmstat: symbol %s not defined\n", sym);
exit(1);
} }
if (kvm_read(kd, namelist[nlx].n_value, addr, size) != size) { if (kvm_read(kd, namelist[nlx].n_value, addr, size) != size) {
sym = namelist[nlx].n_name; sym = namelist[nlx].n_name;
if (*sym == '_') if (*sym == '_')
++sym; ++sym;
(void)fprintf(stderr, "vmstat: %s: %s\n", sym, kvm_geterr(kd)); errx(1, "%s: %s", sym, kvm_geterr(kd));
exit(1);
} }
} }
@ -831,7 +823,6 @@ void
usage() usage()
{ {
(void)fprintf(stderr, (void)fprintf(stderr,
"usage: vmstat [-ims] [-c count] [-M core] \ "usage: vmstat [-ims] [-c count] [-M core] [-N system] [-w wait] [disks]\n");
[-N system] [-w wait] [disks]\n");
exit(1); exit(1);
} }