chpstat: Adapt to new JSON Lines text format

util_fmt now provides support for JSON Lines text format. Adapt certain
checks in the code and document the newly supported format in the man
page accordingly.

Reviewed-by: Peter Oberparleiter <oberpar@linux.ibm.com>
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
This commit is contained in:
Jan Höppner
2026-04-01 18:27:37 +02:00
parent 88bf638487
commit 6e53be736e
2 changed files with 20 additions and 3 deletions
+17
View File
@@ -384,6 +384,17 @@ with an ASCII Record Separator character (0x1e) and suffixed with an ASCII Line
Feed character (0x0a) in accordance with RFC7464.
.br
See section "OUTPUT FORMAT" for more details.
.BR
.PP
.IP \(bu 3
.B jsonl:
Line-delimited JSON data structures
Data for each iteration is formatted as a single JSON data structure separated
by an ASCII Line Feed character (0x0a, LF).
.BR
See section "OUTPUT FORMAT" for more details.
.br
.PP
@@ -736,6 +747,12 @@ Subsequent objects each represent channel-path statistics data for one iteration
.br
.PP
.SS jsonl
The jsonl output format is a data streaming variation of the JSON output format
described above with the same properties as the json\-seq output with the
difference that JSON data is separated only by an ASCII Line Feed character
(0x0a, LF).
.SH "EXIT CODES"
.TP
+3 -3
View File
@@ -1270,7 +1270,7 @@ static void cmd_list(void)
if (opts.groups & KEY_GRP_METRICS)
update_util_all(true);
if (opts.fmt != FMT_JSONSEQ)
if (!util_fmt_is_json_stream(opts.fmt))
util_fmt_obj_start(FMT_LIST, NULL);
for (i = 0; opts.forever || i < opts.iterations; i++) {
if (i > 0)
@@ -1286,7 +1286,7 @@ static void cmd_list(void)
* via pipes (e.g. for use with grep). */
fflush(stdout);
}
if (opts.fmt != FMT_JSONSEQ)
if (!util_fmt_is_json_stream(opts.fmt))
util_fmt_obj_end();
}
@@ -1972,7 +1972,7 @@ static void init_fmt(void)
flags |= FMT_FILTER;
if (!opts.use_prefix)
flags |= FMT_NOPREFIX;
if (opts.fmt == FMT_JSON || opts.fmt == FMT_JSONSEQ) {
if (util_fmt_is_json(opts.fmt)) {
/* Ensure correct JSON even if interrupted. */
flags |= FMT_HANDLEINT;
}