+ if (ts->nr_block_infos) {
+ /* Block error histogram and types */
+ int len;
+ unsigned int *percentiles = NULL;
+ unsigned int block_state_counts[BLOCK_STATE_COUNT];
+
+ len = calc_block_percentiles(ts->nr_block_infos, ts->block_infos,
+ ts->percentile_list,
+ &percentiles, block_state_counts);
+
+ if (len) {
+ struct json_object *block, *percentile_object, *states;
+ int state;
+ block = json_create_object();
+ json_object_add_value_object(root, "block", block);
+
+ percentile_object = json_create_object();
+ json_object_add_value_object(block, "percentiles",
+ percentile_object);
+ for (i = 0; i < len; i++) {
+ char buf[20];
+ snprintf(buf, sizeof(buf), "%f",
+ ts->percentile_list[i].u.f);
+ json_object_add_value_int(percentile_object,
+ (const char *)buf,
+ percentiles[i]);
+ }
+
+ states = json_create_object();
+ json_object_add_value_object(block, "states", states);
+ for (state = 0; state < BLOCK_STATE_COUNT; state++) {
+ json_object_add_value_int(states,
+ block_state_names[state],
+ block_state_counts[state]);
+ }
+ free(percentiles);
+ }
+ }
+
+ if (ts->ss_dur) {
+ struct json_object *data;
+ struct json_array *iops, *bw;
+ int i, j, k;
+ char ss_buf[64];
+
+ snprintf(ss_buf, sizeof(ss_buf), "%s%s:%f%s",
+ ts->ss_state & FIO_SS_IOPS ? "iops" : "bw",
+ ts->ss_state & FIO_SS_SLOPE ? "_slope" : "",
+ (float) ts->ss_limit.u.f,
+ ts->ss_state & FIO_SS_PCT ? "%" : "");
+
+ tmp = json_create_object();
+ json_object_add_value_object(root, "steadystate", tmp);
+ json_object_add_value_string(tmp, "ss", ss_buf);
+ json_object_add_value_int(tmp, "duration", (int)ts->ss_dur);
+ json_object_add_value_int(tmp, "attained", (ts->ss_state & FIO_SS_ATTAINED) > 0);
+
+ snprintf(ss_buf, sizeof(ss_buf), "%f%s", (float) ts->ss_criterion.u.f,
+ ts->ss_state & FIO_SS_PCT ? "%" : "");
+ json_object_add_value_string(tmp, "criterion", ss_buf);
+ json_object_add_value_float(tmp, "max_deviation", ts->ss_deviation.u.f);
+ json_object_add_value_float(tmp, "slope", ts->ss_slope.u.f);
+
+ data = json_create_object();
+ json_object_add_value_object(tmp, "data", data);
+ bw = json_create_array();
+ iops = json_create_array();
+
+ /*
+ ** if ss was attained or the buffer is not full,
+ ** ss->head points to the first element in the list.
+ ** otherwise it actually points to the second element
+ ** in the list
+ */
+ if ((ts->ss_state & FIO_SS_ATTAINED) || !(ts->ss_state & FIO_SS_BUFFER_FULL))
+ j = ts->ss_head;
+ else
+ j = ts->ss_head == 0 ? ts->ss_dur - 1 : ts->ss_head - 1;
+ for (i = 0; i < ts->ss_dur; i++) {
+ k = (j + i) % ts->ss_dur;
+ json_array_add_value_int(bw, ts->ss_bw_data[k]);
+ json_array_add_value_int(iops, ts->ss_iops_data[k]);
+ }
+ json_object_add_value_int(data, "bw_mean", steadystate_bw_mean(ts));
+ json_object_add_value_int(data, "iops_mean", steadystate_iops_mean(ts));
+ json_object_add_value_array(data, "iops", iops);
+ json_object_add_value_array(data, "bw", bw);
+ }
+