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: Sanskriti Sharma <sansharm@redhat.com>
This commit is contained in:
Sanskriti Sharma 2018-08-08 11:48:32 -04:00 committed by Craig Small
parent 7a6437ce42
commit 528158ed77

View File

@ -80,6 +80,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;
@ -232,6 +235,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);
@ -378,6 +382,15 @@ static void new_format(void)
if (procps_meminfo_new(&mem_info) < 0)
xerrx(EXIT_FAILURE, _("Unable to create meminfo structure"));
pgpgin[tog] = VMSTAT_GET(vm_info, VMSTAT_PGPGIN, ul_int);
pgpgout[tog] = VMSTAT_GET(vm_info, VMSTAT_PGPGOUT, ul_int);
pswpin[tog] = VMSTAT_GET(vm_info, VMSTAT_PSWPIN, ul_int);
pswpout[tog] = VMSTAT_GET(vm_info, VMSTAT_PSWPOUT, ul_int);
if (!(mem_stack = procps_meminfo_select(mem_info, Mem_items, MAX_mem)))
xerrx(EXIT_FAILURE, _("Unable to select memory information"));
if (y_option == 0) {
if (t_option) {
(void) time( &the_time );
tm_ptr = localtime( &the_time );
@ -397,14 +410,6 @@ static void new_format(void)
cpu_sto = TICv(stat_STO);
cpu_gue = TICv(stat_GST) + TICv(stat_GNI);
pgpgin[tog] = VMSTAT_GET(vm_info, VMSTAT_PGPGIN, ul_int);
pgpgout[tog] = VMSTAT_GET(vm_info, VMSTAT_PGPGOUT, ul_int);
pswpin[tog] = VMSTAT_GET(vm_info, VMSTAT_PSWPIN, ul_int);
pswpout[tog] = VMSTAT_GET(vm_info, VMSTAT_PSWPOUT, ul_int);
if (!(mem_stack = procps_meminfo_select(mem_info, Mem_items, MAX_mem)))
xerrx(EXIT_FAILURE, _("Unable to select memory information"));
Div = cpu_use + cpu_sys + cpu_idl + cpu_iow + cpu_sto;
if (!Div) {
Div = 1;
@ -439,6 +444,8 @@ static void new_format(void)
}
printf("\n");
} else
num_updates++;
/* main loop */
for (i = 1; infinite_updates || i < num_updates; i++) {
@ -944,6 +951,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}
};
@ -956,7 +964,7 @@ int main(int argc, char *argv[])
atexit(close_stdout);
while ((c =
getopt_long(argc, argv, "afmnsdDp:S:wthV", longopts, NULL)) != -1)
getopt_long(argc, argv, "afmnsdDp:S:wthVy", longopts, NULL)) != -1)
switch (c) {
case 'V':
printf(PROCPS_NG_VERSION);
@ -1023,6 +1031,10 @@ 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);