summaryrefslogtreecommitdiffstats
path: root/usr.bin/vmstat
diff options
context:
space:
mode:
authorsjg <sjg@FreeBSD.org>2014-11-19 01:07:58 +0000
committersjg <sjg@FreeBSD.org>2014-11-19 01:07:58 +0000
commitb137080f19736ee33fede2e88bb54438604cf86b (patch)
tree377ac0ac449528621eb192cd245adadb5fd53668 /usr.bin/vmstat
parentab21a29eb607d4dfe389b965fbdee27558e791aa (diff)
parent4a8d07956d121238d006d34ffe7d6269744e8b1a (diff)
downloadFreeBSD-src-b137080f19736ee33fede2e88bb54438604cf86b.zip
FreeBSD-src-b137080f19736ee33fede2e88bb54438604cf86b.tar.gz
Merge from head@274682
Diffstat (limited to 'usr.bin/vmstat')
-rw-r--r--usr.bin/vmstat/vmstat.830
-rw-r--r--usr.bin/vmstat/vmstat.c77
2 files changed, 70 insertions, 37 deletions
diff --git a/usr.bin/vmstat/vmstat.8 b/usr.bin/vmstat/vmstat.8
index f04cc42..4566ad2 100644
--- a/usr.bin/vmstat/vmstat.8
+++ b/usr.bin/vmstat/vmstat.8
@@ -28,7 +28,7 @@
.\" @(#)vmstat.8 8.1 (Berkeley) 6/6/93
.\" $FreeBSD$
.\"
-.Dd October 21, 2006
+.Dd August 8, 2014
.Dt VMSTAT 8
.Os
.Sh NAME
@@ -38,9 +38,8 @@
.Nm
.\" .Op Fl fimst
.Op Fl afHhimPsz
-.Op Fl c Ar count
.Op Fl M Ar core Op Fl N Ar system
-.Op Fl w Ar wait
+.Op Fl c Ar count
.Op Fl n Ar devs
.Oo
.Fl p
@@ -48,7 +47,9 @@
.Ar type , if , pass
.Sm on
.Oc
-.Op Ar disks
+.Op Fl w Ar wait
+.Op Ar disks ...
+.Op wait Op count
.Sh DESCRIPTION
The
.Nm
@@ -91,10 +92,12 @@ and
system calls since system startup, and the number of pages of virtual memory
involved in each.
.It Fl h
-Changes memory columns into more easily human readable form. Default if
+Changes memory columns into more easily human readable form.
+The default if
standard output is a terminal device.
.It Fl H
-Changes memory columns into straight numbers. Default if standard output
+Changes memory columns into straight numbers.
+The default if standard output
is not a terminal device (such as a script).
.It Fl i
Report on the number of interrupts taken by each device since system
@@ -214,6 +217,21 @@ Report on memory used by the kernel zone allocator,
by zone.
.El
.Pp
+The
+.Ar wait
+and
+.Ar count
+arguments may be given after their respective flags at any point
+on the command line before the
+.Ar disks
+argument(s), or without their flags, as the final argument(s).
+The latter form is accepted for backwards compatibility, but it is
+preferred to use the forms with
+.Fl w
+and
+.Fl c
+to avoid ambiguity.
+.Pp
By default,
.Nm
displays the following information:
diff --git a/usr.bin/vmstat/vmstat.c b/usr.bin/vmstat/vmstat.c
index 67f438e..760dce8 100644
--- a/usr.bin/vmstat/vmstat.c
+++ b/usr.bin/vmstat/vmstat.c
@@ -299,15 +299,12 @@ retry_nlist:
argv = getdrivedata(argv);
}
-#define BACKWARD_COMPATIBILITY
-#ifdef BACKWARD_COMPATIBILITY
if (*argv) {
f = atof(*argv);
interval = f * 1000;
if (*++argv)
reps = atoi(*argv);
}
-#endif
if (interval) {
if (!reps)
@@ -660,6 +657,8 @@ dovmstat(unsigned int interval, int reps)
uptime = getuptime();
halfuptime = uptime / 2;
rate_adj = 1;
+ ncpus = 1;
+ maxid = 0;
/*
* If the user stops the program (control-Z) and then resumes it,
@@ -705,7 +704,7 @@ dovmstat(unsigned int interval, int reps)
}
for (hdrcnt = 1;;) {
if (!--hdrcnt)
- printhdr(ncpus, cpumask);
+ printhdr(maxid, cpumask);
if (kd != NULL) {
if (kvm_getcptime(kd, cur.cp_time) < 0)
errx(1, "kvm_getcptime: %s", kvm_geterr(kd));
@@ -756,7 +755,7 @@ dovmstat(unsigned int interval, int reps)
errx(1, "%s", devstat_errbuf);
break;
case 1:
- printhdr(ncpus, cpumask);
+ printhdr(maxid, cpumask);
break;
default:
break;
@@ -768,22 +767,26 @@ dovmstat(unsigned int interval, int reps)
fill_vmmeter(&sum);
fill_vmtotal(&total);
- (void)printf("%2d %1d %1d",
+ (void)printf("%1d %1d %1d",
total.t_rq - 1, total.t_dw + total.t_pw, total.t_sw);
#define vmstat_pgtok(a) ((a) * (sum.v_page_size >> 10))
#define rate(x) (((x) * rate_adj + halfuptime) / uptime) /* round */
if (hflag) {
+ printf("");
+ prthuman(total.t_avm * (u_int64_t)sum.v_page_size, 5);
printf(" ");
- prthuman(total.t_avm * (u_int64_t)sum.v_page_size, 7);
- printf(" ");
- prthuman(total.t_free * (u_int64_t)sum.v_page_size, 6);
+ prthuman(total.t_free * (u_int64_t)sum.v_page_size, 5);
printf(" ");
+ (void)printf("%5lu ",
+ (unsigned long)rate(sum.v_vm_faults -
+ osum.v_vm_faults));
} else {
- printf(" %7d ", vmstat_pgtok(total.t_avm));
- printf(" %6d ", vmstat_pgtok(total.t_free));
+ printf(" %7d", vmstat_pgtok(total.t_avm));
+ printf(" %7d ", vmstat_pgtok(total.t_free));
+ (void)printf("%4lu ",
+ (unsigned long)rate(sum.v_vm_faults -
+ osum.v_vm_faults));
}
- (void)printf("%5lu ",
- (unsigned long)rate(sum.v_vm_faults - osum.v_vm_faults));
(void)printf("%3lu ",
(unsigned long)rate(sum.v_reactivated - osum.v_reactivated));
(void)printf("%3lu ",
@@ -794,10 +797,10 @@ dovmstat(unsigned int interval, int reps)
(osum.v_swapout + osum.v_vnodeout)));
(void)printf("%5lu ",
(unsigned long)rate(sum.v_tfree - osum.v_tfree));
- (void)printf("%3lu ",
+ (void)printf("%4lu ",
(unsigned long)rate(sum.v_pdpages - osum.v_pdpages));
devstats();
- (void)printf("%4lu %4lu %4lu",
+ (void)printf("%4lu %5lu %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));
@@ -825,36 +828,46 @@ dovmstat(unsigned int interval, int reps)
}
static void
-printhdr(int ncpus, u_long cpumask)
+printhdr(int maxid, u_long cpumask)
{
int i, num_shown;
num_shown = (num_selected < maxshowdevs) ? num_selected : maxshowdevs;
- (void)printf(" procs memory page%*s", 19, "");
+ if (hflag) {
+ (void)printf("procs memory page%*s ", 19, "");
+ } else {
+ (void)printf("procs memory page%*s ", 19, "");
+ }
if (num_shown > 1)
- (void)printf(" disks %*s", num_shown * 4 - 7, "");
+ (void)printf(" disks %*s", num_shown * 4 - 7, "");
else if (num_shown == 1)
- (void)printf("disk");
- (void)printf(" faults ");
+ (void)printf(" disk");
+ (void)printf(" faults ");
if (Pflag) {
- for (i = 0; i < ncpus; i++) {
+ for (i = 0; i <= maxid; i++) {
if (cpumask & (1ul << i))
- printf("cpu%-2d ", i);
+ printf(" cpu%d ", i);
}
printf("\n");
} else
- printf("cpu\n");
- (void)printf(" r b w avm fre flt re pi po fr sr ");
+ printf(" cpu\n");
+ if (hflag) {
+ (void)printf("r b w avm fre flt re pi po fr sr ");
+ } else {
+ (void)printf("r b w avm fre flt re pi po fr sr ");
+ }
for (i = 0; i < num_devices; i++)
if ((dev_select[i].selected)
&& (dev_select[i].selected <= maxshowdevs))
(void)printf("%c%c%d ", dev_select[i].device_name[0],
dev_select[i].device_name[1],
dev_select[i].unit_number);
- (void)printf(" in sy cs");
+ (void)printf(" in sy cs");
if (Pflag) {
- for (i = 0; i < ncpus; i++)
- printf(" us sy id");
+ for (i = 0; i <= maxid; i++) {
+ if (cpumask & (1ul << i))
+ printf(" us sy id");
+ }
printf("\n");
} else
printf(" us sy id\n");
@@ -981,7 +994,8 @@ dosum(void)
(void)printf("%9u intransit blocking page faults\n", sum.v_intrans);
(void)printf("%9u total VM faults taken\n", sum.v_vm_faults);
(void)printf("%9u page faults requiring I/O\n", sum.v_io_faults);
- (void)printf("%9u pages affected by kernel thread creation\n", sum.v_kthreadpages);
+ (void)printf("%9u pages affected by kernel thread creation\n",
+ sum.v_kthreadpages);
(void)printf("%9u pages affected by fork()\n", sum.v_forkpages);
(void)printf("%9u pages affected by vfork()\n", sum.v_vforkpages);
(void)printf("%9u pages affected by rfork()\n", sum.v_rforkpages);
@@ -1123,7 +1137,8 @@ pcpustats(int ncpus, u_long cpumask, int maxid)
continue;
for (state = 0; state < CPUSTATES; ++state) {
tmp = cur_cp_times[i * CPUSTATES + state];
- cur_cp_times[i * CPUSTATES + state] -= last_cp_times[i * CPUSTATES + state];
+ cur_cp_times[i * CPUSTATES + state] -= last_cp_times[i *
+ CPUSTATES + state];
last_cp_times[i * CPUSTATES + state] = tmp;
}
}
@@ -1360,7 +1375,7 @@ static void
usage(void)
{
(void)fprintf(stderr, "%s%s",
- "usage: vmstat [-afHhimPsz] [-c count] [-M core [-N system]] [-w wait]\n",
- " [-n devs] [-p type,if,pass] [disks]\n");
+ "usage: vmstat [-afHhimPsz] [-M core [-N system]] [-c count] [-n devs]\n",
+ " [-p type,if,pass] [-w wait] [disks] [wait [count]]\n");
exit(1);
}
OpenPOWER on IntegriCloud