diff options
| -rw-r--r-- | procps/vmstat.c | 42 |
1 files changed, 29 insertions, 13 deletions
diff --git a/procps/vmstat.c b/procps/vmstat.c index 2f9558e17..f479dbecf 100644 --- a/procps/vmstat.c +++ b/procps/vmstat.c | |||
| @@ -372,25 +372,41 @@ static void print_row(const unsigned data[NCOLS], | |||
| 372 | if ((col.mod & MOD_DECREMENT) && value) | 372 | if ((col.mod & MOD_DECREMENT) && value) |
| 373 | value--; | 373 | value--; |
| 374 | 374 | ||
| 375 | if (!is_first) | ||
| 376 | bb_putchar(' '); | ||
| 377 | is_first = 0; | ||
| 375 | /* memory can easily overflow the columns: | 378 | /* memory can easily overflow the columns: |
| 376 | * r b swpd free buff cache si so bi bo in cs us sy id wa st gu | 379 | * r b swpd free buff cache si so bi bo in cs us sy id wa st gu |
| 377 | * 3 0 0 2019152 1029788 8602060 0 0 29 211 5699 13 9 5 86 0 0 0 | 380 | * 3 0 0 2019152 1029788 8602060 0 0 29 211 5699 13 9 5 86 0 0 0 |
| 378 | * ^ ^ ^ shortened width was here | 381 | * ^-------^-------^-attempt to shorten width here |
| 379 | * To improve this, shorten the requested field width if previous field overflowed. | 382 | * To improve this, shorten the next field width if previous field overflowed. |
| 380 | */ | 383 | */ |
| 384 | //TODO: more improvements: | ||
| 385 | //Shift left entire set of memory fields if it has space padding and overruns at the right, | ||
| 386 | //as in the example above (zero bytes in swap: can replace " 0" with "0" to make data fit). | ||
| 381 | { | 387 | { |
| 382 | int digits_printed, width; | 388 | int chars_printed, width; |
| 383 | width = (col.width - overrun >= 0 ? col.width - overrun : 0); | 389 | width = (col.width - overrun >= 0 ? col.width - overrun : 0); |
| 384 | digits_printed = printf(" %*u" + is_first, width, value) - 1 + is_first; | 390 | /* For large intervals such as "vmstat 60" (one minute), or |
| 385 | overrun += (digits_printed - col.width); | 391 | * for cases with a lot of block I/O (try 'grep -rF noT_eXisting /usr'), |
| 386 | is_first = 0; | 392 | * can use smart_ulltoa4() to format "si", "so", "in" and "cs"; |
| 387 | //TODO: more improvements: | 393 | * smart_ulltoa5() to format "bi" and "bo". |
| 388 | //Shift left entire set of memory fields if it is space-padded at the left and overruns at the right, | 394 | * This way, we can show arbitrarily large accumulated counts for these. Example: |
| 389 | //as in the example above (zero bytes in swap). | 395 | * r b swpd free buff cache si so bi bo in cs us sy id wa st gu |
| 390 | //For large intervals such as "vmstat 60" (one minute), | 396 | * 1 0 0 947636 76548 15373248 0 0 657k 23284 2.3m 4.1m 24 9 65 0 0 0 |
| 391 | //can use smart_ulltoa4() to format "si", "so", "in" and "cs"; | 397 | * Downside: incompatible output format. Do we need to make this conditional on an option? |
| 392 | //smart_ulltoa5() to format "bi" and "bo": | 398 | */ |
| 393 | //this way, we can show arbitrarily large accumucated counts for these. | 399 | if ((col.width>>1) == 4/2) { |
| 400 | char buf45[6]; | ||
| 401 | if (col.width == 4) | ||
| 402 | smart_ulltoa4(value, buf45, " kmgtpezy")[0] = '\0'; | ||
| 403 | else | ||
| 404 | smart_ulltoa5(value, buf45, " kmgtpezy")[0] = '\0'; | ||
| 405 | chars_printed = printf("%*s", width, skip_whitespace(buf45)); | ||
| 406 | } else { | ||
| 407 | chars_printed = printf("%*u", width, value); | ||
| 408 | } | ||
| 409 | overrun += (chars_printed - col.width); | ||
| 394 | } | 410 | } |
| 395 | } | 411 | } |
| 396 | 412 | ||
