[PATCH] Enable output logging to file instead of stdout
authorJens Axboe <axboe@suse.de>
Thu, 8 Jun 2006 19:40:11 +0000 (21:40 +0200)
committerJens Axboe <axboe@suse.de>
Thu, 8 Jun 2006 19:40:11 +0000 (21:40 +0200)
README
fio.c
fio.h
init.c
ioengines.c
log.c
stat.c

diff --git a/README b/README
index a85962e4b9345bb0f10e69690a73d0bffc2c67e6..94a1b40843ff633d7a310362aacafb0e8b266571 100644 (file)
--- a/README
+++ b/README
@@ -50,6 +50,7 @@ $ fio
        -l Generate per-job latency logs
        -w Generate per-job bandwidth logs
        -f <file> Read <file> for job descriptions
        -l Generate per-job latency logs
        -w Generate per-job bandwidth logs
        -f <file> Read <file> for job descriptions
+       -O <file> Log output to file
        -h Print help info
        -v Print version information and exit
 
        -h Print help info
        -v Print version information and exit
 
diff --git a/fio.c b/fio.c
index 93ca720e63d561af530a1dddc4730891de3e445c..c95d7b57deb4ad903ae84d34849fc19bb26f4378 100644 (file)
--- a/fio.c
+++ b/fio.c
@@ -222,7 +222,7 @@ static int check_min_rate(struct thread_data *td, struct timeval *now)
 
                rate = (td->this_io_bytes[ddir] - td->rate_bytes) / spent;
                if (rate < td->ratemin) {
 
                rate = (td->this_io_bytes[ddir] - td->rate_bytes) / spent;
                if (rate < td->ratemin) {
-                       printf("%s: min rate %d not met, got %ldKiB/sec\n", td->name, td->ratemin, rate);
+                       fprintf(f_out, "%s: min rate %d not met, got %ldKiB/sec\n", td->name, td->ratemin, rate);
                        if (rate_quit)
                                terminate_threads(td->groupid);
                        return 1;
                        if (rate_quit)
                                terminate_threads(td->groupid);
                        return 1;
@@ -274,8 +274,8 @@ static void hexdump(void *buffer, int len)
        int i;
 
        for (i = 0; i < len; i++)
        int i;
 
        for (i = 0; i < len; i++)
-               printf("%02x", p[i]);
-       printf("\n");
+               fprintf(f_out, "%02x", p[i]);
+       fprintf(f_out, "\n");
 }
 
 static int verify_io_u_crc32(struct verify_header *hdr, struct io_u *io_u)
 }
 
 static int verify_io_u_crc32(struct verify_header *hdr, struct io_u *io_u)
@@ -287,8 +287,8 @@ static int verify_io_u_crc32(struct verify_header *hdr, struct io_u *io_u)
        c = crc32(p, hdr->len - sizeof(*hdr));
 
        if (c != hdr->crc32) {
        c = crc32(p, hdr->len - sizeof(*hdr));
 
        if (c != hdr->crc32) {
-               fprintf(stderr, "crc32: verify failed at %llu/%u\n", io_u->offset, io_u->buflen);
-               fprintf(stderr, "crc32: wanted %lx, got %lx\n", hdr->crc32, c);
+               fprintf(f_err, "crc32: verify failed at %llu/%u\n", io_u->offset, io_u->buflen);
+               fprintf(f_err, "crc32: wanted %lx, got %lx\n", hdr->crc32, c);
                return 1;
        }
 
                return 1;
        }
 
