backend: Logging exec_{pre|post}run
authorErwan Velu <erwan@enovance.com>
Wed, 17 Jul 2013 21:04:46 +0000 (23:04 +0200)
committerErwan Velu <erwan@enovance.com>
Wed, 17 Jul 2013 21:16:31 +0000 (23:16 +0200)
When using the exec_{pre|post}run option in fio jobs, it's very
important being able to read the output of thoses commands later.

As the output could be very verbose, let's log all the output of the
command in separate file.

As an example, when running two jobs called "write" and "read" the
exec_prerun option is used. During fio's execution, the following
message will be shown :
write : Saving output of prerun in write.prerun.txt
read : Saving output of prerun in read.prerun.txt

The output filename is so composed of the job name appended with the pre
or post run name and a final .txt extension.

That's pretty simple and shall do the job.

backend.c
fio.1

index c2fa34ccc7731fb3c11c280d7f887c00cd6e36d0..b9c1c1230585cc41b2a78eb8e218ebe58e6d87ea 100644 (file)
--- a/backend.c
+++ b/backend.c
@@ -1086,14 +1086,15 @@ static int keep_running(struct thread_data *td)
        return 0;
 }
 
-static int exec_string(const char *string)
+static int exec_string(struct thread_options *o, const char *string, const char *mode)
 {
-       int ret, newlen = strlen(string) + 1 + 2;
+       int ret, newlen = strlen(string) + strlen(o->name) + strlen(mode) + 9 + 1;
        char *str;
 
        str = malloc(newlen);
-       sprintf(str, "%s", string);
+       sprintf(str, "%s &> %s.%s.txt", string, o->name, mode);
 
+       log_info("%s : Saving output of %s in %s.%s.txt\n",o->name, mode, o->name, mode);
        ret = system(str);
        if (ret == -1)
                log_err("fio: exec of cmd <%s> failed\n", str);
@@ -1274,7 +1275,7 @@ static void *thread_main(void *data)
        if (init_random_map(td))
                goto err;
 
-       if (o->exec_prerun && exec_string(o->exec_prerun))
+       if (o->exec_prerun && exec_string(o, o->exec_prerun, (const char *)"prerun"))
                goto err;
 
        if (o->pre_read) {
@@ -1397,7 +1398,7 @@ static void *thread_main(void *data)
 
        fio_mutex_up(writeout_mutex);
        if (o->exec_postrun)
-               exec_string(o->exec_postrun);
+               exec_string(o, o->exec_postrun, (const char *)"postrun");
 
        if (exitall_on_terminate)
                fio_terminate_threads(td->groupid);
diff --git a/fio.1 b/fio.1
index 91020b2eeb89a4b5b3d4da3f9ff7f2aa87f668c0..91fd5311afe6f1166a2be31109470661465ef576 100644 (file)
--- a/fio.1
+++ b/fio.1
@@ -1061,9 +1061,15 @@ simulate a smaller amount of memory. The amount specified is per worker.
 .TP
 .BI exec_prerun \fR=\fPstr
 Before running the job, execute the specified command with \fBsystem\fR\|(3).
+.RS
+Output is redirected in a file called \fBjobname.prerun.txt\fR
+.RE
 .TP
 .BI exec_postrun \fR=\fPstr
 Same as \fBexec_prerun\fR, but the command is executed after the job completes.
+.RS
+Output is redirected in a file called \fBjobname.postrun.txt\fR
+.RE
 .TP
 .BI ioscheduler \fR=\fPstr
 Attempt to switch the device hosting the file to the specified I/O scheduler.