Commit 85d65bbc authored by Sanskriti Sharma's avatar Sanskriti Sharma

vmstat: Provides option to omit first report

The first report from vmstat provides statistics since system boot. This is
often thrown out. Thus, this provides a command line option to omit it. The
program still provides <count> reports.
Signed-off-by: 's avatarSanskriti Sharma <sansharm@redhat.com>
parent 5e1c339b
Pipeline #27799488 passed with stage
in 2 minutes and 56 seconds
......@@ -87,6 +87,9 @@ Display version information and exit.
.TP
\fB\-h\fR, \fB\-\-help\fR
Display help and exit.
.TP
\fB\-y\fR, \fB\-\-no-first\fR
Omits first report with statistics since system boot.
.PD
.SH "FIELD DESCRIPTION FOR VM MODE"
.SS
......
......@@ -75,6 +75,9 @@ static int a_option;
/* "-w" means "wide output" */
static int w_option;
/* "-y" means "skip first output" */
static int y_option;
/* "-t" means "show timestamp" */
static int t_option;
......@@ -104,6 +107,7 @@ static void __attribute__ ((__noreturn__))
fputs(_(" -S, --unit <char> define display unit\n"), out);
fputs(_(" -w, --wide wide output\n"), out);
fputs(_(" -t, --timestamp show timestamp\n"), out);
fputs(_(" -y, --no-first skips first line of output\n"), out);
fputs(USAGE_SEPARATOR, out);
fputs(USAGE_HELP, out);
fputs(USAGE_VERSION, out);
......@@ -307,12 +311,14 @@ static void new_format(void)
cpu_zzz, pgpgin, pgpgout, pswpin, pswpout, intr, ctxt, &running,
&blocked, &dummy_1, &dummy_2);
if (y_option == 0) {
if (t_option) {
(void) time( &the_time );
tm_ptr = localtime( &the_time );
if (tm_ptr && strftime(timebuf, sizeof(timebuf), "%Y-%m-%d %H:%M:%S", tm_ptr)) {
;
} else {
}
else {
timebuf[0] = '\0';
}
}
......@@ -348,6 +354,9 @@ static void new_format(void)
}
printf("\n");
}
else
num_updates++;
/* main loop */
for (i = 1; infinite_updates || i < num_updates; i++) {
......@@ -887,6 +896,7 @@ int main(int argc, char *argv[])
{"timestamp", no_argument, NULL, 't'},
{"help", no_argument, NULL, 'h'},
{"version", no_argument, NULL, 'V'},
{"no-first", no_argument, NULL, 'y'},
{NULL, 0, NULL, 0}
};
......@@ -899,7 +909,7 @@ int main(int argc, char *argv[])
atexit(close_stdout);
while ((c =
getopt_long(argc, argv, "afmnsdDp:S:wthV", longopts,
getopt_long(argc, argv, "afmnsdDp:S:wthVy", longopts,
NULL)) != -1)
switch (c) {
case 'V':
......@@ -968,6 +978,11 @@ int main(int argc, char *argv[])
case 't':
t_option = 1;
break;
case 'y':
/* Don't display stats since system restart */
y_option = 1;
break;
default:
/* no other aguments defined yet. */
usage(stderr);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment