Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 16 Oct 2018 20:53:17 +0000 (UTC)
From:      John Baldwin <jhb@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-11@freebsd.org
Subject:   svn commit: r339392 - stable/11/usr.bin/vmstat
Message-ID:  <201810162053.w9GKrHtO037028@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: jhb
Date: Tue Oct 16 20:53:16 2018
New Revision: 339392
URL: https://svnweb.freebsd.org/changeset/base/339392

Log:
  MFC 326138,326436,326852: Style fixes to kdump.
  
  326138:
  Use C standard spelling uint64_t for u_int64_t.
  
  326436:
  vmstat: fix style(9) violations and bump WARNS.
  
  326852:
  Re-add spaces lost in r326436.

Modified:
  stable/11/usr.bin/vmstat/Makefile
  stable/11/usr.bin/vmstat/vmstat.c
Directory Properties:
  stable/11/   (props changed)

Modified: stable/11/usr.bin/vmstat/Makefile
==============================================================================
--- stable/11/usr.bin/vmstat/Makefile	Tue Oct 16 20:12:35 2018	(r339391)
+++ stable/11/usr.bin/vmstat/Makefile	Tue Oct 16 20:53:16 2018	(r339392)
@@ -5,6 +5,6 @@ PROG=	vmstat
 MAN=	vmstat.8
 LIBADD=	devstat kvm memstat xo util
 
-WARNS?=	1
+WARNS?=	6
 
 .include <bsd.prog.mk>

Modified: stable/11/usr.bin/vmstat/vmstat.c
==============================================================================
--- stable/11/usr.bin/vmstat/vmstat.c	Tue Oct 16 20:12:35 2018	(r339391)
+++ stable/11/usr.bin/vmstat/vmstat.c	Tue Oct 16 20:53:16 2018	(r339392)
@@ -82,55 +82,43 @@ __FBSDID("$FreeBSD$");
 
 static char da[] = "da";
 
+enum x_stats { X_SUM, X_HZ, X_STATHZ, X_NCHSTATS, X_INTRNAMES, X_SINTRNAMES,
+    X_INTRCNT, X_SINTRCNT, X_DEFICIT, X_REC, X_PGIN, X_XSTATS };
+
 static struct nlist namelist[] = {
-#define X_SUM		0
-	{ "_vm_cnt" },
-#define X_HZ		1
-	{ "_hz" },
-#define X_STATHZ	2
-	{ "_stathz" },
-#define X_NCHSTATS	3
-	{ "_nchstats" },
-#define	X_INTRNAMES	4
-	{ "_intrnames" },
-#define	X_SINTRNAMES	5
-	{ "_sintrnames" },
-#define	X_INTRCNT	6
-	{ "_intrcnt" },
-#define	X_SINTRCNT	7
-	{ "_sintrcnt" },
+	[X_SUM] = { .n_name = "_vm_cnt", },
+	[X_HZ] = { .n_name = "_hz", },
+	[X_STATHZ] = { .n_name = "_stathz", },
+	[X_NCHSTATS] = { .n_name = "_nchstats", },
+	[X_INTRNAMES] = { .n_name = "_intrnames", },
+	[X_SINTRNAMES] = { .n_name = "_sintrnames", },
+	[X_INTRCNT] = { .n_name = "_intrcnt", },
+	[X_SINTRCNT] = { .n_name = "_sintrcnt", },
 #ifdef notyet
-#define	X_DEFICIT	XXX
-	{ "_deficit" },
-#define X_REC		XXX
-	{ "_rectime" },
-#define X_PGIN		XXX
-	{ "_pgintime" },
-#define	X_XSTATS	XXX
-	{ "_xstats" },
-#define X_END		XXX
-#else
-#define X_END		8
+	[X_DEFICIT] = { .n_name = "_deficit", },
+	[X_REC] = { .n_name = "_rectime", },
+	[X_PGIN] = { .n_name = "_pgintime", },
+	[X_XSTATS] = { .n_name = "_xstats", },
 #endif
-	{ "" },
+	{ .n_name = NULL, },
 };
 
-static struct statinfo cur, last;
-static int num_devices, maxshowdevs;
-static long generation;
-static struct device_selection *dev_select;
-static int num_selected;
 static struct devstat_match *matches;
-static int num_matches = 0;
-static int num_devices_specified, num_selections;
-static long select_generation;
-static char **specified_devices;
+static struct device_selection *dev_select;
+static struct statinfo cur, last;
 static devstat_select_mode select_mode;
+static size_t size_cp_times;
+static long *cur_cp_times, *last_cp_times;
+static long generation, select_generation;
+static int hz, hdrcnt, maxshowdevs;
+static int num_devices, num_devices_specified;
+static int num_matches, num_selected, num_selections;
+static char **specified_devices;
 
 static struct	vmmeter sum, osum;
 
 #define	VMSTAT_DEFAULT_LINES	20	/* Default number of `winlines'. */
-volatile sig_atomic_t wresized;		/* Tty resized, when non-zero. */
+static volatile sig_atomic_t wresized;		/* Tty resized when non-zero. */
 static int winlines = VMSTAT_DEFAULT_LINES; /* Current number of tty rows. */
 
 static int	aflag;
@@ -138,7 +126,7 @@ static int	nflag;
 static int	Pflag;
 static int	hflag;
 
-static kvm_t   *kd;
+static kvm_t	*kd;
 
 #define	FORKSTAT	0x01
 #define	INTRSTAT	0x02
@@ -146,11 +134,11 @@ static kvm_t   *kd;
 #define	SUMSTAT		0x08
 #define	TIMESTAT	0x10
 #define	VMSTAT		0x20
-#define ZMEMSTAT	0x40
+#define	ZMEMSTAT	0x40
 #define	OBJSTAT		0x80
 
 static void	cpustats(void);
