summaryrefslogtreecommitdiffstats
path: root/usr.bin/vmstat
diff options
context:
space:
mode:
authorsbruno <sbruno@FreeBSD.org>2010-05-21 17:10:52 +0000
committersbruno <sbruno@FreeBSD.org>2010-05-21 17:10:52 +0000
commitd60c486b8837161509dbd904a6a44af49249ef8a (patch)
tree56522a4131784ea7422f6a54a563401513353b18 /usr.bin/vmstat
parentec26a9488b14e8d1ed236fc5c08772c155ea9ce8 (diff)
downloadFreeBSD-src-d60c486b8837161509dbd904a6a44af49249ef8a.zip
FreeBSD-src-d60c486b8837161509dbd904a6a44af49249ef8a.tar.gz
Allow sub-second interval timings for iostat and vmstat.
e.g. vmstat -w.5 iostat -w.5 Reviewed by: jhb Approved by: scottl (mentor) Obtained from: Yahoo Inc. MFC after: 2 weeks
Diffstat (limited to 'usr.bin/vmstat')
-rw-r--r--usr.bin/vmstat/vmstat.83
-rw-r--r--usr.bin/vmstat/vmstat.c20
2 files changed, 17 insertions, 6 deletions
diff --git a/usr.bin/vmstat/vmstat.8 b/usr.bin/vmstat/vmstat.8
index d810978..81a5906 100644
--- a/usr.bin/vmstat/vmstat.8
+++ b/usr.bin/vmstat/vmstat.8
@@ -209,6 +209,9 @@ seconds between each display.
If no repeat
.Ar wait
interval is specified, the default is 1 second.
+The
+.Nm
+command will accept and honor a non-integer number of seconds.
.It Fl z
Report on memory used by the kernel zone allocator,
.Xr uma 9 ,
diff --git a/usr.bin/vmstat/vmstat.c b/usr.bin/vmstat/vmstat.c
index cf4b73a..4105a36 100644
--- a/usr.bin/vmstat/vmstat.c
+++ b/usr.bin/vmstat/vmstat.c
@@ -57,6 +57,7 @@ __FBSDID("$FreeBSD$");
#include <sys/ioctl.h>
#include <sys/resource.h>
#include <sys/sysctl.h>
+#include <sys/time.h>
#include <sys/vmmeter.h>
#include <sys/pcpu.h>
@@ -181,6 +182,7 @@ main(int argc, char *argv[])
{
int c, todo;
unsigned int interval;
+ float f;
int reps;
char *memf, *nlistf;
char errbuf[_POSIX2_LINE_MAX];
@@ -243,7 +245,9 @@ main(int argc, char *argv[])
#endif
break;
case 'w':
- interval = atoi(optarg);
+ /* Convert to milliseconds. */
+ f = atof(optarg);
+ interval = f * 1000;
break;
case 'z':
todo |= ZMEMSTAT;
@@ -298,7 +302,8 @@ main(int argc, char *argv[])
#define BACKWARD_COMPATIBILITY
#ifdef BACKWARD_COMPATIBILITY
if (*argv) {
- interval = atoi(*argv);
+ f = atof(*argv);
+ interval = f * 1000;
if (*++argv)
reps = atoi(*argv);
}
@@ -308,7 +313,7 @@ main(int argc, char *argv[])
if (!reps)
reps = -1;
} else if (reps)
- interval = 1;
+ interval = 1 * 1000;
if (todo & FORKSTAT)
doforkst();
@@ -652,9 +657,11 @@ dovmstat(unsigned int interval, int reps)
size_t size;
int ncpus, maxid;
u_long cpumask;
+ int rate_adj;
uptime = getuptime();
halfuptime = uptime / 2;
+ rate_adj = 1;
/*
* If the user stops the program (control-Z) and then resumes it,
@@ -766,7 +773,7 @@ dovmstat(unsigned int interval, int reps)
(void)printf("%2d %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) + halfuptime) / uptime) /* round */
+#define rate(x) (((x) * rate_adj + halfuptime) / uptime) /* round */
if (hflag) {
printf(" ");
prthuman(total.t_avm * (u_int64_t)sum.v_page_size, 7);
@@ -806,15 +813,16 @@ dovmstat(unsigned int interval, int reps)
break;
osum = sum;
uptime = interval;
+ rate_adj = 1000;
/*
* We round upward to avoid losing low-frequency events
- * (i.e., >= 1 per interval but < 1 per second).
+ * (i.e., >= 1 per interval but < 1 per millisecond).
*/
if (interval != 1)
halfuptime = (uptime + 1) / 2;
else
halfuptime = 0;
- (void)sleep(interval);
+ (void)usleep(interval * 1000);
}
}
OpenPOWER on IntegriCloud