stat: update json+ output format for --lat_percentiles option
authorVincent Fu <vincent.fu@wdc.com>
Mon, 9 Oct 2017 14:47:12 +0000 (10:47 -0400)
committerJens Axboe <axboe@kernel.dk>
Mon, 9 Oct 2017 15:09:55 +0000 (09:09 -0600)
If --lat_percentiles is set to 1, change the json+ output format
so that the bins are inside the 'lat_ns' object.

Also update fio_jsonplus_clat2csv to look in the two possible
locations.

Signed-off-by: Jens Axboe <axboe@kernel.dk>
stat.c
tools/fio_jsonplus_clat2csv

diff --git a/stat.c b/stat.c
index 09afa5bdd8f5bb0fb3c771d01bae2fa1f491dc1e..c5a68ad5c489cb0baf083220edbd63c4d2bcf591 100644 (file)
--- a/stat.c
+++ b/stat.c
@@ -962,7 +962,7 @@ static void add_ddir_status_json(struct thread_stat *ts,
        unsigned int len;
        int i;
        const char *ddirname[] = {"read", "write", "trim"};
-       struct json_object *dir_object, *tmp_object, *percentile_object, *clat_bins_object;
+       struct json_object *dir_object, *tmp_object, *percentile_object, *clat_bins_object = NULL;
        char buf[120];
        double p_of_agg = 100.0;
 
@@ -1036,7 +1036,9 @@ static void add_ddir_status_json(struct thread_stat *ts,
 
        if (output_format & FIO_OUTPUT_JSON_PLUS) {
                clat_bins_object = json_create_object();
-               json_object_add_value_object(tmp_object, "bins", clat_bins_object);
+               if (ts->clat_percentiles)
+                       json_object_add_value_object(tmp_object, "bins", clat_bins_object);
+
                for(i = 0; i < FIO_IO_U_PLAT_NR; i++) {
                        if (ts->io_u_plat[ddir][i]) {
                                snprintf(buf, sizeof(buf), "%llu", plat_idx_to_val(i));
@@ -1055,6 +1057,9 @@ static void add_ddir_status_json(struct thread_stat *ts,
        json_object_add_value_int(tmp_object, "max", max);
        json_object_add_value_float(tmp_object, "mean", mean);
        json_object_add_value_float(tmp_object, "stddev", dev);
+       if (output_format & FIO_OUTPUT_JSON_PLUS && ts->lat_percentiles)
+               json_object_add_value_object(tmp_object, "bins", clat_bins_object);
+
        if (ovals)
                free(ovals);
 
index d4ac16e422f6a6df3f61c3af3ebcb9d8a4edc8fe..64fdc9f3a00b187605c5c02db12391c4bf1d5291 100755 (executable)
@@ -107,8 +107,16 @@ def main():
 
         prev_ddir = None
         for ddir in ddir_set:
+            if 'bins' in jsondata['jobs'][jobnum][ddir]['clat_ns']:
+                bins_loc = 'clat_ns'
+            elif 'bins' in jsondata['jobs'][jobnum][ddir]['lat_ns']:
+                bins_loc = 'lat_ns'
+            else:
+                raise RuntimeError("Latency bins not found. "
+                                   "Are you sure you are using json+ output?")
+
             bins[ddir] = [[int(key), value] for key, value in
-                          jsondata['jobs'][jobnum][ddir]['clat_ns']
+                          jsondata['jobs'][jobnum][ddir][bins_loc]
                           ['bins'].iteritems()]
             bins[ddir] = sorted(bins[ddir], key=lambda bin: bin[0])
 
@@ -123,7 +131,7 @@ def main():
         outfile = stub + '_job' + str(jobnum) + ext
 
         with open(outfile, 'w') as output:
-            output.write("clat_nsec, ")
+            output.write("{0}ec, ".format(bins_loc))
             ddir_list = list(ddir_set)
             for ddir in ddir_list:
                 output.write("{0}_count, {0}_cumulative, {0}_percentile, ".