From: Darrick J. Wong Date: Mon, 29 Jul 2024 23:23:13 +0000 (-0700) Subject: libfrog: print wider columns for free space histogram X-Git-Tag: v6.10.0~13^2~5 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=993f187f191be6c139e2d453034a05290967945d;p=thirdparty%2Fxfsprogs-dev.git libfrog: print wider columns for free space histogram The values reported here can reach very large values, so compute the column width dynamically. Signed-off-by: Darrick J. Wong Reviewed-by: Christoph Hellwig --- diff --git a/libfrog/histogram.c b/libfrog/histogram.c index c2f344a8..7cee6b35 100644 --- a/libfrog/histogram.c +++ b/libfrog/histogram.c @@ -110,10 +110,30 @@ hist_print( { unsigned int obs_w = strlen(hstr->observations); unsigned int sum_w = strlen(hstr->sum); + unsigned int from_w = 7, to_w = 7; unsigned int i; - printf("%7s %7s %*s %*s %6s\n", - _("from"), _("to"), + for (i = 0; i < hs->nr_buckets; i++) { + char buf[256]; + + if (hs->buckets[i].nr_obs == 0) + continue; + + snprintf(buf, sizeof(buf) - 1, "%lld", hs->buckets[i].low); + from_w = max(from_w, strlen(buf)); + + snprintf(buf, sizeof(buf) - 1, "%lld", hs->buckets[i].high); + to_w = max(to_w, strlen(buf)); + + snprintf(buf, sizeof(buf) - 1, "%lld", hs->buckets[i].nr_obs); + obs_w = max(obs_w, strlen(buf)); + + snprintf(buf, sizeof(buf) - 1, "%lld", hs->buckets[i].sum); + sum_w = max(sum_w, strlen(buf)); + } + + printf("%*s %*s %*s %*s %6s\n", + from_w, _("from"), to_w, _("to"), obs_w, hstr->observations, sum_w, hstr->sum, _("pct")); @@ -122,8 +142,9 @@ hist_print( if (hs->buckets[i].nr_obs == 0) continue; - printf("%7lld %7lld %*lld %*lld %6.2f\n", - hs->buckets[i].low, hs->buckets[i].high, + printf("%*lld %*lld %*lld %*lld %6.2f\n", + from_w, hs->buckets[i].low, + to_w, hs->buckets[i].high, obs_w, hs->buckets[i].nr_obs, sum_w, hs->buckets[i].sum, hs->buckets[i].sum * 100.0 / hs->tot_sum);