Don't setup output buffers we are not going to use
authorJens Axboe <axboe@fb.com>
Tue, 27 Oct 2015 07:43:44 +0000 (16:43 +0900)
committerJens Axboe <axboe@fb.com>
Tue, 27 Oct 2015 07:43:44 +0000 (16:43 +0900)
Signed-off-by: Jens Axboe <axboe@fb.com>
lib/output_buffer.c
lib/output_buffer.h
stat.c

index 145272a00d60e4ed067ac404c1a1966a4bb98668..da7087470ec41f131f0f03d8112086c223ab6bf8 100644 (file)
@@ -7,12 +7,11 @@
 
 #define BUF_INC        1024
 
 
 #define BUF_INC        1024
 
-void buf_output_init(struct buf_output *out, int index)
+void buf_output_init(struct buf_output *out)
 {
 {
-       out->max_buflen = BUF_INC;
-       out->buf = malloc(out->max_buflen);
-       memset(out->buf, 0, out->max_buflen);
+       out->max_buflen = 0;
        out->buflen = 0;
        out->buflen = 0;
+       out->buf = NULL;
 }
 
 void buf_output_free(struct buf_output *out)
 }
 
 void buf_output_free(struct buf_output *out)
@@ -23,11 +22,11 @@ void buf_output_free(struct buf_output *out)
 size_t buf_output_add(struct buf_output *out, const char *buf, size_t len)
 {
        while (out->max_buflen - out->buflen < len) {
 size_t buf_output_add(struct buf_output *out, const char *buf, size_t len)
 {
        while (out->max_buflen - out->buflen < len) {
-               size_t newlen = out->max_buflen + BUF_INC - out->buflen;
+               size_t old_max = out->max_buflen;
 
                out->max_buflen += BUF_INC;
                out->buf = realloc(out->buf, out->max_buflen);
 
                out->max_buflen += BUF_INC;
                out->buf = realloc(out->buf, out->max_buflen);
-               memset(&out->buf[out->buflen], 0, newlen);
+               memset(&out->buf[old_max], 0, BUF_INC);
        }
 
        memcpy(&out->buf[out->buflen], buf, len);
        }
 
        memcpy(&out->buf[out->buflen], buf, len);
index 0dfc3e254cbbdbf61e4199e29a5dfe97caf55aeb..396002fbfa91474fd02bfb291acdd72fa712918f 100644 (file)
@@ -9,7 +9,7 @@ struct buf_output {
        size_t max_buflen;
 };
 
        size_t max_buflen;
 };
 
-void buf_output_init(struct buf_output *out, int index);
+void buf_output_init(struct buf_output *out);
 void buf_output_free(struct buf_output *out);
 size_t buf_output_add(struct buf_output *out, const char *buf, size_t len);
 size_t buf_output_flush(struct buf_output *out);
 void buf_output_free(struct buf_output *out);
 size_t buf_output_add(struct buf_output *out, const char *buf, size_t len);
 size_t buf_output_flush(struct buf_output *out);
diff --git a/stat.c b/stat.c
index 3d7dcde10681a99dd56a6a8dd2663cf774aae4e7..2c218158b8cd61aa2780acb6d412e7a42b4bb5b4 100644 (file)
--- a/stat.c
+++ b/stat.c
@@ -1400,8 +1400,6 @@ void __show_run_stats(void)
 
        runstats = malloc(sizeof(struct group_run_stats) * (groupid + 1));
 
 
        runstats = malloc(sizeof(struct group_run_stats) * (groupid + 1));
 
-       memset(output, 0, sizeof(output));
-
        for (i = 0; i < groupid + 1; i++)
                init_group_run_stat(&runstats[i]);
 
        for (i = 0; i < groupid + 1; i++)
                init_group_run_stat(&runstats[i]);
 
@@ -1560,7 +1558,7 @@ void __show_run_stats(void)
        }
 
        for (i = 0; i < FIO_OUTPUT_NR; i++)
        }
 
        for (i = 0; i < FIO_OUTPUT_NR; i++)
-               buf_output_init(&output[i], i);
+               buf_output_init(&output[i]);
 
        /*
         * don't overwrite last signal output
 
        /*
         * don't overwrite last signal output