@@ -305,7 +305,7 @@ static int verify_io_u_md5(struct verify_header *hdr, struct io_u *io_u)
        md5_update(&md5_ctx, p, hdr->len - sizeof(*hdr));
 
        if (memcmp(hdr->md5_digest, md5_ctx.hash, sizeof(md5_ctx.hash))) {
        md5_update(&md5_ctx, p, hdr->len - sizeof(*hdr));
 
        if (memcmp(hdr->md5_digest, md5_ctx.hash, sizeof(md5_ctx.hash))) {
-               fprintf(stderr, "md5: verify failed at %llu/%u\n", io_u->offset, io_u->buflen);
+               fprintf(f_err, "md5: verify failed at %llu/%u\n", io_u->offset, io_u->buflen);
                hexdump(hdr->md5_digest, sizeof(hdr->md5_digest));
                hexdump(md5_ctx.hash, sizeof(md5_ctx.hash));
                return 1;
                hexdump(hdr->md5_digest, sizeof(hdr->md5_digest));
                hexdump(md5_ctx.hash, sizeof(md5_ctx.hash));
                return 1;
@@ -327,7 +327,7 @@ static int verify_io_u(struct io_u *io_u)
        else if (hdr->verify_type == VERIFY_CRC32)
                ret = verify_io_u_crc32(hdr, io_u);
        else {
        else if (hdr->verify_type == VERIFY_CRC32)
                ret = verify_io_u_crc32(hdr, io_u);
        else {
-               fprintf(stderr, "Bad verify type %d\n", hdr->verify_type);
+               fprintf(f_err, "Bad verify type %d\n", hdr->verify_type);
                ret = 1;
        }
 
                ret = 1;
        }
 
@@ -851,7 +851,7 @@ static int init_io(struct thread_data *td)
        else if (td->io_engine == FIO_SPLICEIO)
                return fio_spliceio_init(td);
        else {
        else if (td->io_engine == FIO_SPLICEIO)
                return fio_spliceio_init(td);
        else {
-               fprintf(stderr, "bad io_engine %d\n", td->io_engine);
+               fprintf(f_err, "bad io_engine %d\n", td->io_engine);
                return 1;
        }
 }
                return 1;
        }
 }
@@ -878,7 +878,7 @@ static void cleanup_io_u(struct thread_data *td)
        } else if (td->mem_type == MEM_MMAP)
                munmap(td->orig_buffer, td->orig_buffer_size);
        else
        } else if (td->mem_type == MEM_MMAP)
                munmap(td->orig_buffer, td->orig_buffer_size);
        else
-               fprintf(stderr, "Bad memory type %d\n", td->mem_type);
+               fprintf(f_err, "Bad memory type %d\n", td->mem_type);
 
        td->orig_buffer = NULL;
 }
 
        td->orig_buffer = NULL;
 }
