From cb1c002bed03eed479d01446f79fe8265333f223 Mon Sep 17 00:00:00 2001 From: Peter Oberparleiter Date: Wed, 13 Aug 2025 17:02:55 +0200 Subject: [PATCH] chpstat: Ensure consistent table group spacing In tabular output, chpstat adds an additional space between columns of different groups (e.g. between READ and WRITE data). Currently this is done by increasing the column width of the first column in a group. Depending on the value displayed in this first column of a group, the spacing may vanish, and under certain circumstances, the precision of auto-scaled *_PART columns may be higher than the precision of the related *_TOTAL columns, resulting in a confusing view. Example: DPU READ(B/s) WRITE(B/s) ID PART TOTAL PART TOTAL 6 10.7M 10.7M 10.8M 10.8M 6 0.00 11.3K 0.00 0.00 ^^ ^^ Fix this by consistently adding padding between column groups without increasing the column width of the first column of a group. Also ensure the same width for *_PART and *_TOTAL columns. Reviewed-by: Jimmy Brisson Reviewed-by: Vineeth Vijayan Signed-off-by: Peter Oberparleiter Signed-off-by: Steffen Eiden --- zconf/chp/chpstat/chpstat.c | 14 +++++++++----- zconf/chp/chpstat/column.c | 31 +++++++++++++++++++++++++++++++ zconf/chp/chpstat/column.h | 1 + 3 files changed, 41 insertions(+), 5 deletions(-) diff --git a/zconf/chp/chpstat/chpstat.c b/zconf/chp/chpstat/chpstat.c index 09d1e94c..e822d858 100644 --- a/zconf/chp/chpstat/chpstat.c +++ b/zconf/chp/chpstat/chpstat.c @@ -1278,7 +1278,7 @@ static struct util_rec *define_table(void) rec = util_rec_new_wide(NULL); column_for_each_selected(col) { util_rec_def(rec, col->name, UTIL_REC_ALIGN_RIGHT, - (int)col->width, ""); + (int)col->width + (int)col->pad, ""); } return rec; @@ -1539,11 +1539,15 @@ static void print_table_header(void) { struct column_t *col; unsigned int i, next_i, num, width, hdr_width; + const char *last_hdr1 = NULL; /* Print first header line and update column width based on heading. */ for (i = 0; (col = column_get_by_index(i, true)); i = next_i) { - if (i > 0) - printf(" "); + if (last_hdr1 && strcmp(last_hdr1, col->hdr1_group) != 0) { + col->pad = 1; + printf("%*s", col->pad + 1, ""); + } + last_hdr1 = col->hdr1_group; get_hdr_group_size(i, &num, &width); if (num == 1) { /* Update column width in case heading is wider. */ @@ -1571,7 +1575,7 @@ static void print_table_header(void) i = 0; column_for_each_selected(col) { if (i++ > 0) - printf(" "); + printf("%*s", col->pad + 1, ""); printf("%*s", col->width, col->hdr2); } printf("\n"); @@ -1678,7 +1682,7 @@ static void calc_column_widths(void) col->width = MAX(col->width, width); /* Double space between groups. */ if (last_hdr1 && strcmp(last_hdr1, col->hdr1_group) != 0) - col->width++; + col->pad++; last_hdr1 = col->hdr1_group; } } diff --git a/zconf/chp/chpstat/column.c b/zconf/chp/chpstat/column.c index b333ebfe..0dc4e80a 100644 --- a/zconf/chp/chpstat/column.c +++ b/zconf/chp/chpstat/column.c @@ -53,6 +53,7 @@ static struct column_t columns[] = { HDR1_CHP_SINGLE, HDR1_CHP_GROUP, 0, + 0, }, { COL_TYPE, @@ -63,6 +64,7 @@ static struct column_t columns[] = { HDR1_CHP_SINGLE, HDR1_CHP_GROUP, 0, + 0, }, { COL_CMG, @@ -73,6 +75,7 @@ static struct column_t columns[] = { HDR1_CHP_SINGLE, HDR1_CHP_GROUP, 0, + 0, }, { COL_SPEED, @@ -83,6 +86,7 @@ static struct column_t columns[] = { HDR1_CHP_SINGLE, HDR1_CHP_GROUP, 0, + 0, }, { COL_SHARED, @@ -93,6 +97,7 @@ static struct column_t columns[] = { HDR1_CHP_SINGLE, HDR1_CHP_GROUP, 0, + 0, }, { COL_INTERVAL, @@ -103,6 +108,7 @@ static struct column_t columns[] = { HDR1_CHP_SINGLE, HDR1_CHP_GROUP, 0, + 0, }, { COL_UTIL_PART, @@ -112,6 +118,7 @@ static struct column_t columns[] = { "PART", HDR1_UTIL_SINGLE, HDR1_UTIL_GROUP, + 5, 0, }, { @@ -122,6 +129,7 @@ static struct column_t columns[] = { "TOTAL", HDR1_UTIL_SINGLE, HDR1_UTIL_GROUP, + 5, 0, }, { @@ -133,6 +141,7 @@ static struct column_t columns[] = { HDR1_UTIL_SINGLE, HDR1_UTIL_GROUP, 0, + 0, }, { COL_UTIL_DATA, @@ -143,6 +152,7 @@ static struct column_t columns[] = { HDR1_UTIL_SINGLE, HDR1_UTIL_GROUP, 0, + 0, }, { COL_READ_PART, @@ -152,6 +162,7 @@ static struct column_t columns[] = { "PART", HDR1_READ_SINGLE, HDR1_READ_GROUP, + 5, 0, }, { @@ -162,6 +173,7 @@ static struct column_t columns[] = { "TOTAL", HDR1_READ_SINGLE, HDR1_READ_GROUP, + 5, 0, }, { @@ -172,6 +184,7 @@ static struct column_t columns[] = { "PART", HDR1_WRITE_SINGLE, HDR1_WRITE_GROUP, + 5, 0, }, { @@ -182,6 +195,7 @@ static struct column_t columns[] = { "TOTAL", HDR1_WRITE_SINGLE, HDR1_WRITE_GROUP, + 5, 0, }, { @@ -193,6 +207,7 @@ static struct column_t columns[] = { HDR1_FICON_SINGLE, HDR1_FICON_GROUP, 0, + 0, }, { COL_FICON_ACTIVE, @@ -203,6 +218,7 @@ static struct column_t columns[] = { HDR1_FICON_SINGLE, HDR1_FICON_GROUP, 0, + 0, }, { COL_FICON_DEFER, @@ -213,6 +229,7 @@ static struct column_t columns[] = { HDR1_FICON_SINGLE, HDR1_FICON_GROUP, 0, + 0, }, { COL_HPF_RATE, @@ -223,6 +240,7 @@ static struct column_t columns[] = { HDR1_HPF_SINGLE, HDR1_HPF_GROUP, 0, + 0, }, { COL_HPF_ACTIVE, @@ -233,6 +251,7 @@ static struct column_t columns[] = { HDR1_HPF_SINGLE, HDR1_HPF_GROUP, 0, + 0, }, { COL_HPF_DEFER, @@ -243,6 +262,7 @@ static struct column_t columns[] = { HDR1_HPF_SINGLE, HDR1_HPF_GROUP, 0, + 0, }, { COL_MSG_RATE_PART, @@ -252,6 +272,7 @@ static struct column_t columns[] = { "PART", HDR1_MSGR_SINGLE, HDR1_MSGR_GROUP, + 5, 0, }, { @@ -262,6 +283,7 @@ static struct column_t columns[] = { "TOTAL", HDR1_MSGR_SINGLE, HDR1_MSGR_GROUP, + 5, 0, }, { @@ -272,6 +294,7 @@ static struct column_t columns[] = { "PART", HDR1_MSGSZ_SINGLE, HDR1_MSGSZ_GROUP, + 5, 0, }, { @@ -282,6 +305,7 @@ static struct column_t columns[] = { "TOTAL", HDR1_MSGSZ_SINGLE, HDR1_MSGSZ_GROUP, + 5, 0, }, { @@ -293,6 +317,7 @@ static struct column_t columns[] = { "SNDFAIL", "SNDFAIL", 0, + 0, }, { COL_RCV_FAIL_PART, @@ -302,6 +327,7 @@ static struct column_t columns[] = { "PART", HDR1_MSG_RCVF_SINGLE, HDR1_MSG_RCVF_GROUP, + 5, 0, }, { @@ -312,6 +338,7 @@ static struct column_t columns[] = { "TOTAL", HDR1_MSG_RCVF_SINGLE, HDR1_MSG_RCVF_GROUP, + 5, 0, }, { @@ -323,6 +350,7 @@ static struct column_t columns[] = { HDR1_DPU_UTIL_SINGLE, HDR1_DPU_UTIL_GROUP, 0, + 0, }, { COL_DPU_UTIL, @@ -333,6 +361,7 @@ static struct column_t columns[] = { HDR1_DPU_UTIL_SINGLE, HDR1_DPU_UTIL_GROUP, 0, + 0, }, { COL_DPU_UTIL_PART, @@ -342,6 +371,7 @@ static struct column_t columns[] = { "PART", HDR1_DPU_UTIL_SINGLE, HDR1_DPU_UTIL_GROUP, + 5, 0, }, { @@ -352,6 +382,7 @@ static struct column_t columns[] = { "TOTAL", HDR1_DPU_UTIL_SINGLE, HDR1_DPU_UTIL_GROUP, + 5, 0, }, }; diff --git a/zconf/chp/chpstat/column.h b/zconf/chp/chpstat/column.h index 969cf620..44f8e406 100644 --- a/zconf/chp/chpstat/column.h +++ b/zconf/chp/chpstat/column.h @@ -66,6 +66,7 @@ struct column_t { const char *hdr1_single; char *hdr1_group; unsigned int width; + unsigned int pad; }; #define column_for_each(c) \