From d8b6843aca3286d966d414dcaca7f3673f415970 Mon Sep 17 00:00:00 2001 From: Miles Bader Date: Mon, 14 Jul 1997 22:50:32 +0000 Subject: (main): Don't print fields we cannot get. --- utils/vmstat.c | 36 +++++++++++++++++++++++------------- 1 file changed, 23 insertions(+), 13 deletions(-) diff --git a/utils/vmstat.c b/utils/vmstat.c index 418f2878..bada18f9 100644 --- a/utils/vmstat.c +++ b/utils/vmstat.c @@ -567,17 +567,24 @@ main (int argc, char **argv) for (field = fields, num = 0, first = 1; field->name; field++, num++) if (output_fields & (1 << (field - fields))) { - int sign = 0; val_t val = vm_state_get_field (&state, field); - if (repeats && field->change_type == CUMUL) + if (val < 0) + /* Couldn't fetch this field, don't try again. */ + const_fields &= ~(1 << (field - fields)); + else { - sign = 1; - val -= vm_state_get_field (&prev_state, field); - } + int sign = 0; - PSEP (" ", 0); - PVAL (val, field, fwidths[num], sign); + if (repeats && field->change_type == CUMUL) + { + sign = 1; + val -= vm_state_get_field (&prev_state, field); + } + + PSEP (" ", 0); + PVAL (val, field, fwidths[num], sign); + } } putchar ('\n'); @@ -617,14 +624,17 @@ main (int argc, char **argv) if (output_fields & (1 << (field - fields))) { val_t val = vm_state_get_field (&state, field); - int fwidth = 0; - if (print_prefix) + if (val >= 0) { - printf ("%s: ", field->name); - fwidth = max_width - strlen (field->name); + int fwidth = 0; + if (print_prefix) + { + printf ("%s: ", field->name); + fwidth = max_width - strlen (field->name); + } + PVAL (val, field, fwidth, 0); + putchar ('\n'); } - PVAL (val, field, fwidth, 0); - putchar ('\n'); } } -- cgit v1.2.3