@@ -952,17 +952,17 @@ static int create_file(struct thread_data *td, unsigned long long size,
                return 0;
 
        if (!size) {
                return 0;
 
        if (!size) {
-               fprintf(stderr, "Need size for create\n");
+               fprintf(f_err, "Need size for create\n");
                td_verror(td, EINVAL);
                return 1;
        }
 
        if (!extend) {
                oflags = O_CREAT | O_TRUNC;
                td_verror(td, EINVAL);
                return 1;
        }
 
        if (!extend) {
                oflags = O_CREAT | O_TRUNC;
-               printf("%s: Laying out IO file (%LuMiB)\n", td->name, size >> 20);
+               fprintf(f_out, "%s: Laying out IO file (%LuMiB)\n", td->name, size >> 20);
        } else {
                oflags = O_APPEND;
        } else {
                oflags = O_APPEND;
-               printf("%s: Extending IO file (%Lu -> %LuMiB)\n", td->name, (td->file_size - size) >> 20, td->file_size >> 20);
+               fprintf(f_out, "%s: Extending IO file (%Lu -> %LuMiB)\n", td->name, (td->file_size - size) >> 20, td->file_size >> 20);
        }
 
        td->fd = open(td->file_name, O_WRONLY | oflags, 0644);
        }
 
        td->fd = open(td->file_name, O_WRONLY | oflags, 0644);
@@ -1068,13 +1068,13 @@ static int get_file_size(struct thread_data *td)
                return ret;
 
        if (td->file_offset > td->real_file_size) {
                return ret;
 
        if (td->file_offset > td->real_file_size) {
-               fprintf(stderr, "%s: offset extends end (%Lu > %Lu)\n", td->name, td->file_offset, td->real_file_size);
+               fprintf(f_err, "%s: offset extends end (%Lu > %Lu)\n", td->name, td->file_offset, td->real_file_size);
                return 1;
        }
 
        td->io_size = td->file_size;
        if (td->io_size == 0) {
                return 1;
        }
 
        td->io_size = td->file_size;
        if (td->io_size == 0) {
-               fprintf(stderr, "%s: no io blocks\n", td->name);
+               fprintf(f_err, "%s: no io blocks\n", td->name);
                td_verror(td, EINVAL);
                return 1;
        }
                td_verror(td, EINVAL);
                return 1;
        }
@@ -1253,7 +1253,7 @@ static int switch_ioscheduler(struct thread_data *td)
 
        sprintf(tmp2, "[%s]", td->ioscheduler);
        if (!strstr(tmp, tmp2)) {
 
        sprintf(tmp2, "[%s]", td->ioscheduler);
        if (!strstr(tmp, tmp2)) {
-               fprintf(stderr, "fio: io scheduler %s not found\n", td->ioscheduler);
+               fprintf(f_err, "fio: io scheduler %s not found\n", td->ioscheduler);
                td_verror(td, EINVAL);
                fclose(f);
                return 1;
                td_verror(td, EINVAL);
                fclose(f);
                return 1;
@@ -1461,7 +1461,7 @@ static void check_str_update(struct thread_data *td)
                        c = 'P';
                        break;
                default:
                        c = 'P';
                        break;
                default:
-                       printf("state %d\n", td->runstate);
+                       fprintf(f_err, "state %d\n", td->runstate);
        }
 
        run_str[td->thread_number - 1] = c;
        }
 
        run_str[td->thread_number - 1] = c;
@@ -1613,7 +1613,7 @@ static void print_thread_status(void)
        if (!nr_running && !nr_pending)
                return;
 
        if (!nr_running && !nr_pending)
                return;
 
-       printf("Threads now running (%d)", nr_running);
+       printf("Threads running: %d", nr_running);
        if (m_rate || t_rate)
                printf(", commitrate %d/%dKiB/sec", t_rate, m_rate);
        if (eta_sec != INT_MAX) {
        if (m_rate || t_rate)
                printf(", commitrate %d/%dKiB/sec", t_rate, m_rate);
        if (eta_sec != INT_MAX) {
@@ -1678,8 +1678,7 @@ static void *fio_pin_memory(void)
        if (phys_mem) {
                if ((mlock_size + 128 * 1024 * 1024) > phys_mem) {
                        mlock_size = phys_mem - 128 * 1024 * 1024;
        if (phys_mem) {
                if ((mlock_size + 128 * 1024 * 1024) > phys_mem) {
                        mlock_size = phys_mem - 128 * 1024 * 1024;
-                       printf("fio: limiting mlocked memory to %lluMiB\n",
-                                                       mlock_size >> 20);
+                       fprintf(f_out, "fio: limiting mlocked memory to %lluMiB\n", mlock_size >> 20);
                }
        }
 
                }
        }
 
@@ -1827,7 +1826,7 @@ static void run_threads(void)
                }
 
                if (left) {
                }
 
                if (left) {
-                       fprintf(stderr, "fio: %d jobs failed to start\n", left);
+                       fprintf(f_err, "fio: %d jobs failed to start\n", left);
                        for (i = 0; i < this_jobs; i++) {
                                td = map[i];
                                if (!td)
                        for (i = 0; i < this_jobs; i++) {
                                td = map[i];
                                if (!td)
@@ -1877,7 +1876,7 @@ int main(int argc, char *argv[])
                return 1;
 
        if (!thread_number) {
                return 1;
 
        if (!thread_number) {
-               printf("Nothing to do\n");
+               fprintf(f_err, "Nothing to do\n");
                return 1;
        }
 
                return 1;
        }
 
diff --git a/fio.h b/fio.h
index 671cb22f88609da3aed675be5c818b2de51ee101..f6c2ee3bd81cd149b7f8da4866e48c32750765b7 100644 (file)
--- a/fio.h
+++ b/fio.h
@@ -324,6 +324,8 @@ extern int exitall_on_terminate;
 extern int thread_number;
 extern int shm_id;
 extern int groupid;
 extern int thread_number;
 extern int shm_id;
 extern int groupid;
+extern FILE *f_out;
+extern FILE *f_err;
 
 extern struct thread_data *threads;
 
 
 extern struct thread_data *threads;
 
diff --git a/init.c b/init.c
index 3117d60e5d68e530fde45fed328b7b6bb4e39108..b40437afa84fab9aaaeac099e37088246ce2bcd5 100644 (file)
--- a/init.c
+++ b/init.c
@@ -54,6 +54,8 @@ int write_lat_log = 0;
 int write_bw_log = 0;
 int exitall_on_terminate = 0;
 unsigned long long mlock_size = 0;
 int write_bw_log = 0;
 int exitall_on_terminate = 0;
 unsigned long long mlock_size = 0;
+FILE *f_out = NULL;
+FILE *f_err = NULL;
 
 static struct thread_data *get_new_job(int global, struct thread_data *parent)
 {
 
 static struct thread_data *get_new_job(int global, struct thread_data *parent)
 {
@@ -89,13 +91,13 @@ static int add_job(struct thread_data *td, const char *jobname, int job_add_num)
 
 #ifndef FIO_HAVE_LIBAIO
        if (td->io_engine == FIO_LIBAIO) {
 
 #ifndef FIO_HAVE_LIBAIO
        if (td->io_engine == FIO_LIBAIO) {
-               fprintf(stderr, "Linux libaio not available\n");
+               fprintf(f_err, "Linux libaio not available\n");
                return 1;
        }
 #endif
 #ifndef FIO_HAVE_POSIXAIO
        if (td->io_engine == FIO_POSIXAIO) {
                return 1;
        }
 #endif
 #ifndef FIO_HAVE_POSIXAIO
        if (td->io_engine == FIO_POSIXAIO) {
-               fprintf(stderr, "posix aio not available\n");
+               fprintf(f_err, "posix aio not available\n");
                return 1;
        }
 #endif
                return 1;
        }
 #endif
@@ -172,9 +174,9 @@ static int add_job(struct thread_data *td, const char *jobname, int job_add_num)
        ddir = td->ddir + (!td->sequential << 1) + (td->iomix << 2);
 
        if (!job_add_num)
        ddir = td->ddir + (!td->sequential << 1) + (td->iomix << 2);
 
        if (!job_add_num)
-               printf("%s: (g=%d): rw=%s, odir=%d, bs=%d-%d, rate=%d, ioengine=%s, iodepth=%d\n", td->name, td->groupid, ddir_str[ddir], td->odirect, td->min_bs, td->max_bs, td->rate, td->io_engine_name, td->iodepth);
+               fprintf(f_out, "%s: (g=%d): rw=%s, odir=%d, bs=%d-%d, rate=%d, ioengine=%s, iodepth=%d\n", td->name, td->groupid, ddir_str[ddir], td->odirect, td->min_bs, td->max_bs, td->rate, td->io_engine_name, td->iodepth);
        else if (job_add_num == 1)
        else if (job_add_num == 1)
-               printf("...\n");
+               fprintf(f_out, "...\n");
 
        /*
         * recurse add identical jobs, clear numjobs and stonewall options
 
        /*
         * recurse add identical jobs, clear numjobs and stonewall options
@@ -493,7 +495,7 @@ static int str_rw_cb(struct thread_data *td, char *mem)
                return 0;
        }
 
                return 0;
        }
 
-       fprintf(stderr, "fio: data direction: read, write, randread, randwrite, rw, randrw\n");
+       fprintf(f_err, "fio: data direction: read, write, randread, randwrite, rw, randrw\n");
        return 1;
 }
 
        return 1;
 }
 
@@ -510,7 +512,7 @@ static int str_verify_cb(struct thread_data *td, char *mem)
                return 0;
        }
 
                return 0;
        }
 
-       fprintf(stderr, "fio: verify types: md5, crc32\n");
+       fprintf(f_err, "fio: verify types: md5, crc32\n");
        return 1;
 }
 
        return 1;
 }
 
@@ -527,7 +529,7 @@ static int str_mem_cb(struct thread_data *td, char *mem)
                return 0;
        }
 
                return 0;
        }
 
-       fprintf(stderr, "fio: mem type: malloc, shm, mmap\n");
+       fprintf(f_err, "fio: mem type: malloc, shm, mmap\n");
        return 1;
 }
 
        return 1;
 }
 
@@ -560,7 +562,7 @@ static int str_ioengine_cb(struct thread_data *td, char *str)
                return 0;
        }
 
                return 0;
        }
 
-       fprintf(stderr, "fio: ioengine: { linuxaio, aio, libaio }, posixaio, sync, mmap, sgio, splice\n");
+       fprintf(f_err, "fio: ioengine: { linuxaio, aio, libaio }, posixaio, sync, mmap, sgio, splice\n");
        return 1;
 }
 
        return 1;
 }
 
@@ -618,7 +620,7 @@ int parse_jobs_ini(char *file)
 
                        if (!check_int(p, "prio", &prio)) {
 #ifndef FIO_HAVE_IOPRIO
 
                        if (!check_int(p, "prio", &prio)) {
 #ifndef FIO_HAVE_IOPRIO
-                               fprintf(stderr, "io priorities not available\n");
+                               fprintf(f_err, "io priorities not available\n");
                                ret = 1;
                                break;
 #endif
                                ret = 1;
                                break;
 #endif
@@ -628,7 +630,7 @@ int parse_jobs_ini(char *file)
                        }
                        if (!check_int(p, "prioclass", &prioclass)) {
 #ifndef FIO_HAVE_IOPRIO
                        }
                        if (!check_int(p, "prioclass", &prioclass)) {
 #ifndef FIO_HAVE_IOPRIO
-                               fprintf(stderr, "io priorities not available\n");
+                               fprintf(f_err, "io priorities not available\n");
                                ret = 1;
                                break;
 #else
                                ret = 1;
                                break;
 #else
@@ -660,7 +662,7 @@ int parse_jobs_ini(char *file)
                        }
                        if (!check_int(p, "cpumask", &cpu)) {
 #ifndef FIO_HAVE_CPU_AFFINITY
                        }
                        if (!check_int(p, "cpumask", &cpu)) {
 #ifndef FIO_HAVE_CPU_AFFINITY
-                               fprintf(stderr, "cpu affinity not available\n");
+                               fprintf(f_err, "cpu affinity not available\n");
                                ret = 1;
                                break;
 #endif
                                ret = 1;
                                break;
 #endif
@@ -833,7 +835,7 @@ int parse_jobs_ini(char *file)
                        }
                        if (!check_strstore(p, "iolog", tmpbuf)) {
                                if (td->write_iolog) {
                        }
                        if (!check_strstore(p, "iolog", tmpbuf)) {
                                if (td->write_iolog) {
-                                       fprintf(stderr, "fio: read iolog overrides given write_iolog\n");
+                                       fprintf(f_err, "fio: read iolog overrides given write_iolog\n");
                                        free(td->iolog_file);
                                        td->write_iolog = 0;
                                }
                                        free(td->iolog_file);
                                        td->write_iolog = 0;
                                }
@@ -847,7 +849,7 @@ int parse_jobs_ini(char *file)
                                        td->iolog_file = strdup(tmpbuf);
                                        td->write_iolog = 1;
                                } else
                                        td->iolog_file = strdup(tmpbuf);
                                        td->write_iolog = 1;
                                } else
-                                       fprintf(stderr, "fio: read iolog overrides given write_iolog\n");
+                                       fprintf(f_err, "fio: read iolog overrides given write_iolog\n");
                                fgetpos(f, &off);
                                continue;
                        }
                                fgetpos(f, &off);
                                continue;
                        }
@@ -863,7 +865,7 @@ int parse_jobs_ini(char *file)
                        }
                        if (!check_strstore(p, "ioscheduler", tmpbuf)) {
 #ifndef FIO_HAVE_IOSCHED_SWITCH
                        }
                        if (!check_strstore(p, "ioscheduler", tmpbuf)) {
 #ifndef FIO_HAVE_IOSCHED_SWITCH
-                               fprintf(stderr, "io scheduler switching not available\n");
+                               fprintf(f_err, "io scheduler switching not available\n");
                                ret = 1;
                                break;
 #else
                                ret = 1;
                                break;
 #else
@@ -961,7 +963,7 @@ static void parse_cmd_line(int argc, char *argv[])
 {
        int c;
 
 {
        int c;
 
-       while ((c = getopt(argc, argv, "s:b:t:r:R:o:f:lwvh")) != EOF) {
+       while ((c = getopt(argc, argv, "s:b:t:r:R:o:f:lwvhO:")) != EOF) {
                switch (c) {
                        case 's':
                                def_thread.sequential = !!atoi(optarg);
                switch (c) {
                        case 's':
                                def_thread.sequential = !!atoi(optarg);
@@ -995,6 +997,14 @@ static void parse_cmd_line(int argc, char *argv[])
                        case 'w':
                                write_bw_log = 1;
                                break;
                        case 'w':
                                write_bw_log = 1;
                                break;
+                       case 'O':
+                               f_out = fopen(optarg, "w+");
+                               if (!f_out) {
+                                       perror("fopen output");
+                                       exit(1);
+                               }
+                               f_err = f_out;
+                               break;
                        case 'h':
                                usage(argv[0]);
                                exit(0);
                        case 'h':
                                usage(argv[0]);
                                exit(0);
@@ -1006,6 +1016,10 @@ static void parse_cmd_line(int argc, char *argv[])
 
        if (!ini_file && argc > 1 && argv[argc - 1][0] != '-')
                ini_file = strdup(argv[argc - 1]);
 
        if (!ini_file && argc > 1 && argv[argc - 1][0] != '-')
                ini_file = strdup(argv[argc - 1]);
+       if (!f_out) {
+               f_out = stdout;
+               f_err = stderr;
+       }
 }
 
 static void free_shm(void)
 }
 
 static void free_shm(void)
@@ -1062,7 +1076,7 @@ int parse_options(int argc, char *argv[])
        parse_cmd_line(argc, argv);
 
        if (!ini_file) {
        parse_cmd_line(argc, argv);
 
        if (!ini_file) {
-               printf("Need job file\n");
+               fprintf(f_err, "Need job file\n");
                usage(argv[0]);
                return 1;
        }
                usage(argv[0]);
                return 1;
        }
index b086b60c9d3e156c4c9781b6e3f868577285f37b..c94fcb30c23b87ccea185b88c642081864017111 100644 (file)
@@ -610,7 +610,7 @@ static int fio_sgio_prep(struct thread_data *td, struct io_u *io_u)
        int nr_blocks, lba;
 
        if (io_u->buflen & (sd->bs - 1)) {
        int nr_blocks, lba;
 
        if (io_u->buflen & (sd->bs - 1)) {
-               fprintf(stderr, "read/write not sector aligned\n");
+               fprintf(f_err, "read/write not sector aligned\n");
                return EINVAL;
        }
 
                return EINVAL;
        }
 
@@ -718,7 +718,7 @@ int fio_sgio_init(struct thread_data *td)
                if (ret)
                        return ret;
        } else {
                if (ret)
                        return ret;
        } else {
-               fprintf(stderr, "ioengine sgio only works on block devices\n");
+               fprintf(f_err, "ioengine sgio only works on block devices\n");
                return 1;
        }
 
                return 1;
        }
 
diff --git a/log.c b/log.c
index 8d313ec65419ef926f560d762d88eb4996341379..a364e220919eb3ee23185fb128a9de80908884cf 100644 (file)
--- a/log.c
+++ b/log.c
@@ -122,7 +122,7 @@ int init_iolog(struct thread_data *td)
                struct io_piece *ipo;
 
                if (sscanf(p, "%d,%llu,%u", &rw, &offset, &bytes) != 3) {
                struct io_piece *ipo;
 
                if (sscanf(p, "%d,%llu,%u", &rw, &offset, &bytes) != 3) {
-                       fprintf(stderr, "bad iolog: %s\n", p);
+                       fprintf(f_err, "bad iolog: %s\n", p);
                        continue;
                }
                if (rw == DDIR_READ)
                        continue;
                }
                if (rw == DDIR_READ)
@@ -130,7 +130,7 @@ int init_iolog(struct thread_data *td)
                else if (rw == DDIR_WRITE)
                        writes++;
                else {
                else if (rw == DDIR_WRITE)
                        writes++;
                else {
-                       fprintf(stderr, "bad ddir: %d\n", rw);
+                       fprintf(f_err, "bad ddir: %d\n", rw);
                        continue;
                }
 
                        continue;
                }
 
@@ -169,7 +169,7 @@ int setup_rate(struct thread_data *td)
                return 0;
 
        if (td->rate < td->ratemin) {
                return 0;
 
        if (td->rate < td->ratemin) {
-               fprintf(stderr, "min rate larger than nominal rate\n");
+               fprintf(f_err, "min rate larger than nominal rate\n");
                return -1;
        }
 
                return -1;
        }
 
diff --git a/stat.c b/stat.c
index a540304c6b1d928fc05deea96096c0ace01b91b3..cfd27ce79104dc2678e9f80680e76a46006bce27 100644 (file)
--- a/stat.c
+++ b/stat.c
@@ -233,7 +233,7 @@ void init_disk_util(struct thread_data *td)
                p = dirname(foo);
                sprintf(tmp, "%s/queue", p);
                if (stat(tmp, &st)) {
                p = dirname(foo);
                sprintf(tmp, "%s/queue", p);
                if (stat(tmp, &st)) {
-                       fprintf(stderr, "unknown sysfs layout\n");
+                       fprintf(f_err, "unknown sysfs layout\n");
                        return;
                }
                sprintf(foo, "%s", p);
                        return;
                }
                sprintf(foo, "%s", p);
@@ -287,12 +287,12 @@ static int calc_lat(struct io_stat *is, unsigned long *min, unsigned long *max,
 
 static void show_group_stats(struct group_run_stats *rs, int id)
 {
 
 static void show_group_stats(struct group_run_stats *rs, int id)
 {
-       printf("\nRun status group %d (all jobs):\n", id);
+       fprintf(f_out, "\nRun status group %d (all jobs):\n", id);
 
        if (rs->max_run[DDIR_READ])
 
        if (rs->max_run[DDIR_READ])
-               printf("   READ: io=%lluMiB, aggrb=%llu, minb=%llu, maxb=%llu, mint=%llumsec, maxt=%llumsec\n", rs->io_kb[0] >> 10, rs->agg[0], rs->min_bw[0], rs->max_bw[0], rs->min_run[0], rs->max_run[0]);
+               fprintf(f_out, "   READ: io=%lluMiB, aggrb=%llu, minb=%llu, maxb=%llu, mint=%llumsec, maxt=%llumsec\n", rs->io_kb[0] >> 10, rs->agg[0], rs->min_bw[0], rs->max_bw[0], rs->min_run[0], rs->max_run[0]);
        if (rs->max_run[DDIR_WRITE])
        if (rs->max_run[DDIR_WRITE])
-               printf("  WRITE: io=%lluMiB, aggrb=%llu, minb=%llu, maxb=%llu, mint=%llumsec, maxt=%llumsec\n", rs->io_kb[1] >> 10, rs->agg[1], rs->min_bw[1], rs->max_bw[1], rs->min_run[1], rs->max_run[1]);
+               fprintf(f_out, "  WRITE: io=%lluMiB, aggrb=%llu, minb=%llu, maxb=%llu, mint=%llumsec, maxt=%llumsec\n", rs->io_kb[1] >> 10, rs->agg[1], rs->min_bw[1], rs->max_bw[1], rs->min_run[1], rs->max_run[1]);
 }
 
 static void show_disk_util(void)
 }
 
 static void show_disk_util(void)
@@ -302,7 +302,7 @@ static void show_disk_util(void)
        struct disk_util *du;
        double util;
 
        struct disk_util *du;
        double util;
 
-       printf("\nDisk stats (read/write):\n");
+       fprintf(f_out, "\nDisk stats (read/write):\n");
 
        list_for_each(entry, &disk_list) {
                du = list_entry(entry, struct disk_util, list);
 
        list_for_each(entry, &disk_list) {
                du = list_entry(entry, struct disk_util, list);
@@ -312,7 +312,7 @@ static void show_disk_util(void)
                if (util > 100.0)
                        util = 100.0;
 
                if (util > 100.0)
                        util = 100.0;
 
-               printf("  %s: ios=%u/%u, merge=%u/%u, ticks=%u/%u, in_queue=%u, util=%3.2f%%\n", du->name, dus->ios[0], dus->ios[1], dus->merges[0], dus->merges[1], dus->ticks[0], dus->ticks[1], dus->time_in_queue, util);
+               fprintf(f_out, "  %s: ios=%u/%u, merge=%u/%u, ticks=%u/%u, in_queue=%u, util=%3.2f%%\n", du->name, dus->ios[0], dus->ios[1], dus->merges[0], dus->merges[1], dus->ticks[0], dus->ticks[1], dus->time_in_queue, util);
        }
 }
 
        }
 }
 
@@ -328,19 +328,19 @@ static void show_ddir_status(struct thread_data *td, struct group_run_stats *rs,
                return;
 
        bw = td->io_bytes[ddir] / td->runtime[ddir];
                return;
 
        bw = td->io_bytes[ddir] / td->runtime[ddir];
-       printf("  %s: io=%6lluMiB, bw=%6lluKiB/s, runt=%6lumsec\n", ddir_str[ddir], td->io_bytes[ddir] >> 20, bw, td->runtime[ddir]);
+       fprintf(f_out, "  %s: io=%6lluMiB, bw=%6lluKiB/s, runt=%6lumsec\n", ddir_str[ddir], td->io_bytes[ddir] >> 20, bw, td->runtime[ddir]);
 
        if (calc_lat(&td->slat_stat[ddir], &min, &max, &mean, &dev))
 
        if (calc_lat(&td->slat_stat[ddir], &min, &max, &mean, &dev))
-               printf("    slat (msec): min=%5lu, max=%5lu, avg=%5.02f, dev=%5.02f\n", min, max, mean, dev);
+               fprintf(f_out, "    slat (msec): min=%5lu, max=%5lu, avg=%5.02f, dev=%5.02f\n", min, max, mean, dev);
 
        if (calc_lat(&td->clat_stat[ddir], &min, &max, &mean, &dev))
 
        if (calc_lat(&td->clat_stat[ddir], &min, &max, &mean, &dev))
-               printf("    clat (msec): min=%5lu, max=%5lu, avg=%5.02f, dev=%5.02f\n", min, max, mean, dev);
+               fprintf(f_out, "    clat (msec): min=%5lu, max=%5lu, avg=%5.02f, dev=%5.02f\n", min, max, mean, dev);
 
        if (calc_lat(&td->bw_stat[ddir], &min, &max, &mean, &dev)) {
                double p_of_agg;
 
                p_of_agg = mean * 100 / (double) rs->agg[ddir];
 
        if (calc_lat(&td->bw_stat[ddir], &min, &max, &mean, &dev)) {
                double p_of_agg;
 
                p_of_agg = mean * 100 / (double) rs->agg[ddir];
-               printf("    bw (KiB/s) : min=%5lu, max=%5lu, per=%3.2f%%, avg=%5.02f, dev=%5.02f\n", min, max, p_of_agg, mean, dev);
+               fprintf(f_out, "    bw (KiB/s) : min=%5lu, max=%5lu, per=%3.2f%%, avg=%5.02f, dev=%5.02f\n", min, max, p_of_agg, mean, dev);
        }
 }
 
        }
 }
 
@@ -352,7 +352,7 @@ static void show_thread_status(struct thread_data *td,
        if (!(td->io_bytes[0] + td->io_bytes[1]) && !td->error)
                return;
 
        if (!(td->io_bytes[0] + td->io_bytes[1]) && !td->error)
                return;
 
-       printf("%s: (groupid=%d): err=%2d:\n",td->name, td->groupid, td->error);
+       fprintf(f_out, "%s: (groupid=%d): err=%2d:\n",td->name, td->groupid, td->error);
 
        show_ddir_status(td, rs, td->ddir);
        if (td->io_bytes[td->ddir ^ 1])
 
        show_ddir_status(td, rs, td->ddir);
        if (td->io_bytes[td->ddir ^ 1])
@@ -368,7 +368,7 @@ static void show_thread_status(struct thread_data *td,
                sys_cpu = 0;
        }
 
                sys_cpu = 0;
        }
 
-       printf("  cpu          : usr=%3.2f%%, sys=%3.2f%%, ctx=%lu\n", usr_cpu, sys_cpu, td->ctx);
+       fprintf(f_out, "  cpu          : usr=%3.2f%%, sys=%3.2f%%, ctx=%lu\n", usr_cpu, sys_cpu, td->ctx);
 }
 
 void show_run_stats(void)
 }
 
 void show_run_stats(void)
@@ -393,7 +393,7 @@ void show_run_stats(void)
                td = &threads[i];
 
                if (td->error) {
                td = &threads[i];
 
                if (td->error) {
-                       printf("%s: %s\n", td->name, td->verror);
+                       fprintf(f_out, "%s: %s\n", td->name, td->verror);
                        continue;
                }
 
                        continue;
                }