[PATCH] Enable output logging to file instead of stdout
diff --git a/init.c b/init.c
index 3117d60..b40437a 100644
--- a/init.c
+++ b/init.c
@@ -54,6 +54,8 @@
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)
{
@@ -89,13 +91,13 @@
#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) {
- fprintf(stderr, "posix aio not available\n");
+ fprintf(f_err, "posix aio not available\n");
return 1;
}
#endif
@@ -172,9 +174,9 @@
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)
- printf("...\n");
+ fprintf(f_out, "...\n");
/*
* recurse add identical jobs, clear numjobs and stonewall options
@@ -493,7 +495,7 @@
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;
}
@@ -510,7 +512,7 @@
return 0;
}
- fprintf(stderr, "fio: verify types: md5, crc32\n");
+ fprintf(f_err, "fio: verify types: md5, crc32\n");
return 1;
}
@@ -527,7 +529,7 @@
return 0;
}
- fprintf(stderr, "fio: mem type: malloc, shm, mmap\n");
+ fprintf(f_err, "fio: mem type: malloc, shm, mmap\n");
return 1;
}
@@ -560,7 +562,7 @@
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;
}
@@ -618,7 +620,7 @@
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
@@ -628,7 +630,7 @@
}
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
@@ -660,7 +662,7 @@
}
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
@@ -833,7 +835,7 @@
}
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;
}
@@ -847,7 +849,7 @@
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;
}
@@ -863,7 +865,7 @@
}
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
@@ -961,7 +963,7 @@
{
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);
@@ -995,6 +997,14 @@
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);
@@ -1006,6 +1016,10 @@
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)
@@ -1062,7 +1076,7 @@
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;
}