aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlexander Motin <mav@FreeBSD.org>2023-12-06 19:55:58 +0000
committerAlexander Motin <mav@FreeBSD.org>2023-12-06 20:00:19 +0000
commit6f048e71304310db80a210d07cb3768de18589c8 (patch)
tree725a453c8791cb0f084489e0cf8e2fe401364e1f
parentd2ce3d89e93cab3942b771ccd64e7c83532c090a (diff)
downloadsrc-6f048e71304310db80a210d07cb3768de18589c8.tar.gz
src-6f048e71304310db80a210d07cb3768de18589c8.zip
vmstat: Improve -z formatting for large names/values
MFC after: 2 weeks
-rw-r--r--usr.bin/vmstat/vmstat.c21
1 files changed, 10 insertions, 11 deletions
diff --git a/usr.bin/vmstat/vmstat.c b/usr.bin/vmstat/vmstat.c
index 6476df06fe39..6d5f000f46a3 100644
--- a/usr.bin/vmstat/vmstat.c
+++ b/usr.bin/vmstat/vmstat.c
@@ -1455,8 +1455,7 @@ domemstat_zone(void)
{
struct memory_type_list *mtlp;
struct memory_type *mtp;
- int error;
- char name[MEMTYPE_MAXNAME + 1];
+ int error, len;
mtlp = memstat_mtl_alloc();
if (mtlp == NULL) {
@@ -1481,20 +1480,20 @@ domemstat_zone(void)
}
}
xo_open_container("memory-zone-statistics");
- xo_emit("{T:/%-20s} {T:/%6s} {T:/%6s} {T:/%8s} {T:/%8s} {T:/%8s} {T:/%8s} "
- "{T:/%4s} {T:/%4s}\n", "ITEM", "SIZE",
- "LIMIT", "USED", "FREE", "REQ", "FAIL", "SLEEP", "XDOMAIN");
+ xo_emit("{T:/%-19s} {T:/%7s} {T:/%7s} {T:/%8s} {T:/%8s} {T:/%8s} "
+ "{T:/%4s} {T:/%4s} {T:/%4s}\n", "ITEM", "SIZE",
+ "LIMIT", "USED", "FREE", "REQ", "FAIL", "SLEEP", "XDOM");
xo_open_list("zone");
for (mtp = memstat_mtl_first(mtlp); mtp != NULL;
mtp = memstat_mtl_next(mtp)) {
- strlcpy(name, memstat_get_name(mtp), MEMTYPE_MAXNAME);
- strcat(name, ":");
+ len = strlen(memstat_get_name(mtp));
xo_open_instance("zone");
- xo_emit("{d:name/%-20s}{ke:name/%s} {:size/%6ju}, "
- "{:limit/%6ju},{:used/%8ju},"
+ xo_emit("{k:name/%s}:{d:size/%*ju}{e:size/%ju},"
+ "{:limit/%7ju},{:used/%8ju},"
"{:free/%8ju},{:requests/%8ju},"
- "{:fail/%4ju},{:sleep/%4ju},{:xdomain/%4ju}\n", name,
- memstat_get_name(mtp),
+ "{:fail/%4ju},{:sleep/%4ju},{:xdomain/%4ju}\n",
+ memstat_get_name(mtp), MAX(1, 26 - len),
+ (uintmax_t)memstat_get_size(mtp),
(uintmax_t)memstat_get_size(mtp),
(uintmax_t)memstat_get_countlimit(mtp),
(uintmax_t)memstat_get_count(mtp),