mirror of
https://github.com/ibm-s390-linux/s390-tools.git
synced 2026-08-05 02:14:52 +00:00
hyptop: Keep track of string-typed columns
For structured output (i.e. JSON), some type information of the columns is required, at least the ability to distinguish values that are strings and possibly need to be quoted. Unfortunately at the time column values are formatted this information is lost. The column types are specified implicitly during the unit conversion of the raw value. For example, online time is stored as a u64 value but is converted into a "d:h:m" string. Introduce a private flag per column that signifies if that column is to be formatted as a string. This flag will be set in the appropriate unit conversion function. Reviewed-by: Mete Durlu <meted@linux.ibm.com> Signed-off-by: Bjoern Walk <bwalk@linux.ibm.com> Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
This commit is contained in:
@@ -106,6 +106,7 @@ struct table_col_priv {
|
||||
char head_char[2];
|
||||
char head_last[TABLE_HEADING_SIZE];
|
||||
int rsort;
|
||||
int needs_quotes;
|
||||
};
|
||||
|
||||
/*
|
||||
@@ -135,6 +136,11 @@ static inline int table_col_enabled(struct table_col *col)
|
||||
return col->p->enabled;
|
||||
}
|
||||
|
||||
static inline int table_col_needs_quotes(struct table_col *col)
|
||||
{
|
||||
return col->p->needs_quotes;
|
||||
}
|
||||
|
||||
/*
|
||||
* Table Column Constructor Macros
|
||||
*/
|
||||
|
||||
@@ -63,7 +63,7 @@ static int l_unit_raw(struct table_col *col, struct table_entry *e)
|
||||
*/
|
||||
static int l_str(struct table_col *col, struct table_entry *e)
|
||||
{
|
||||
(void) col;
|
||||
col->p->needs_quotes = 1;
|
||||
return strlen(e->str);
|
||||
}
|
||||
|
||||
@@ -226,6 +226,8 @@ static int l_unit_hm_u64(char *str, u64 v1, int negative)
|
||||
|
||||
static int l_unit_hm(struct table_col *col, struct table_entry *e)
|
||||
{
|
||||
col->p->needs_quotes = 1;
|
||||
|
||||
if (!e->set)
|
||||
return snprintf(e->str, sizeof(e->str), L_COL_NOT_SET_STR);
|
||||
|
||||
@@ -272,6 +274,8 @@ static int l_unit_dhm_u64(char *str, u64 v1, int negative)
|
||||
|
||||
static int l_unit_dhm(struct table_col *col, struct table_entry *e)
|
||||
{
|
||||
col->p->needs_quotes = 1;
|
||||
|
||||
if (!e->set)
|
||||
return snprintf(e->str, sizeof(e->str), L_COL_NOT_SET_STR);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user