+static void show_ss_normal(struct thread_stat *ts, struct buf_output *out)
+{
+ char *p1, *p1alt, *p2;
+ unsigned long long bw_mean, iops_mean;
+ const int i2p = is_power_of_2(ts->kb_base);
+
+ if (!ts->ss_dur)
+ return;
+
+ bw_mean = steadystate_bw_mean(ts);
+ iops_mean = steadystate_iops_mean(ts);
+
+ p1 = num2str(bw_mean / ts->kb_base, ts->sig_figs, ts->kb_base, i2p, ts->unit_base);
+ p1alt = num2str(bw_mean / ts->kb_base, ts->sig_figs, ts->kb_base, !i2p, ts->unit_base);
+ p2 = num2str(iops_mean, ts->sig_figs, 1, 0, N2S_NONE);
+
+ log_buf(out, " steadystate : attained=%s, bw=%s (%s), iops=%s, %s%s=%.3f%s\n",
+ ts->ss_state & FIO_SS_ATTAINED ? "yes" : "no",
+ p1, p1alt, p2,
+ ts->ss_state & FIO_SS_IOPS ? "iops" : "bw",
+ ts->ss_state & FIO_SS_SLOPE ? " slope": " mean dev",
+ ts->ss_criterion.u.f,
+ ts->ss_state & FIO_SS_PCT ? "%" : "");
+
+ free(p1);
+ free(p1alt);
+ free(p2);
+}
+
+static void show_agg_stats(struct disk_util_agg *agg, int terse,
+ struct buf_output *out)
+{
+ if (!agg->slavecount)
+ return;
+
+ if (!terse) {
+ log_buf(out, ", aggrios=%llu/%llu, aggrmerge=%llu/%llu, "
+ "aggrticks=%llu/%llu, aggrin_queue=%llu, "
+ "aggrutil=%3.2f%%",
+ (unsigned long long) agg->ios[0] / agg->slavecount,
+ (unsigned long long) agg->ios[1] / agg->slavecount,
+ (unsigned long long) agg->merges[0] / agg->slavecount,
+ (unsigned long long) agg->merges[1] / agg->slavecount,
+ (unsigned long long) agg->ticks[0] / agg->slavecount,
+ (unsigned long long) agg->ticks[1] / agg->slavecount,
+ (unsigned long long) agg->time_in_queue / agg->slavecount,
+ agg->max_util.u.f);
+ } else {
+ log_buf(out, ";slaves;%llu;%llu;%llu;%llu;%llu;%llu;%llu;%3.2f%%",
+ (unsigned long long) agg->ios[0] / agg->slavecount,
+ (unsigned long long) agg->ios[1] / agg->slavecount,
+ (unsigned long long) agg->merges[0] / agg->slavecount,
+ (unsigned long long) agg->merges[1] / agg->slavecount,
+ (unsigned long long) agg->ticks[0] / agg->slavecount,
+ (unsigned long long) agg->ticks[1] / agg->slavecount,
+ (unsigned long long) agg->time_in_queue / agg->slavecount,
+ agg->max_util.u.f);
+ }
+}
+
+static void aggregate_slaves_stats(struct disk_util *masterdu)
+{
+ struct disk_util_agg *agg = &masterdu->agg;
+ struct disk_util_stat *dus;
+ struct flist_head *entry;
+ struct disk_util *slavedu;
+ double util;
+
+ flist_for_each(entry, &masterdu->slaves) {
+ slavedu = flist_entry(entry, struct disk_util, slavelist);
+ dus = &slavedu->dus;
+ agg->ios[0] += dus->s.ios[0];
+ agg->ios[1] += dus->s.ios[1];
+ agg->merges[0] += dus->s.merges[0];
+ agg->merges[1] += dus->s.merges[1];
+ agg->sectors[0] += dus->s.sectors[0];
+ agg->sectors[1] += dus->s.sectors[1];
+ agg->ticks[0] += dus->s.ticks[0];
+ agg->ticks[1] += dus->s.ticks[1];
+ agg->time_in_queue += dus->s.time_in_queue;
+ agg->slavecount++;
+
+ util = (double) (100 * dus->s.io_ticks / (double) slavedu->dus.s.msec);
+ /* System utilization is the utilization of the
+ * component with the highest utilization.
+ */
+ if (util > agg->max_util.u.f)
+ agg->max_util.u.f = util;
+
+ }
+
+ if (agg->max_util.u.f > 100.0)
+ agg->max_util.u.f = 100.0;
+}
+
+void print_disk_util(struct disk_util_stat *dus, struct disk_util_agg *agg,
+ int terse, struct buf_output *out)
+{
+ double util = 0;
+
+ if (dus->s.msec)
+ util = (double) 100 * dus->s.io_ticks / (double) dus->s.msec;
+ if (util > 100.0)
+ util = 100.0;
+
+ if (!terse) {
+ if (agg->slavecount)
+ log_buf(out, " ");
+
+ log_buf(out, " %s: ios=%llu/%llu, merge=%llu/%llu, "
+ "ticks=%llu/%llu, in_queue=%llu, util=%3.2f%%",
+ dus->name,
+ (unsigned long long) dus->s.ios[0],
+ (unsigned long long) dus->s.ios[1],
+ (unsigned long long) dus->s.merges[0],
+ (unsigned long long) dus->s.merges[1],
+ (unsigned long long) dus->s.ticks[0],
+ (unsigned long long) dus->s.ticks[1],
+ (unsigned long long) dus->s.time_in_queue,
+ util);
+ } else {
+ log_buf(out, ";%s;%llu;%llu;%llu;%llu;%llu;%llu;%llu;%3.2f%%",
+ dus->name,
+ (unsigned long long) dus->s.ios[0],
+ (unsigned long long) dus->s.ios[1],
+ (unsigned long long) dus->s.merges[0],
+ (unsigned long long) dus->s.merges[1],
+ (unsigned long long) dus->s.ticks[0],
+ (unsigned long long) dus->s.ticks[1],
+ (unsigned long long) dus->s.time_in_queue,
+ util);
+ }
+
+ /*
+ * If the device has slaves, aggregate the stats for
+ * those slave devices also.
+ */
+ show_agg_stats(agg, terse, out);
+
+ if (!terse)
+ log_buf(out, "\n");
+}
+
+void json_array_add_disk_util(struct disk_util_stat *dus,
+ struct disk_util_agg *agg, struct json_array *array)
+{
+ struct json_object *obj;
+ double util = 0;
+
+ if (dus->s.msec)
+ util = (double) 100 * dus->s.io_ticks / (double) dus->s.msec;
+ if (util > 100.0)
+ util = 100.0;
+
+ obj = json_create_object();
+ json_array_add_value_object(array, obj);
+
+ json_object_add_value_string(obj, "name", (const char *)dus->name);
+ json_object_add_value_int(obj, "read_ios", dus->s.ios[0]);
+ json_object_add_value_int(obj, "write_ios", dus->s.ios[1]);
+ json_object_add_value_int(obj, "read_merges", dus->s.merges[0]);
+ json_object_add_value_int(obj, "write_merges", dus->s.merges[1]);
+ json_object_add_value_int(obj, "read_ticks", dus->s.ticks[0]);
+ json_object_add_value_int(obj, "write_ticks", dus->s.ticks[1]);
+ json_object_add_value_int(obj, "in_queue", dus->s.time_in_queue);
+ json_object_add_value_float(obj, "util", util);
+
+ /*
+ * If the device has slaves, aggregate the stats for
+ * those slave devices also.
+ */
+ if (!agg->slavecount)
+ return;
+ json_object_add_value_int(obj, "aggr_read_ios",
+ agg->ios[0] / agg->slavecount);
+ json_object_add_value_int(obj, "aggr_write_ios",
+ agg->ios[1] / agg->slavecount);
+ json_object_add_value_int(obj, "aggr_read_merges",
+ agg->merges[0] / agg->slavecount);
+ json_object_add_value_int(obj, "aggr_write_merge",
+ agg->merges[1] / agg->slavecount);
+ json_object_add_value_int(obj, "aggr_read_ticks",
+ agg->ticks[0] / agg->slavecount);
+ json_object_add_value_int(obj, "aggr_write_ticks",
+ agg->ticks[1] / agg->slavecount);
+ json_object_add_value_int(obj, "aggr_in_queue",
+ agg->time_in_queue / agg->slavecount);
+ json_object_add_value_float(obj, "aggr_util", agg->max_util.u.f);
+}
+
+static void json_object_add_disk_utils(struct json_object *obj,
+ struct flist_head *head)
+{
+ struct json_array *array = json_create_array();
+ struct flist_head *entry;
+ struct disk_util *du;
+
+ json_object_add_value_array(obj, "disk_util", array);
+
+ flist_for_each(entry, head) {
+ du = flist_entry(entry, struct disk_util, list);
+
+ aggregate_slaves_stats(du);
+ json_array_add_disk_util(&du->dus, &du->agg, array);
+ }
+}
+
+void show_disk_util(int terse, struct json_object *parent,
+ struct buf_output *out)
+{
+ struct flist_head *entry;
+ struct disk_util *du;
+ bool do_json;
+
+ if (!is_running_backend())
+ return;
+
+ if (flist_empty(&disk_list)) {
+ return;
+ }
+
+ if ((output_format & FIO_OUTPUT_JSON) && parent)
+ do_json = true;
+ else
+ do_json = false;
+
+ if (!terse && !do_json)
+ log_buf(out, "\nDisk stats (read/write):\n");
+
+ if (do_json)
+ json_object_add_disk_utils(parent, &disk_list);
+ else if (output_format & ~(FIO_OUTPUT_JSON | FIO_OUTPUT_JSON_PLUS)) {
+ flist_for_each(entry, &disk_list) {
+ du = flist_entry(entry, struct disk_util, list);
+
+ aggregate_slaves_stats(du);
+ print_disk_util(&du->dus, &du->agg, terse, out);
+ }
+ }
+}
+