-static void	pcpustats(int, u_long, int);
+static void	pcpustats(u_long, int);
 static void	devstats(void);
 static void	doforkst(void);
 static void	dointr(unsigned int, int);
@@ -161,7 +149,6 @@ static void	domemstat_malloc(void);
 static void	domemstat_zone(void);
 static void	kread(int, void *, size_t);
 static void	kreado(int, void *, size_t, size_t);
-static char    *kgetstr(const char *);
 static void	needhdr(int);
 static void	needresize(int);
 static void	doresize(void);
@@ -171,16 +158,15 @@ static void	usage(void);
 static long	pct(long, long);
 static long long	getuptime(void);
 
-static char   **getdrivedata(char **);
+static char	**getdrivedata(char **);
 
 int
 main(int argc, char *argv[])
 {
-	int c, todo;
-	unsigned int interval;
+	char *bp, *buf, *memf, *nlistf;
 	float f;
-	int reps;
-	char *memf, *nlistf;
+	int bufsize, c, len, reps, todo;
+	unsigned int interval;
 	char errbuf[_POSIX2_LINE_MAX];
 
 	memf = nlistf = NULL;
@@ -190,7 +176,7 @@ main(int argc, char *argv[])
 
 	argc = xo_parse_args(argc, argv);
 	if (argc < 0)
-		return argc;
+		return (argc);
 
 	while ((c = getopt(argc, argv, "ac:fhHiM:mN:n:oPp:stw:z")) != -1) {
 		switch (c) {
@@ -229,13 +215,14 @@ main(int argc, char *argv[])
 			maxshowdevs = atoi(optarg);
 			if (maxshowdevs < 0)
 				xo_errx(1, "number of devices %d is < 0",
-				     maxshowdevs);
+				    maxshowdevs);
 			break;
 		case 'o':
 			todo |= OBJSTAT;
 			break;
 		case 'p':
-			if (devstat_buildmatch(optarg, &matches, &num_matches) != 0)
+			if (devstat_buildmatch(optarg, &matches, &num_matches)
+			    != 0)
 				xo_errx(1, "%s", devstat_errbuf);
 			break;
 		case 's':
@@ -245,7 +232,8 @@ main(int argc, char *argv[])
 #ifdef notyet
 			todo |= TIMESTAT;
 #else
-			xo_errx(EX_USAGE, "sorry, -t is not (re)implemented yet");
+			xo_errx(EX_USAGE,
+			    "sorry, -t is not (re)implemented yet");
 #endif
 			break;
 		case 'w':
@@ -277,10 +265,10 @@ main(int argc, char *argv[])
 retry_nlist:
 	if (kd != NULL && (c = kvm_nlist(kd, namelist)) != 0) {
 		if (c > 0) {
-			int bufsize = 0, len = 0;
-			char *buf, *bp;
+			bufsize = 0, len = 0;
+
 			/*
-			 * 'cnt' was renamed to 'vm_cnt'. If 'vm_cnt' is not
+			 * 'cnt' was renamed to 'vm_cnt'.  If 'vm_cnt' is not
 			 * found try looking up older 'cnt' symbol.
 			 * */
 			if (namelist[X_SUM].n_type == 0 &&
@@ -288,9 +276,11 @@ retry_nlist:
 				namelist[X_SUM].n_name = "_cnt";
 				goto retry_nlist;
 			}
+
 			for (c = 0; c < (int)(nitems(namelist)); c++)
 				if (namelist[c].n_type == 0)
-					bufsize += strlen(namelist[c].n_name) + 1;
+					bufsize += strlen(namelist[c].n_name)
+					    + 1;
 			bufsize += len + 1;
 			buf = bp = alloca(bufsize);
 
@@ -376,6 +366,7 @@ mysysctl(const char *name, void *oldp, size_t *oldlenp
 static char **
 getdrivedata(char **argv)
 {
+
 	if ((num_devices = devstat_getnumdevs(NULL)) < 0)
 		xo_errx(1, "%s", devstat_errbuf);
 
@@ -388,20 +379,19 @@ getdrivedata(char **argv)
 	num_devices = cur.dinfo->numdevs;
 	generation = cur.dinfo->generation;
 
-	specified_devices = (char **)malloc(sizeof(char *));
+	specified_devices = malloc(sizeof(char *));
 	for (num_devices_specified = 0; *argv; ++argv) {
 		if (isdigit(**argv))
 			break;
 		num_devices_specified++;
-		specified_devices = (char **)realloc(specified_devices,
-						     sizeof(char *) *
-						     num_devices_specified);
+		specified_devices = realloc(specified_devices,
+		    sizeof(char *) * num_devices_specified);
 		specified_devices[num_devices_specified - 1] = *argv;
 	}
 	dev_select = NULL;
 
 	if (nflag == 0 && maxshowdevs < num_devices_specified)
-			maxshowdevs = num_devices_specified;
+		maxshowdevs = num_devices_specified;
 
 	/*
 	 * People are generally only interested in disk statistics when
@@ -416,7 +406,6 @@ getdrivedata(char **argv)
 	if ((num_devices_specified == 0) && (num_matches == 0)) {
 		if (devstat_buildmatch(da, &matches, &num_matches) != 0)
 			xo_errx(1, "%s", devstat_errbuf);
-
 		select_mode = DS_SELECT_ADD;
 	} else
 		select_mode = DS_SELECT_ONLY;
@@ -427,10 +416,10 @@ getdrivedata(char **argv)
 	 * or 1.  If we get back -1, though, there is an error.
 	 */
 	if (devstat_selectdevs(&dev_select, &num_selected, &num_selections,
-		       &select_generation, generation, cur.dinfo->devices,
-		       num_devices, matches, num_matches, specified_devices,
-		       num_devices_specified, select_mode,
-		       maxshowdevs, 0) == -1)
+	    &select_generation, generation, cur.dinfo->devices,
+	    num_devices, matches, num_matches, specified_devices,
+	    num_devices_specified, select_mode,
+	    maxshowdevs, 0) == -1)
 		xo_errx(1, "%s", devstat_errbuf);
 
 	return(argv);
@@ -443,7 +432,6 @@ getuptime(void)
 	struct timespec sp;
 
 	(void)clock_gettime(CLOCK_UPTIME, &sp);
-
 	return((long long)sp.tv_sec * 1000000000LL + sp.tv_nsec);
 }
 
@@ -451,11 +439,11 @@ static void
 fill_pcpu(struct pcpu ***pcpup, int* maxcpup)
 {
 	struct pcpu **pcpu;
-	
 	int maxcpu, i;
 
 	*pcpup = NULL;
-	
+	*maxcpup = 0;
+
 	if (kd == NULL)
 		return;
 
@@ -492,6 +480,7 @@ fill_vmmeter(struct vmmeter *vmmp)
 {
 	struct pcpu **pcpu;
 	int maxcpu, i;
+	size_t size;
 
 	if (kd != NULL) {
 		kread(X_SUM, vmmp, sizeof(*vmmp));
@@ -534,7 +523,7 @@ fill_vmmeter(struct vmmeter *vmmp)
 		}
 		free_pcpu(pcpu, maxcpu);
 	} else {
-		size_t size = sizeof(unsigned int);
+		size = sizeof(unsigned int);
 #define GET_VM_STATS(cat, name) \
 	mysysctl("vm.stats." #cat "." #name, &vmmp->name, &size, NULL, 0)
 		/* sys */
@@ -596,11 +585,13 @@ fill_vmmeter(struct vmmeter *vmmp)
 static void
 fill_vmtotal(struct vmtotal *vmtp)
 {
+	size_t size;
+
 	if (kd != NULL) {
 		/* XXX fill vmtp */
 		xo_errx(1, "not implemented");
 	} else {
-		size_t size = sizeof(*vmtp);
+		size = sizeof(*vmtp);
 		mysysctl("vm.vmtotal", vmtp, &size, NULL, 0);
 		if (size != sizeof(*vmtp))
 			xo_errx(1, "vm.total size mismatch");
@@ -611,14 +602,10 @@ fill_vmtotal(struct vmtotal *vmtp)
 static int
 getcpuinfo(u_long *maskp, int *maxidp)
 {
-	int maxcpu;
-	int maxid;
-	int ncpus;
-	int i, j;
-	int empty;
-	size_t size;
 	long *times;
 	u_long mask;
+	size_t size;
+	int empty, i, j, maxcpu, maxid, ncpus;
 
 	if (kd != NULL)
 		xo_errx(1, "not implemented");
@@ -654,10 +641,10 @@ getcpuinfo(u_long *maskp, int *maxidp)
 
 
 static void
-prthuman(const char *name, u_int64_t val, int size)
+prthuman(const char *name, uint64_t val, int size)
 {
-	char buf[10];
 	int flags;
+	char buf[10];
 	char fmt[128];
 
 	snprintf(fmt, sizeof(fmt), "{:%s/%%*s}", name);
@@ -670,28 +657,23 @@ prthuman(const char *name, u_int64_t val, int size)
 	xo_emit(fmt, size, buf);
 }
 
-static int hz, hdrcnt;
-
-static long *cur_cp_times;
-static long *last_cp_times;
-static size_t size_cp_times;
-
 static void
 dovmstat(unsigned int interval, int reps)
 {
+	struct clockinfo clockrate;
 	struct vmtotal total;
-	time_t uptime, halfuptime;
 	struct devinfo *tmp_dinfo;
-	size_t size;
-	int ncpus, maxid;
 	u_long cpumask;
-	int rate_adj;
+	size_t size;
+	time_t uptime, halfuptime;
+	int ncpus, maxid, rate_adj, retval;
 
 	uptime = getuptime() / 1000000000LL;
 	halfuptime = uptime / 2;
 	rate_adj = 1;
 	ncpus = 1;
 	maxid = 0;
+	cpumask = 0;
 
 	/*
 	 * If the user stops the program (control-Z) and then resumes it,
@@ -720,8 +702,6 @@ dovmstat(unsigned int interval, int reps)
 		if (!hz)
 			kread(X_HZ, &hz, sizeof(hz));
 	} else {
-		struct clockinfo clockrate;
-
 		size = sizeof(clockrate);
 		mysysctl("kern.clockrate", &clockrate, &size, NULL, 0);
 		if (size != sizeof(clockrate))
@@ -770,19 +750,17 @@ dovmstat(unsigned int interval, int reps)
 		case -1:
 			xo_errx(1, "%s", devstat_errbuf);
 			break;
-		case 1: {
-			int retval;
-
+		case 1:
 			num_devices = cur.dinfo->numdevs;
 			generation = cur.dinfo->generation;
 
 			retval = devstat_selectdevs(&dev_select, &num_selected,
-					    &num_selections, &select_generation,
-					    generation, cur.dinfo->devices,
-					    num_devices, matches, num_matches,
-					    specified_devices,
-					    num_devices_specified, select_mode,
-					    maxshowdevs, 0);
+			    &num_selections, &select_generation,
+			    generation, cur.dinfo->devices,
+			    num_devices, matches, num_matches,
+			    specified_devices,
+			    num_devices_specified, select_mode,
+			    maxshowdevs, 0);
 			switch (retval) {
 			case -1:
 				xo_errx(1, "%s", devstat_errbuf);
@@ -793,7 +771,7 @@ dovmstat(unsigned int interval, int reps)
 			default:
 				break;
 			}
-		}
+			break;
 		default:
 			break;
 		}
@@ -802,8 +780,8 @@ dovmstat(unsigned int interval, int reps)
 		fill_vmtotal(&total);
 		xo_open_container("processes");
 		xo_emit("{:runnable/%1d} {:waiting/%ld} "
-		        "{:swapped-out/%ld}",
-		    total.t_rq - 1, total.t_dw + total.t_pw, total.t_sw);
+		    "{:swapped-out/%ld}", total.t_rq - 1, total.t_dw +
+		    total.t_pw, total.t_sw);
 		xo_close_container("processes");
 		xo_open_container("memory");
 #define vmstat_pgtok(a) ((a) * (sum.v_page_size >> 10))
@@ -811,27 +789,28 @@ dovmstat(unsigned int interval, int reps)
 		if (hflag) {
 			xo_emit("");
 			prthuman("available-memory",
-			         total.t_avm * (u_int64_t)sum.v_page_size, 5);
+			    total.t_avm * (uint64_t)sum.v_page_size, 5);
 			xo_emit(" ");
 			prthuman("free-memory",
-			         total.t_free * (u_int64_t)sum.v_page_size, 5);
+			    total.t_free * (uint64_t)sum.v_page_size, 5);
 			xo_emit(" ");
 		} else {
 			xo_emit(" ");
 			xo_emit("{:available-memory/%7d}",
-			        vmstat_pgtok(total.t_avm));
+			    vmstat_pgtok(total.t_avm));
 			xo_emit(" ");
 			xo_emit("{:free-memory/%7d}",
-			        vmstat_pgtok(total.t_free));
+			    vmstat_pgtok(total.t_free));
 		}
 		xo_emit("{:total-page-faults/%5lu} ",
-		        (unsigned long)rate(sum.v_vm_faults -
-		        osum.v_vm_faults));
+		    (unsigned long)rate(sum.v_vm_faults -
+		    osum.v_vm_faults));
 		xo_close_container("memory");
 
 		xo_open_container("paging-rates");
 		xo_emit("{:page-reactivated/%3lu} ",
-		    (unsigned long)rate(sum.v_reactivated - osum.v_reactivated));
+		    (unsigned long)rate(sum.v_reactivated -
+		    osum.v_reactivated));
 		xo_emit("{:paged-in/%3lu} ",
 		    (unsigned long)rate(sum.v_swapin + sum.v_vnodein -
 		    (osum.v_swapin + osum.v_vnodein)));
@@ -847,13 +826,13 @@ dovmstat(unsigned int interval, int reps)
 		devstats();
 		xo_open_container("fault-rates");
 		xo_emit("{:interrupts/%4lu} {:system-calls/%5lu} "
-		        "{:context-switches/%5u}",
+		    "{:context-switches/%5lu}",
 		    (unsigned long)rate(sum.v_intr - osum.v_intr),
 		    (unsigned long)rate(sum.v_syscall - osum.v_syscall),
 		    (unsigned long)rate(sum.v_swtch - osum.v_swtch));
 		xo_close_container("fault-rates");
 		if (Pflag)
-			pcpustats(ncpus, cpumask, maxid);
+			pcpustats(cpumask, maxid);
 		else
 			cpustats();
 		xo_emit("\n");
@@ -881,13 +860,12 @@ printhdr(int maxid, u_long cpumask)
 	int i, num_shown;
 
 	num_shown = MIN(num_selected, maxshowdevs);
-	if (hflag) {
+	if (hflag)
 		xo_emit("{T:procs}  {T:memory}       {T:/page%*s}", 19, "");
-	} else {
+	else
 		xo_emit("{T:procs}     {T:memory}        {T:/page%*s}", 19, "");
-	}
 	if (num_shown > 1)
-		xo_emit(" {T:/disks %*s}", num_shown * 4 - 7, ""); 
+		xo_emit(" {T:/disks %*s}", num_shown * 4 - 7, "");
 	else if (num_shown == 1)
 		xo_emit("   {T:disks}");
 	xo_emit("   {T:faults}      ");
@@ -900,16 +878,18 @@ printhdr(int maxid, u_long cpumask)
 	} else
 		xo_emit("   {T:cpu}\n");
 	if (hflag) {
-		xo_emit("{T:r} {T:b} {T:w}  {T:avm}   {T:fre}   {T:flt}  {T:re}  {T:pi}  {T:po}    {T:fr}   {T:sr} ");
+		xo_emit("{T:r} {T:b} {T:w}  {T:avm}   {T:fre}   {T:flt}  {T:re}"
+		    "  {T:pi}  {T:po}    {T:fr}   {T:sr} ");
 	} else {
-		xo_emit("{T:r} {T:b} {T:w}     {T:avm}     {T:fre}  {T:flt}  {T:re}  {T:pi}  {T:po}    {T:fr}   {T:sr} ");
+		xo_emit("{T:r} {T:b} {T:w}     {T:avm}     {T:fre}  {T:flt}  "
+		    "{T:re}  {T:pi}  {T:po}    {T:fr}   {T:sr} ");
 	}
 	for (i = 0; i < num_devices; i++)
-		if ((dev_select[i].selected)
-		 && (dev_select[i].selected <= maxshowdevs))
+		if ((dev_select[i].selected) &&
+		    (dev_select[i].selected <= maxshowdevs))
 			xo_emit("{T:/%c%c%d} ", dev_select[i].device_name[0],
-				     dev_select[i].device_name[1],
-				     dev_select[i].unit_number);
+			    dev_select[i].device_name[1],
+			    dev_select[i].unit_number);
 	xo_emit("  {T:in}    {T:sy}    {T:cs}");
 	if (Pflag) {
 		for (i = 0; i <= maxid; i++) {
@@ -940,7 +920,7 @@ needhdr(int dummy __unused)
  * prepended to the next output.
  */
 void
-needresize(int signo)
+needresize(int signo __unused)
 {
 
 	wresized = 1;
@@ -953,8 +933,8 @@ needresize(int signo)
 void
 doresize(void)
 {
-	int status;
 	struct winsize w;
+	int status;
 
 	for (;;) {
 		status = ioctl(fileno(stdout), TIOCGWINSZ, &w);
@@ -985,13 +965,13 @@ dotimes(void)
 	kread(X_PGIN, &pgintime, sizeof(pgintime));
 	kread(X_SUM, &sum, sizeof(sum));
 	xo_emit("{:page-reclaims/%u} {N:reclaims}, "
-		"{:reclaim-time/%u} {N:total time (usec)}\n",
+	    "{:reclaim-time/%u} {N:total time (usec)}\n",
 	    sum.v_pgrec, rectime);
 	xo_emit("{L:average}: {:reclaim-average/%u} {N:usec \\/ reclaim}\n",
-		rectime / sum.v_pgrec);
+	    rectime / sum.v_pgrec);
 	xo_emit("\n");
 	xo_emit("{:page-ins/%u} {N:page ins}, "
-		"{:page-in-time/%u} {N:total time (msec)}\n",
+	    "{:page-in-time/%u} {N:total time (msec)}\n",
 	    sum.v_pgin, pgintime / 10);
 	xo_emit("{L:average}: {:average/%8.1f} {N:msec \\/ page in}\n",
 	    pgintime / (sum.v_pgin * 10.0));
@@ -1015,93 +995,94 @@ static void
 dosum(void)
 {
 	struct nchstats lnchstats;
+	size_t size;
 	long nchtotal;
 
 	fill_vmmeter(&sum);
 	xo_open_container("summary-statistics");
 	xo_emit("{:context-switches/%9u} {N:cpu context switches}\n",
-		sum.v_swtch);
+	    sum.v_swtch);
 	xo_emit("{:interrupts/%9u} {N:device interrupts}\n",
-		sum.v_intr);
+	    sum.v_intr);
 	xo_emit("{:software-interrupts/%9u} {N:software interrupts}\n",
-		sum.v_soft);
+	    sum.v_soft);
 	xo_emit("{:traps/%9u} {N:traps}\n", sum.v_trap);
 	xo_emit("{:system-calls/%9u} {N:system calls}\n",
-		sum.v_syscall);
+	    sum.v_syscall);
 	xo_emit("{:kernel-threads/%9u} {N:kernel threads created}\n",
-		sum.v_kthreads);
+	    sum.v_kthreads);
 	xo_emit("{:forks/%9u} {N: fork() calls}\n", sum.v_forks);
 	xo_emit("{:vforks/%9u} {N:vfork() calls}\n",
-		sum.v_vforks);
+	    sum.v_vforks);
 	xo_emit("{:rforks/%9u} {N:rfork() calls}\n",
-		sum.v_rforks);
+	    sum.v_rforks);
 	xo_emit("{:swap-ins/%9u} {N:swap pager pageins}\n",
-		sum.v_swapin);
+	    sum.v_swapin);
 	xo_emit("{:swap-in-pages/%9u} {N:swap pager pages paged in}\n",
-		sum.v_swappgsin);
+	    sum.v_swappgsin);
 	xo_emit("{:swap-outs/%9u} {N:swap pager pageouts}\n",
-		sum.v_swapout);
+	    sum.v_swapout);
 	xo_emit("{:swap-out-pages/%9u} {N:swap pager pages paged out}\n",
-		sum.v_swappgsout);
+	    sum.v_swappgsout);
 	xo_emit("{:vnode-page-ins/%9u} {N:vnode pager pageins}\n",
-		sum.v_vnodein);
+	    sum.v_vnodein);
 	xo_emit("{:vnode-page-in-pages/%9u} {N:vnode pager pages paged in}\n",
-		sum.v_vnodepgsin);
+	    sum.v_vnodepgsin);
 	xo_emit("{:vnode-page-outs/%9u} {N:vnode pager pageouts}\n",
-		sum.v_vnodeout);
+	    sum.v_vnodeout);
 	xo_emit("{:vnode-page-outs/%9u} {N:vnode pager pages paged out}\n",
-		sum.v_vnodepgsout);
+	    sum.v_vnodepgsout);
 	xo_emit("{:page-daemon-wakeups/%9u} {N:page daemon wakeups}\n",
-		sum.v_pdwakeups);
-	xo_emit("{:page-daemon-pages/%9u} {N:pages examined by the page daemon}\n",
-		sum.v_pdpages);
-	xo_emit("{:page-reclamation-shortfalls/%9u} {N:clean page reclamation shortfalls}\n",
-		sum.v_pdshortfalls);
+	    sum.v_pdwakeups);
+	xo_emit("{:page-daemon-pages/%9u} {N:pages examined by the page "
+	    "daemon}\n", sum.v_pdpages);
+	xo_emit("{:page-reclamation-shortfalls/%9u} {N:clean page reclamation "
+	    "shortfalls}\n", sum.v_pdshortfalls);
 	xo_emit("{:reactivated/%9u} {N:pages reactivated by the page daemon}\n",
-		sum.v_reactivated);
+	    sum.v_reactivated);
 	xo_emit("{:copy-on-write-faults/%9u} {N:copy-on-write faults}\n",
-		sum.v_cow_faults);
-	xo_emit("{:copy-on-write-optimized-faults/%9u} {N:copy-on-write optimized faults}\n",
-		sum.v_cow_optim);
+	    sum.v_cow_faults);
+	xo_emit("{:copy-on-write-optimized-faults/%9u} {N:copy-on-write "
+	    "optimized faults}\n", sum.v_cow_optim);
 	xo_emit("{:zero-fill-pages/%9u} {N:zero fill pages zeroed}\n",
-		sum.v_zfod);
+	    sum.v_zfod);
 	xo_emit("{:zero-fill-prezeroed/%9u} {N:zero fill pages prezeroed}\n",
-		sum.v_ozfod);
+	    sum.v_ozfod);
 	xo_emit("{:intransit-blocking/%9u} {N:intransit blocking page faults}\n",
-		sum.v_intrans);
+	    sum.v_intrans);
 	xo_emit("{:total-faults/%9u} {N:total VM faults taken}\n",
-		sum.v_vm_faults);
+	    sum.v_vm_faults);
 	xo_emit("{:faults-requiring-io/%9u} {N:page faults requiring I\\/O}\n",
-		sum.v_io_faults);
-	xo_emit("{:faults-from-thread-creation/%9u} {N:pages affected by kernel thread creation}\n",
-		sum.v_kthreadpages);
+	    sum.v_io_faults);
+	xo_emit("{:faults-from-thread-creation/%9u} {N:pages affected by "
+	    "kernel thread creation}\n", sum.v_kthreadpages);
 	xo_emit("{:faults-from-fork/%9u} {N:pages affected by  fork}()\n",
-		sum.v_forkpages);
+	    sum.v_forkpages);
 	xo_emit("{:faults-from-vfork/%9u} {N:pages affected by vfork}()\n",
-		sum.v_vforkpages);
+	    sum.v_vforkpages);
 	xo_emit("{:pages-rfork/%9u} {N:pages affected by rfork}()\n",
-		sum.v_rforkpages);
+	    sum.v_rforkpages);
 	xo_emit("{:pages-freed/%9u} {N:pages freed}\n",
-		sum.v_tfree);
+	    sum.v_tfree);
 	xo_emit("{:pages-freed-by-daemon/%9u} {N:pages freed by daemon}\n",
-		sum.v_dfree);
+	    sum.v_dfree);
 	xo_emit("{:pages-freed-on-exit/%9u} {N:pages freed by exiting processes}\n",
-		sum.v_pfree);
+	    sum.v_pfree);
 	xo_emit("{:active-pages/%9u} {N:pages active}\n",
-		sum.v_active_count);
+	    sum.v_active_count);
 	xo_emit("{:inactive-pages/%9u} {N:pages inactive}\n",
-		sum.v_inactive_count);
+	    sum.v_inactive_count);
 	xo_emit("{:laundry-pages/%9u} {N:pages in the laundry queue}\n",
-		sum.v_laundry_count);
+	    sum.v_laundry_count);
 	xo_emit("{:wired-pages/%9u} {N:pages wired down}\n",
-		sum.v_wire_count);
+	    sum.v_wire_count);
 	xo_emit("{:free-pages/%9u} {N:pages free}\n",
-		sum.v_free_count);
+	    sum.v_free_count);
 	xo_emit("{:bytes-per-page/%9u} {N:bytes per page}\n", sum.v_page_size);
 	if (kd != NULL) {
 		kread(X_NCHSTATS, &lnchstats, sizeof(lnchstats));
 	} else {
-		size_t size = sizeof(lnchstats);
+		size = sizeof(lnchstats);
 		mysysctl("vfs.cache.nchstats", &lnchstats, &size, NULL, 0);
 		if (size != sizeof(lnchstats))
 			xo_errx(1, "vfs.cache.nchstats size mismatch");
@@ -1110,17 +1091,17 @@ dosum(void)
 	    lnchstats.ncs_badhits + lnchstats.ncs_falsehits +
 	    lnchstats.ncs_miss + lnchstats.ncs_long;
 	xo_emit("{:total-name-lookups/%9ld} {N:total name lookups}\n",
-	        nchtotal);
+	    nchtotal);
 	xo_emit("{P:/%9s} {N:cache hits} "
-	        "({:positive-cache-hits/%ld}% pos + "
-	        "{:negative-cache-hits/%ld}% {N:neg}) "
-	        "system {:cache-hit-percent/%ld}% per-directory\n",
+	    "({:positive-cache-hits/%ld}% pos + "
+	    "{:negative-cache-hits/%ld}% {N:neg}) "
+	    "system {:cache-hit-percent/%ld}% per-directory\n",
 	    "", PCT(lnchstats.ncs_goodhits, nchtotal),
 	    PCT(lnchstats.ncs_neghits, nchtotal),
 	    PCT(lnchstats.ncs_pass2, nchtotal));
 	xo_emit("{P:/%9s} {L:deletions} {:deletions/%ld}%, "
-	        "{L:falsehits} {:false-hits/%ld}%, "
-	        "{L:toolong} {:too-long/%ld}%\n", "",
+	    "{L:falsehits} {:false-hits/%ld}%, "
+	    "{L:toolong} {:too-long/%ld}%\n", "",
 	    PCT(lnchstats.ncs_badhits, nchtotal),
 	    PCT(lnchstats.ncs_falsehits, nchtotal),
 	    PCT(lnchstats.ncs_long, nchtotal));
