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:
parent
7a6437ce42
commit
528158ed77
30
vmstat.c
30
vmstat.c
@ -80,6 +80,9 @@ static int a_option;
|
|||||||
/* "-w" means "wide output" */
|
/* "-w" means "wide output" */
|
||||||
static int w_option;
|
static int w_option;
|
||||||
|
|
||||||
|
/* "-y" means "skip first output" */
|
||||||
|
static int y_option;
|
||||||
|
|
||||||
/* "-t" means "show timestamp" */
|
/* "-t" means "show timestamp" */
|
||||||
static int t_option;
|
static int t_option;
|
||||||
|
|
||||||
@ -232,6 +235,7 @@ static void __attribute__ ((__noreturn__))
|
|||||||
fputs(_(" -S, --unit <char> define display unit\n"), out);
|
fputs(_(" -S, --unit <char> define display unit\n"), out);
|
||||||
fputs(_(" -w, --wide wide output\n"), out);
|
fputs(_(" -w, --wide wide output\n"), out);
|
||||||
fputs(_(" -t, --timestamp show timestamp\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_SEPARATOR, out);
|
||||||
fputs(USAGE_HELP, out);
|
fputs(USAGE_HELP, out);
|
||||||
fputs(USAGE_VERSION, out);
|
fputs(USAGE_VERSION, out);
|
||||||
@ -378,6 +382,15 @@ static void new_format(void)
|
|||||||
if (procps_meminfo_new(&mem_info) < 0)
|
if (procps_meminfo_new(&mem_info) < 0)
|
||||||
xerrx(EXIT_FAILURE, _("Unable to create meminfo structure"));
|
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) {
|
if (t_option) {
|
||||||
(void) time( &the_time );
|
(void) time( &the_time );
|
||||||
tm_ptr = localtime( &the_time );
|
tm_ptr = localtime( &the_time );
|
||||||
@ -397,14 +410,6 @@ static void new_format(void)
|
|||||||
cpu_sto = TICv(stat_STO);
|
cpu_sto = TICv(stat_STO);
|
||||||
cpu_gue = TICv(stat_GST) + TICv(stat_GNI);
|
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;
|
Div = cpu_use + cpu_sys + cpu_idl + cpu_iow + cpu_sto;
|
||||||
if (!Div) {
|
if (!Div) {
|
||||||
Div = 1;
|
Div = 1;
|
||||||
@ -439,6 +444,8 @@ static void new_format(void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
printf("\n");
|
printf("\n");
|
||||||
|
} else
|
||||||
|
num_updates++;
|
||||||
|
|
||||||
/* main loop */
|
/* main loop */
|
||||||
for (i = 1; infinite_updates || i < num_updates; i++) {
|
for (i = 1; infinite_updates || i < num_updates; i++) {
|
||||||
@ -944,6 +951,7 @@ int main(int argc, char *argv[])
|
|||||||
{"timestamp", no_argument, NULL, 't'},
|
{"timestamp", no_argument, NULL, 't'},
|
||||||
{"help", no_argument, NULL, 'h'},
|
{"help", no_argument, NULL, 'h'},
|
||||||
{"version", no_argument, NULL, 'V'},
|
{"version", no_argument, NULL, 'V'},
|
||||||
|
{"no-first", no_argument, NULL, 'y'},
|
||||||
{NULL, 0, NULL, 0}
|
{NULL, 0, NULL, 0}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -956,7 +964,7 @@ int main(int argc, char *argv[])
|
|||||||
atexit(close_stdout);
|
atexit(close_stdout);
|
||||||
|
|
||||||
while ((c =
|
while ((c =
|
||||||
getopt_long(argc, argv, "afmnsdDp:S:wthV", longopts, NULL)) != -1)
|
getopt_long(argc, argv, "afmnsdDp:S:wthVy", longopts, NULL)) != -1)
|
||||||
switch (c) {
|
switch (c) {
|
||||||
case 'V':
|
case 'V':
|
||||||
printf(PROCPS_NG_VERSION);
|
printf(PROCPS_NG_VERSION);
|
||||||
@ -1023,6 +1031,10 @@ int main(int argc, char *argv[])
|
|||||||
case 't':
|
case 't':
|
||||||
t_option = 1;
|
t_option = 1;
|
||||||
break;
|
break;
|
||||||
|
case 'y':
|
||||||
|
/* Don't display stats since system restart */
|
||||||
|
y_option = 1;
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
/* no other aguments defined yet. */
|
/* no other aguments defined yet. */
|
||||||
usage(stderr);
|
usage(stderr);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user