X-Git-Url: https://git.kernel.dk/?a=blobdiff_plain;f=stat.c;h=818756dd8537d3385995ae817a7815f57c0c3008;hb=0c5df5f9adccf9e3d8aaba88258ae9a4e0d3b643;hp=7fa601b72d0c3b2e6c449040cbe97f1ea9f60e1d;hpb=3d57c0e9b017a745c748416ce46d2a532d4bc274;p=fio.git diff --git a/stat.c b/stat.c index 7fa601b7..818756dd 100644 --- a/stat.c +++ b/stat.c @@ -18,6 +18,16 @@ struct fio_mutex *stat_mutex; +void clear_rusage_stat(struct thread_data *td) +{ + struct thread_stat *ts = &td->ts; + + fio_getrusage(&td->ru_start); + ts->usr_time = ts->sys_time = 0; + ts->ctx = 0; + ts->minf = ts->majf = 0; +} + void update_rusage_stat(struct thread_data *td) { struct thread_stat *ts = &td->ts; @@ -832,7 +842,7 @@ static void add_ddir_status_json(struct thread_stat *ts, unsigned int len, minv, maxv; int i; const char *ddirname[] = {"read", "write", "trim"}; - struct json_object *dir_object, *tmp_object, *percentile_object; + struct json_object *dir_object, *tmp_object, *percentile_object, *clat_bins_object; char buf[120]; double p_of_agg = 100.0; @@ -903,6 +913,18 @@ static void add_ddir_status_json(struct thread_stat *ts, json_object_add_value_int(percentile_object, (const char *)buf, ovals[i]); } + if (output_format & FIO_OUTPUT_JSON_PLUS) { + clat_bins_object = json_create_object(); + json_object_add_value_object(tmp_object, "bins", clat_bins_object); + for(i = 0; i < FIO_IO_U_PLAT_NR; i++) { + snprintf(buf, sizeof(buf), "%d", i); + json_object_add_value_int(clat_bins_object, (const char *)buf, ts->io_u_plat[ddir][i]); + } + json_object_add_value_int(clat_bins_object, "FIO_IO_U_PLAT_BITS", FIO_IO_U_PLAT_BITS); + json_object_add_value_int(clat_bins_object, "FIO_IO_U_PLAT_VAL", FIO_IO_U_PLAT_VAL); + json_object_add_value_int(clat_bins_object, "FIO_IO_U_PLAT_NR", FIO_IO_U_PLAT_NR); + } + if (!calc_lat(&ts->lat_stat[ddir], &min, &max, &mean, &dev)) { min = max = 0; mean = dev = 0.0; @@ -1083,9 +1105,10 @@ static struct json_object *show_thread_status_json(struct thread_stat *ts, /* ETA Info */ je = get_jobs_eta(1, &size); - json_object_add_value_int(root, "eta", je->eta_sec); - json_object_add_value_int(root, "elapsed", je->elapsed_sec); - + if (je) { + json_object_add_value_int(root, "eta", je->eta_sec); + json_object_add_value_int(root, "elapsed", je->elapsed_sec); + } add_ddir_status_json(ts, rs, DDIR_READ, root); add_ddir_status_json(ts, rs, DDIR_WRITE, root); @@ -1172,7 +1195,7 @@ static struct json_object *show_thread_status_json(struct thread_stat *ts, if (len) { struct json_object *block, *percentile_object, *states; - int state, i; + int state; block = json_create_object(); json_object_add_value_object(root, "block", block); @@ -1230,7 +1253,7 @@ struct json_object *show_thread_status(struct thread_stat *ts, return ret; } -static void sum_stat(struct io_stat *dst, struct io_stat *src, int nr) +static void sum_stat(struct io_stat *dst, struct io_stat *src, bool first) { double mean, S; @@ -1245,7 +1268,7 @@ static void sum_stat(struct io_stat *dst, struct io_stat *src, int nr) * */ - if (nr == 1) { + if (first) { mean = src->mean.u.f; S = src->S.u.f; } else { @@ -1289,31 +1312,38 @@ void sum_group_stats(struct group_run_stats *dst, struct group_run_stats *src) dst->unit_base = src->unit_base; } -void sum_thread_stats(struct thread_stat *dst, struct thread_stat *src, int nr) +void sum_thread_stats(struct thread_stat *dst, struct thread_stat *src, + bool first) { int l, k; for (l = 0; l < DDIR_RWDIR_CNT; l++) { if (!dst->unified_rw_rep) { - sum_stat(&dst->clat_stat[l], &src->clat_stat[l], nr); - sum_stat(&dst->slat_stat[l], &src->slat_stat[l], nr); - sum_stat(&dst->lat_stat[l], &src->lat_stat[l], nr); - sum_stat(&dst->bw_stat[l], &src->bw_stat[l], nr); + sum_stat(&dst->clat_stat[l], &src->clat_stat[l], first); + sum_stat(&dst->slat_stat[l], &src->slat_stat[l], first); + sum_stat(&dst->lat_stat[l], &src->lat_stat[l], first); + sum_stat(&dst->bw_stat[l], &src->bw_stat[l], first); dst->io_bytes[l] += src->io_bytes[l]; if (dst->runtime[l] < src->runtime[l]) dst->runtime[l] = src->runtime[l]; } else { - sum_stat(&dst->clat_stat[0], &src->clat_stat[l], nr); - sum_stat(&dst->slat_stat[0], &src->slat_stat[l], nr); - sum_stat(&dst->lat_stat[0], &src->lat_stat[l], nr); - sum_stat(&dst->bw_stat[0], &src->bw_stat[l], nr); + sum_stat(&dst->clat_stat[0], &src->clat_stat[l], first); + sum_stat(&dst->slat_stat[0], &src->slat_stat[l], first); + sum_stat(&dst->lat_stat[0], &src->lat_stat[l], first); + sum_stat(&dst->bw_stat[0], &src->bw_stat[l], first); dst->io_bytes[0] += src->io_bytes[l]; if (dst->runtime[0] < src->runtime[l]) dst->runtime[0] = src->runtime[l]; + + /* + * We're summing to the same destination, so override + * 'first' after the first iteration of the loop + */ + first = false; } } @@ -1508,7 +1538,7 @@ void __show_run_stats(void) for (k = 0; k < ts->nr_block_infos; k++) ts->block_infos[k] = td->ts.block_infos[k]; - sum_thread_stats(ts, &td->ts, idx); + sum_thread_stats(ts, &td->ts, idx == 1); } for (i = 0; i < nr_ts; i++) { @@ -1599,7 +1629,7 @@ void __show_run_stats(void) show_thread_status_normal(ts, rs, &output[__FIO_OUTPUT_NORMAL]); } } - if (output_format & FIO_OUTPUT_JSON) { + if (!is_backend && (output_format & FIO_OUTPUT_JSON)) { /* disk util stats, if any */ show_disk_util(1, root, &output[__FIO_OUTPUT_JSON]);