stat: don't add duplicate clat entries for json
authorJens Axboe <axboe@kernel.dk>
Sat, 6 Jan 2018 21:47:01 +0000 (14:47 -0700)
committerJens Axboe <axboe@kernel.dk>
Sat, 6 Jan 2018 21:47:01 +0000 (14:47 -0700)
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 <axboe@kernel.dk>
stat.c

diff --git a/stat.c b/stat.c
index 509bd6d8ed3d2ed0273ed17a9f25cc72e242ed03..80f804a19e0bd52ab2e790e07b8041938a50fa22 100644 (file)
--- 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]);
        }