@@ -1130,20 +1111,21 @@ dosum(void)
 static void
 doforkst(void)
 {
+
 	fill_vmmeter(&sum);
 	xo_open_container("fork-statistics");
 	xo_emit("{:fork/%u} {N:forks}, {:fork-pages/%u} {N:pages}, "
-		"{L:average} {:fork-average/%.2f}\n",
+	    "{L:average} {:fork-average/%.2f}\n",
 	    sum.v_forks, sum.v_forkpages,
 	    sum.v_forks == 0 ? 0.0 :
 	    (double)sum.v_forkpages / sum.v_forks);
 	xo_emit("{:vfork/%u} {N:vforks}, {:vfork-pages/%u} {N:pages}, "
-		"{L:average} {:vfork-average/%.2f}\n",
+	    "{L:average} {:vfork-average/%.2f}\n",
 	    sum.v_vforks, sum.v_vforkpages,
 	    sum.v_vforks == 0 ? 0.0 :
 	    (double)sum.v_vforkpages / sum.v_vforks);
 	xo_emit("{:rfork/%u} {N:rforks}, {:rfork-pages/%u} {N:pages}, "
-		"{L:average} {:rfork-average/%.2f}\n",
+	    "{L:average} {:rfork-average/%.2f}\n",
 	    sum.v_rforks, sum.v_rforkpages,
 	    sum.v_rforks == 0 ? 0.0 :
 	    (double)sum.v_rforkpages / sum.v_rforks);
@@ -1153,10 +1135,9 @@ doforkst(void)
 static void
 devstats(void)
 {
-	int dn, state;
-	long double transfers_per_second;
-	long double busy_seconds;
+	long double busy_seconds, transfers_per_second;
 	long tmp;
+	int di, dn, state;
 
 	for (state = 0; state < CPUSTATES; ++state) {
 		tmp = cur.cp_time[state];
@@ -1168,10 +1149,8 @@ devstats(void)
 
 	xo_open_list("device");
 	for (dn = 0; dn < num_devices; dn++) {
-		int di;
-
-		if ((dev_select[dn].selected == 0)
-		 || (dev_select[dn].selected > maxshowdevs))
+		if (dev_select[dn].selected == 0 ||
+		    dev_select[dn].selected > maxshowdevs)
 			continue;
 
 		di = dev_select[dn].position;
@@ -1184,24 +1163,24 @@ devstats(void)
 
 		xo_open_instance("device");
 		xo_emit("{ekq:name/%c%c%d}{:transfers/%3.0Lf} ",
-			dev_select[dn].device_name[0],
-			dev_select[dn].device_name[1],
-			dev_select[dn].unit_number,
-			transfers_per_second);
+		    dev_select[dn].device_name[0],
+		    dev_select[dn].device_name[1],
+		    dev_select[dn].unit_number,
+		    transfers_per_second);
 		xo_close_instance("device");
 	}
 	xo_close_list("device");
 }
 
 static void
-percent(const char *name, double pct, int *over)
+percent(const char *name, double pctv, int *over)
 {
+	int l;
 	char buf[10];
 	char fmt[128];
-	int l;
 
 	snprintf(fmt, sizeof(fmt), " {:%s/%%*s}", name);
-	l = snprintf(buf, sizeof(buf), "%.0f", pct);
+	l = snprintf(buf, sizeof(buf), "%.0f", pctv);
 	if (l == 1 && *over) {
 		xo_emit(fmt, 1, buf);
 		(*over)--;
@@ -1214,8 +1193,8 @@ percent(const char *name, double pct, int *over)
 static void
 cpustats(void)
 {
-	int state, over;
 	double lpct, total;
+	int state, over;
 
 	total = 0;
 	for (state = 0; state < CPUSTATES; ++state)
@@ -1226,19 +1205,20 @@ cpustats(void)
 		lpct = 0.0;
 	over = 0;
 	xo_open_container("cpu-statistics");
-	percent("user", (cur.cp_time[CP_USER] + cur.cp_time[CP_NICE]) * lpct, &over);
-	percent("system", (cur.cp_time[CP_SYS] + cur.cp_time[CP_INTR]) * lpct, &over);
+	percent("user", (cur.cp_time[CP_USER] + cur.cp_time[CP_NICE]) * lpct,
+	    &over);
+	percent("system", (cur.cp_time[CP_SYS] + cur.cp_time[CP_INTR]) * lpct,
+	    &over);
 	percent("idle", cur.cp_time[CP_IDLE] * lpct, &over);
 	xo_close_container("cpu-statistics");
 }
 
 static void
-pcpustats(int ncpus, u_long cpumask, int maxid)
+pcpustats(u_long cpumask, int maxid)
 {
-	int state, i;
 	double lpct, total;
 	long tmp;
-	int over;
+	int i, over, state;
 
 	/* devstats does this for cp_time */
 	for (i = 0; i <= maxid; i++) {
@@ -1267,11 +1247,11 @@ pcpustats(int ncpus, u_long cpumask, int maxid)
 		else
 			lpct = 0.0;
 		percent("user", (cur_cp_times[i * CPUSTATES + CP_USER] +
-			 cur_cp_times[i * CPUSTATES + CP_NICE]) * lpct, &over);
+		    cur_cp_times[i * CPUSTATES + CP_NICE]) * lpct, &over);
 		percent("system", (cur_cp_times[i * CPUSTATES + CP_SYS] +
-			 cur_cp_times[i * CPUSTATES + CP_INTR]) * lpct, &over);
+		    cur_cp_times[i * CPUSTATES + CP_INTR]) * lpct, &over);
 		percent("idle", cur_cp_times[i * CPUSTATES + CP_IDLE] * lpct,
-			&over);
+		    &over);
 		xo_close_instance("cpu");
 	}
 	xo_close_list("cpu");
