client: use temp buffer for single output flush for json/disk util
[fio.git] / client.c
index 31c7c6495790e91018cface694803ff9bfcefa1e..51d84e4249c0d072aa9548e42c359537f0dc9a9f 100644 (file)
--- a/client.c
+++ b/client.c
@@ -198,12 +198,17 @@ static void fio_client_json_init(void)
 
 static void fio_client_json_fini(void)
 {
+       struct buf_output out;
+
        if (!(output_format & FIO_OUTPUT_JSON))
                return;
 
-       log_info("\n");
-       json_print_object(root, NULL);
-       log_info("\n");
+       buf_output_init(&out);
+       __log_buf(&out, "\n");
+       json_print_object(root, &out);
+       __log_buf(&out, "\n");
+       log_info_buf(out.buf, out.buflen);
+       buf_output_free(&out);
        json_free_object(root);
        root = NULL;
        clients_array = NULL;
@@ -1059,9 +1064,6 @@ static void handle_ts(struct fio_client *client, struct fio_net_cmd *cmd)
        struct flist_head *opt_list = NULL;
        struct json_object *tsobj;
 
-       if (output_format & FIO_OUTPUT_TERSE)
-               return;
-
        if (client->opt_lists && p->ts.thread_number <= client->jobs)
                opt_list = &client->opt_lists[p->ts.thread_number - 1];
 
@@ -1098,9 +1100,6 @@ static void handle_gs(struct fio_client *client, struct fio_net_cmd *cmd)
 {
        struct group_run_stats *gs = (struct group_run_stats *) cmd->payload;
 
-       if (output_format & FIO_OUTPUT_TERSE)
-               return;
-
        if (output_format & FIO_OUTPUT_NORMAL)
                show_group_stats(gs, NULL);
 }
@@ -1144,13 +1143,17 @@ static void handle_text(struct fio_client *client, struct fio_net_cmd *cmd)
        const char *buf = (const char *) pdu->buf;
        const char *name;
        int fio_unused ret;
+       struct buf_output out;
+
+       buf_output_init(&out);
 
        name = client->name ? client->name : client->hostname;
 
        if (!client->skip_newline && !(output_format & FIO_OUTPUT_TERSE))
-               fprintf(f_out, "<%s> ", name);
-       ret = fwrite(buf, pdu->buf_len, 1, f_out);
-       fflush(f_out);
+               __log_buf(&out, "<%s> ", name);
+       __log_buf(&out, "%s", buf);
+       log_info_buf(out.buf, out.buflen);
+       buf_output_free(&out);
        client->skip_newline = strchr(buf, '\n') == NULL;
 }
 
@@ -1190,14 +1193,14 @@ static void convert_dus(struct disk_util_stat *dus)
 static void handle_du(struct fio_client *client, struct fio_net_cmd *cmd)
 {
        struct cmd_du_pdu *du = (struct cmd_du_pdu *) cmd->payload;
+       struct buf_output out;
 
-       if (output_format & FIO_OUTPUT_TERSE)
-               return;
+       buf_output_init(&out);
 
        if (!client->disk_stats_shown) {
                client->disk_stats_shown = true;
                if (!(output_format & FIO_OUTPUT_JSON))
-                       log_info("\nDisk stats (read/write):\n");
+                       __log_buf(&out, "\nDisk stats (read/write):\n");
        }
 
        if (output_format & FIO_OUTPUT_JSON) {
@@ -1206,8 +1209,11 @@ static void handle_du(struct fio_client *client, struct fio_net_cmd *cmd)
                duobj = json_array_last_value_object(du_array);
                json_object_add_client_info(duobj, client);
        }
+       if (output_format & FIO_OUTPUT_TERSE)
+               print_disk_util(&du->dus, &du->agg, 1, &out);
        if (output_format & FIO_OUTPUT_NORMAL)
-               print_disk_util(&du->dus, &du->agg, 0, NULL);
+               print_disk_util(&du->dus, &du->agg, 0, &out);
+       buf_output_free(&out);
 }
 
 static void convert_jobs_eta(struct jobs_eta *je)
@@ -1465,9 +1471,6 @@ static void handle_probe(struct fio_client *client, struct fio_net_cmd *cmd)
        const char *os, *arch;
        char bit[16];
 
-       if (output_format & FIO_OUTPUT_TERSE)
-               return;
-
        os = fio_get_os_string(probe->os);
        if (!os)
                os = "unknown";