From 129fb2d422557e493020a8eac00867749af284b4 Mon Sep 17 00:00:00 2001 From: Jens Axboe Date: Sun, 25 Oct 2015 11:55:34 +0900 Subject: [PATCH] Add support for multiple output formats Signed-off-by: Jens Axboe --- diskutil.c | 9 +++++---- eta.c | 2 +- filesetup.c | 2 +- fio.h | 10 +++++++--- init.c | 4 ++-- stat.c | 42 ++++++++++++++++++++++++------------------ 6 files changed, 40 insertions(+), 29 deletions(-) diff --git a/diskutil.c b/diskutil.c index 52d87f64..bb68e8d3 100644 --- a/diskutil.c +++ b/diskutil.c @@ -704,21 +704,22 @@ void show_disk_util(int terse, struct json_object *parent) return; } - if (output_format == FIO_OUTPUT_JSON) + if (output_format & FIO_OUTPUT_JSON) assert(parent); - if (!terse && output_format != FIO_OUTPUT_JSON) + if (!terse && !(output_format & FIO_OUTPUT_JSON)) log_info("\nDisk stats (read/write):\n"); - if (output_format == FIO_OUTPUT_JSON) + if (output_format & FIO_OUTPUT_JSON) json_object_add_disk_utils(parent, &disk_list); - else + if (output_format & ~(FIO_OUTPUT_JSON)) { 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); } + } fio_mutex_up(disk_util_mutex); } diff --git a/eta.c b/eta.c index 3e8eb0bb..ba066546 100644 --- a/eta.c +++ b/eta.c @@ -352,7 +352,7 @@ int calc_thread_status(struct jobs_eta *je, int force) static struct timeval rate_prev_time, disp_prev_time; if (!force) { - if (output_format != FIO_OUTPUT_NORMAL && + if (!(output_format & FIO_OUTPUT_NORMAL) && f_out == stdout) return 0; if (temp_stall_ts || eta_print == FIO_ETA_NEVER) diff --git a/filesetup.c b/filesetup.c index e1dedcd8..634d556e 100644 --- a/filesetup.c +++ b/filesetup.c @@ -936,7 +936,7 @@ int setup_files(struct thread_data *td) */ if (need_extend) { temp_stall_ts = 1; - if (output_format == FIO_OUTPUT_NORMAL) + if (output_format & FIO_OUTPUT_NORMAL) log_info("%s: Laying out IO file(s) (%u file(s) /" " %lluMB)\n", o->name, need_extend, extend_size >> 20); diff --git a/fio.h b/fio.h index adf879f3..b3fe9e1b 100644 --- a/fio.h +++ b/fio.h @@ -674,9 +674,13 @@ extern const char *fio_get_os_string(int); #endif enum { - FIO_OUTPUT_TERSE = 0, - FIO_OUTPUT_JSON, - FIO_OUTPUT_NORMAL, + __FIO_OUTPUT_TERSE = 0, + __FIO_OUTPUT_JSON = 1, + __FIO_OUTPUT_NORMAL = 2, + + FIO_OUTPUT_TERSE = 1U << __FIO_OUTPUT_TERSE, + FIO_OUTPUT_JSON = 1U << __FIO_OUTPUT_JSON, + FIO_OUTPUT_NORMAL = 1U << __FIO_OUTPUT_NORMAL, }; enum { diff --git a/init.c b/init.c index 3f72b366..e7faca10 100644 --- a/init.c +++ b/init.c @@ -1317,7 +1317,7 @@ static int add_job(struct thread_data *td, const char *jobname, int job_add_num, if (!o->name) o->name = strdup(jobname); - if (output_format == FIO_OUTPUT_NORMAL) { + if (output_format & FIO_OUTPUT_NORMAL) { if (!job_add_num) { if (is_backend && !recursed) fio_server_send_add_job(td); @@ -2532,7 +2532,7 @@ int parse_options(int argc, char *argv[]) return 0; } - if (output_format == FIO_OUTPUT_NORMAL) + if (output_format & FIO_OUTPUT_NORMAL) log_info("%s\n", fio_version_string); return 0; diff --git a/stat.c b/stat.c index 00eb75d7..ea5b43a3 100644 --- a/stat.c +++ b/stat.c @@ -1211,13 +1211,16 @@ static void show_thread_status_terse(struct thread_stat *ts, struct json_object *show_thread_status(struct thread_stat *ts, struct group_run_stats *rs) { - if (output_format == FIO_OUTPUT_TERSE) + struct json_object *ret = NULL; + + if (output_format & FIO_OUTPUT_TERSE) show_thread_status_terse(ts, rs); - else if (output_format == FIO_OUTPUT_JSON) - return show_thread_status_json(ts, rs); - else + if (output_format & FIO_OUTPUT_JSON) + ret = show_thread_status_json(ts, rs); + if (output_format & FIO_OUTPUT_NORMAL) show_thread_status_normal(ts, rs); - return NULL; + + return ret; } static void sum_stat(struct io_stat *dst, struct io_stat *src, int nr) @@ -1548,9 +1551,9 @@ void __show_run_stats(void) /* * don't overwrite last signal output */ - if (output_format == FIO_OUTPUT_NORMAL) + if (output_format & FIO_OUTPUT_NORMAL) log_info("\n"); - else if (output_format == FIO_OUTPUT_JSON) { + if (output_format & FIO_OUTPUT_JSON) { char time_buf[32]; time_t time_p; @@ -1573,15 +1576,18 @@ void __show_run_stats(void) if (is_backend) fio_server_send_ts(ts, rs); - else if (output_format == FIO_OUTPUT_TERSE) - show_thread_status_terse(ts, rs); - else if (output_format == FIO_OUTPUT_JSON) { - struct json_object *tmp = show_thread_status_json(ts, rs); - json_array_add_value_object(array, tmp); - } else - show_thread_status_normal(ts, rs); + else { + if (output_format & FIO_OUTPUT_TERSE) + show_thread_status_terse(ts, rs); + if (output_format & FIO_OUTPUT_JSON) { + struct json_object *tmp = show_thread_status_json(ts, rs); + json_array_add_value_object(array, tmp); + } + if (output_format & FIO_OUTPUT_NORMAL) + show_thread_status_normal(ts, rs); + } } - if (output_format == FIO_OUTPUT_JSON) { + if (output_format & FIO_OUTPUT_JSON) { /* disk util stats, if any */ show_disk_util(1, root); @@ -1598,18 +1604,18 @@ void __show_run_stats(void) rs->groupid = i; if (is_backend) fio_server_send_gs(rs); - else if (output_format == FIO_OUTPUT_NORMAL) + else if (output_format & FIO_OUTPUT_NORMAL) show_group_stats(rs); } if (is_backend) fio_server_send_du(); - else if (output_format == FIO_OUTPUT_NORMAL) { + else if (output_format & FIO_OUTPUT_NORMAL) { show_disk_util(0, NULL); show_idle_prof_stats(FIO_OUTPUT_NORMAL, NULL); } - if ( !(output_format == FIO_OUTPUT_TERSE) && append_terse_output) { + if ( !(output_format & FIO_OUTPUT_TERSE) && append_terse_output) { log_info("\nAdditional Terse Output:\n"); for (i = 0; i < nr_ts; i++) { -- 2.25.1