@@ -1303,12 +1283,12 @@ read_intrcnts(unsigned long **intrcnts)
 
 static void
 print_intrcnts(unsigned long *intrcnts, unsigned long *old_intrcnts,
-		char *intrnames, unsigned int nintr,
-		size_t istrnamlen, long long period_ms)
+    char *intrnames, unsigned int nintr, size_t istrnamlen, long long period_ms)
 {
 	unsigned long *intrcnt, *old_intrcnt;
+	char *intrname;
 	uint64_t inttotal, old_inttotal, total_count, total_rate;
-	char* intrname;
+	unsigned long count, rate;
 	unsigned int i;
 
 	inttotal = 0;
@@ -1317,15 +1297,12 @@ print_intrcnts(unsigned long *intrcnts, unsigned long 
 	xo_open_list("interrupt");
 	for (i = 0, intrcnt=intrcnts, old_intrcnt=old_intrcnts; i < nintr; i++) {
 		if (intrname[0] != '\0' && (*intrcnt != 0 || aflag)) {
-			unsigned long count, rate;
-
 			count = *intrcnt - *old_intrcnt;
 			rate = (count * 1000 + period_ms / 2) / period_ms;
 			xo_open_instance("interrupt");
 			xo_emit("{d:name/%-*s}{ket:name/%s} "
 			    "{:total/%20lu} {:rate/%10lu}\n",
-			    (int)istrnamlen, intrname,
-			    intrname, count, rate);
+			    (int)istrnamlen, intrname, intrname, count, rate);
 			xo_close_instance("interrupt");
 		}
 		intrname += strlen(intrname) + 1;
@@ -1335,20 +1312,21 @@ print_intrcnts(unsigned long *intrcnts, unsigned long 
 	total_count = inttotal - old_inttotal;
 	total_rate = (total_count * 1000 + period_ms / 2) / period_ms;
 	xo_close_list("interrupt");
-	xo_emit("{L:/%-*s} {:total-interrupts/%20" PRIu64 "} "
-	        "{:total-rate/%10" PRIu64 "}\n", (int)istrnamlen,
-	        "Total", total_count, total_rate);
+	xo_emit("{L:/%-*s} {:total-interrupts/%20ju} "
+	    "{:total-rate/%10ju}\n", (int)istrnamlen,
+	    "Total", (uintmax_t)total_count, (uintmax_t)total_rate);
 }
 
 static void
 dointr(unsigned int interval, int reps)
 {
-	unsigned long *intrcnts;
-	long long uptime, period_ms;
-	unsigned long *old_intrcnts = NULL;
+	unsigned long *intrcnts, *old_intrcnts;
+	char *intrname, *intrnames;
+	long long period_ms, old_uptime, uptime;
 	size_t clen, inamlen, istrnamlen;
-	char *intrnames, *intrname;
+	unsigned int nintr;
 
+	old_intrcnts = NULL;
 	uptime = getuptime();
 
 	/* Get the names of each interrupt source */
@@ -1377,7 +1355,7 @@ dointr(unsigned int interval, int reps)
 		intrname += strlen(intrname) + 1;
 	}
 	xo_emit("{T:/%-*s} {T:/%20s} {T:/%10s}\n",
-	        (int)istrnamlen, "interrupt", "total", "rate");
+	    (int)istrnamlen, "interrupt", "total", "rate");
 
 	/* 
 	 * Loop reps times printing differential interrupt counts.  If reps is
@@ -1387,9 +1365,6 @@ dointr(unsigned int interval, int reps)
 
 	period_ms = uptime / 1000000;
 	while(1) {
-		unsigned int nintr;
-		long long old_uptime;
-
 		nintr = read_intrcnts(&intrcnts);
 		/* 
 		 * Initialize old_intrcnts to 0 for the first pass, so
@@ -1449,7 +1424,7 @@ domemstat_malloc(void)
 	}
 	xo_open_container("malloc-statistics");
 	xo_emit("{T:/%13s} {T:/%5s} {T:/%6s} {T:/%7s} {T:/%8s}  {T:Size(s)}\n",
-		"Type", "InUse", "MemUse", "HighUse", "Requests");
+	    "Type", "InUse", "MemUse", "HighUse", "Requests");
 	xo_open_list("memory");
 	for (mtp = memstat_mtl_first(mtlp); mtp != NULL;
 	    mtp = memstat_mtl_next(mtp)) {
@@ -1457,12 +1432,12 @@ domemstat_malloc(void)
 		    memstat_get_count(mtp) == 0)
 			continue;
 		xo_open_instance("memory");
-		xo_emit("{k:type/%13s/%s} {:in-use/%5" PRIu64 "} "
-			"{:memory-use/%5" PRIu64 "}{U:K} {:high-use/%7s} "
-			"{:requests/%8" PRIu64 "}  ",
-		    memstat_get_name(mtp), memstat_get_count(mtp),
-		    (memstat_get_bytes(mtp) + 1023) / 1024, "-",
-		    memstat_get_numallocs(mtp));
+		xo_emit("{k:type/%13s/%s} {:in-use/%5ju} "
+		    "{:memory-use/%5ju}{U:K} {:high-use/%7s} "
+		    "{:requests/%8ju}  ",
+		    memstat_get_name(mtp), (uintmax_t)memstat_get_count(mtp),
+		    ((uintmax_t)memstat_get_bytes(mtp) + 1023) / 1024, "-",
+		    (uintmax_t)memstat_get_numallocs(mtp));
 		first = 1;
 		xo_open_list("size");
 		for (i = 0; i < 32; i++) {
@@ -1487,8 +1462,8 @@ domemstat_zone(void)
 {
 	struct memory_type_list *mtlp;
 	struct memory_type *mtp;
-	char name[MEMTYPE_MAXNAME + 1];
 	int error;
+	char name[MEMTYPE_MAXNAME + 1];
 
 	mtlp = memstat_mtl_alloc();
 	if (mtlp == NULL) {
@@ -1514,23 +1489,26 @@ domemstat_zone(void)
 	}
 	xo_open_container("memory-zone-statistics");
 	xo_emit("{T:/%-20s} {T:/%6s} {T:/%6s} {T:/%8s} {T:/%8s} {T:/%8s} "
-		"{T:/%4s} {T:/%4s}\n\n", "ITEM", "SIZE",
-		"LIMIT", "USED", "FREE", "REQ", "FAIL", "SLEEP");
+	    "{T:/%4s} {T:/%4s}\n\n", "ITEM", "SIZE",
+	    "LIMIT", "USED", "FREE", "REQ", "FAIL", "SLEEP");
 	xo_open_list("zone");
 	for (mtp = memstat_mtl_first(mtlp); mtp != NULL;
 	    mtp = memstat_mtl_next(mtp)) {
 		strlcpy(name, memstat_get_name(mtp), MEMTYPE_MAXNAME);
 		strcat(name, ":");
 		xo_open_instance("zone");
-		xo_emit("{d:name/%-20s}{ke:name/%s} {:size/%6" PRIu64 "}, "
-			"{:limit/%6" PRIu64 "},{:used/%8" PRIu64 "},"

*** DIFF OUTPUT TRUNCATED AT 1000 LINES ***



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201810162053.w9GKrHtO037028>