Add a '--showcmd' option for dumping a job file
authorJens Axboe <jens.axboe@oracle.com>
Wed, 4 Apr 2007 09:09:19 +0000 (11:09 +0200)
committerJens Axboe <jens.axboe@oracle.com>
Wed, 4 Apr 2007 09:09:19 +0000 (11:09 +0200)
It effectively shows what the equivelant command line string would be.

Signed-off-by: Jens Axboe <jens.axboe@oracle.com>
README
init.c

diff --git a/README b/README
index 8b55f31400d4fadcc05e1fd55e342df4e89a68b3..6b23d7c5e1b3c52c43c7bb076348c1800e28f592 100644 (file)
--- a/README
+++ b/README
@@ -65,6 +65,7 @@ $ fio
         --version       Print version info and exit
        --help          Print this page
        --cmdhelp=cmd   Print command help, "all" for all of them
+       --showcmd       Turn a job file into command line options
 
 Any parameters following the options will be assumed to be job files,
 unless they match a job file parameter. You can add as many as you want,
diff --git a/init.c b/init.c
index 50c476012d374014b843eff27560f629ae6c9f97..0151c9bd4b2979626e17c592c76938c9e2b68b35 100644 (file)
--- a/init.c
+++ b/init.c
@@ -23,6 +23,7 @@ static char fio_version_string[] = "fio 1.15.1";
 
 static char **ini_file;
 static int max_jobs = MAX_JOBS;
+static int dump_cmdline;
 
 struct thread_data def_thread;
 struct thread_data *threads = NULL;
@@ -85,6 +86,11 @@ static struct option long_options[FIO_NR_OPTIONS] = {
                .has_arg        = optional_argument,
                .val            = 'c',
        },
+       {
+               .name           = "showcmd",
+               .has_arg        = no_argument,
+               .val            = 's'
+       },
        {
                .name           = NULL,
        },
@@ -381,6 +387,14 @@ static int add_job(struct thread_data *td, const char *jobname, int job_add_num)
        if (td == &def_thread)
                return 0;
 
+       /*
+        * if we are just dumping the output command line, don't add the job
+        */
+       if (dump_cmdline) {
+               put_job(td);
+               return 0;
+       }
+
        engine = get_engine_name(td->o.ioengine);
        td->io_ops = load_ioengine(td, engine);
        if (!td->io_ops) {
@@ -560,6 +574,12 @@ static int parse_jobs_ini(char *file, int stonewall_flag)
 
                name[strlen(name) - 1] = '\0';
 
+               if (dump_cmdline) {
+                       log_info("fio ");
+                       if (!global)
+                               log_info("--name=%s ", name);
+               }
+
                td = get_new_job(global, &def_thread);
                if (!td) {
                        ret = 1;
@@ -594,6 +614,8 @@ static int parse_jobs_ini(char *file, int stonewall_flag)
                         * easier on the user.
                         */
                        ret |= fio_option_parse(td, p);
+                       if (!ret && dump_cmdline)
+                               log_info("--%s ", p);
                }
 
                if (!ret) {
@@ -605,6 +627,9 @@ static int parse_jobs_ini(char *file, int stonewall_flag)
                }
        } while (!ret);
 
+       if (dump_cmdline)
+               log_info("\n");
+
        free(string);
        free(name);
        fclose(f);
@@ -696,6 +721,7 @@ static void usage(void)
        printf("\t--version\tPrint version info and exit\n");
        printf("\t--help\t\tPrint this page\n");
        printf("\t--cmdhelp=cmd\tPrint command help, \"all\" for all of them\n");
+       printf("\t--showcmd\tTurn a job file into command line options\n");
 }
 
 static int parse_cmd_line(int argc, char *argv[])
@@ -730,6 +756,9 @@ static int parse_cmd_line(int argc, char *argv[])
                        exit(0);
                case 'c':
                        exit(fio_show_option_help(optarg));
+               case 's':
+                       dump_cmdline = 1;
+                       break;
                case 'v':
                        printf("%s\n", fio_version_string);
                        exit(0);
@@ -812,6 +841,9 @@ int parse_options(int argc, char *argv[])
        options_mem_free(&def_thread);
 
        if (!thread_number) {
+               if (dump_cmdline)
+                       return 0;
+
                log_err("No jobs defined(s)\n");
                return 1;
        }