From: Jens Axboe Date: Sat, 6 Jan 2018 21:47:01 +0000 (-0700) Subject: stat: don't add duplicate clat entries for json X-Git-Tag: fio-3.4~26 X-Git-Url: https://git.kernel.dk/?p=fio.git;a=commitdiff_plain;h=702bd977555105292f3d60dee896cd35ff8b11ef;ds=sidebyside stat: don't add duplicate clat entries for json For some reason the initial commit always filled all entries with zeroes, when it should just stop printing. I suspect this was carried over from the terse/csv output, where we do the same. But there it's actually valid, as we have to have a fixed number of fields. For json we both don't need it, and it's causing us to create invalid json when we have duplicate keys. Fixes: https://github.com/axboe/fio/issues/511 Signed-off-by: Jens Axboe --- diff --git a/stat.c b/stat.c index 509bd6d8..80f804a1 100644 --- a/stat.c +++ b/stat.c @@ -1030,16 +1030,14 @@ static void add_ddir_status_json(struct thread_stat *ts, ts->clat_stat[ddir].samples, ts->percentile_list, &ovals, &maxv, &minv); + if (len > FIO_IO_U_LIST_MAX_LEN) + len = FIO_IO_U_LIST_MAX_LEN; } else len = 0; percentile_object = json_create_object(); json_object_add_value_object(tmp_object, "percentile", percentile_object); - for (i = 0; i < FIO_IO_U_LIST_MAX_LEN; i++) { - if (i >= len) { - json_object_add_value_int(percentile_object, "0.00", 0); - continue; - } + for (i = 0; i < len; i++) { snprintf(buf, sizeof(buf), "%f", ts->percentile_list[i].u.f); json_object_add_value_int(percentile_object, (const char *)buf, ovals[i]); }