Add --debug=parse for option parsing debug
authorJens Axboe <jens.axboe@oracle.com>
Wed, 27 Feb 2008 17:32:33 +0000 (18:32 +0100)
committerJens Axboe <jens.axboe@oracle.com>
Wed, 27 Feb 2008 17:32:33 +0000 (18:32 +0100)
Adds log.h and debug.h to split the logging and debug bits out of
fio, so that the parser can use them.

Signed-off-by: Jens Axboe <jens.axboe@oracle.com>
README
debug.h [new file with mode: 0644]
fio.h
init.c
log.h [new file with mode: 0644]
parse.c

diff --git a/README b/README
index cf48c018d66f45c4271020dc66b572254d6f468f..ef614a28f250bc424c0b3c36f1e4ba95a003568c 100644 (file)
--- a/README
+++ b/README
@@ -100,6 +100,7 @@ options in fio. Currently the options are:
        verify          Dump info related to IO verification
        all             Enable all debug options
        random          Dump info related to random offset generation
+       parse           Dump info related to option matching and parsing
        ? or help       Show available debug options.
 
 You can specify as many as you want, eg --debug=file,mem will enable
diff --git a/debug.h b/debug.h
new file mode 100644 (file)
index 0000000..b11a901
--- /dev/null
+++ b/debug.h
@@ -0,0 +1,42 @@
+#ifndef FIO_DEBUG_H
+#define FIO_DEBUG_H
+
+#include <assert.h>
+#include "log.h"
+
+enum {
+       FD_PROCESS      = 0,
+       FD_FILE,
+       FD_IO,
+       FD_MEM,
+       FD_BLKTRACE,
+       FD_VERIFY,
+       FD_RANDOM,
+       FD_PARSE,
+       FD_DEBUG_MAX,
+};
+
+#ifdef FIO_INC_DEBUG
+struct debug_level {
+       const char *name;
+       unsigned long shift;
+};
+extern struct debug_level debug_levels[];
+
+extern unsigned long fio_debug;
+
+#define dprint(type, str, args...)                             \
+       do {                                                    \
+               assert(type < FD_DEBUG_MAX);                    \
+               if ((((1 << type)) & fio_debug) == 0)           \
+                       break;                                  \
+               log_info("%-8s ", debug_levels[(type)].name);   \
+               log_info(str, ##args);                          \
+       } while (0)
+
+#else
+
+#define dprint(type, str, args...)
+#endif
+
+#endif
diff --git a/fio.h b/fio.h
index 028ef4cb9ec2e79b0296639a2ddc69b2bfdd24a1..0c5b64874cdd81e3d96dadcf56443cd7392e6923 100644 (file)
--- a/fio.h
+++ b/fio.h
@@ -22,6 +22,8 @@
 #include "arch/arch.h"
 #include "os/os.h"
 #include "mutex.h"
+#include "log.h"
+#include "debug.h"
 
 #ifdef FIO_HAVE_GUASI
 #include <guasi.h>
@@ -659,8 +661,6 @@ extern int nr_process, nr_thread;
 extern int shm_id;
 extern int groupid;
 extern int terse_output;
-extern FILE *f_out;
-extern FILE *f_err;
 extern int temp_stall_ts;
 extern unsigned long long mlock_size;
 extern unsigned long page_mask, page_size;
@@ -903,20 +903,6 @@ extern int is_blktrace(const char *);
 extern int load_blktrace(struct thread_data *, const char *);
 #endif
 
-/*
- * If logging output to a file, stderr should go to both stderr and f_err
- */
-#define log_err(args...)       do {            \
-       fprintf(f_err, ##args);                 \
-       if (f_err != stderr)                    \
-               fprintf(stderr, ##args);        \
-       } while (0)
-
-#define log_info(args...)      fprintf(f_out, ##args)
-
-FILE *get_f_out(void);
-FILE *get_f_err(void);
-
 struct ioengine_ops {
        struct list_head list;
        char name[16];
@@ -972,35 +958,7 @@ static inline void clear_error(struct thread_data *td)
        td->verror[0] = '\0';
 }
 
-enum {
-       FD_PROCESS      = 0,
-       FD_FILE,
-       FD_IO,
-       FD_MEM,
-       FD_BLKTRACE,
-       FD_VERIFY,
-       FD_RANDOM,
-       FD_DEBUG_MAX,
-};
-
 #ifdef FIO_INC_DEBUG
-struct debug_level {
-       const char *name;
-       unsigned long shift;
-};
-extern struct debug_level debug_levels[];
-
-extern unsigned long fio_debug;
-
-#define dprint(type, str, args...)                             \
-       do {                                                    \
-               assert(type < FD_DEBUG_MAX);                    \
-               if ((((1 << type)) & fio_debug) == 0)           \
-                       break;                                  \
-               log_info("%-8s ", debug_levels[(type)].name);   \
-               log_info(str, ##args);                          \
-       } while (0)
-
 static inline void dprint_io_u(struct io_u *io_u, const char *p)
 {
        struct fio_file *f = io_u->file;
@@ -1015,7 +973,6 @@ static inline void dprint_io_u(struct io_u *io_u, const char *p)
        }
 }
 #else
-#define dprint(type, str, args...)
 #define dprint_io_u(io_u, p)
 #endif
 
diff --git a/init.c b/init.c
index 4f57ba31705e151f44859ce80109d3fb1c3a110e..659972976c444aabaf456965ad5b5022fa92fb89 100644 (file)
--- a/init.c
+++ b/init.c
@@ -812,6 +812,7 @@ struct debug_level debug_levels[] = {
        { .name = "blktrace",   .shift = FD_BLKTRACE },
        { .name = "verify",     .shift = FD_VERIFY },
        { .name = "random",     .shift = FD_RANDOM },
+       { .name = "parse",      .shift = FD_PARSE },
        { },
 };
 
diff --git a/log.h b/log.h
new file mode 100644 (file)
index 0000000..12c9a55
--- /dev/null
+++ b/log.h
@@ -0,0 +1,21 @@
+#ifndef FIO_LOG_H
+#define FIO_LOG_H
+
+extern FILE *f_out;
+extern FILE *f_err;
+
+/*
+ * If logging output to a file, stderr should go to both stderr and f_err
+ */
+#define log_err(args...)       do {            \
+       fprintf(f_err, ##args);                 \
+       if (f_err != stderr)                    \
+               fprintf(stderr, ##args);        \
+       } while (0)
+
+#define log_info(args...)      fprintf(f_out, ##args)
+
+FILE *get_f_out(void);
+FILE *get_f_err(void);
+
+#endif
diff --git a/parse.c b/parse.c
index 90874f1642c792917d4081b73362199337e627b3..3c203121711dcb9595bea3b1b6e517dad3d76abb 100644 (file)
--- a/parse.c
+++ b/parse.c
@@ -10,6 +10,7 @@
 #include <limits.h>
 
 #include "parse.h"
+#include "debug.h"
 
 static int vp_cmp(const void *p1, const void *p2)
 {
@@ -229,6 +230,9 @@ static int __handle_option(struct fio_option *o, const char *ptr, void *data,
        char **cp;
        int ret = 0, is_time = 0;
 
+       dprint(FD_PARSE, "__handle_option=%s, type=%d, ptr=%s\n", o->name,
+                                                       o->type, ptr);
+
        if (!ptr && o->type != FIO_OPT_STR_SET) {
                fprintf(stderr, "Option %s requires an argument\n", o->name);
                return 1;
@@ -414,6 +418,8 @@ static int handle_option(struct fio_option *o, const char *ptr, void *data)
        const char *ptr2 = NULL;
        int r1, r2;
 
+       dprint(FD_PARSE, "handle_option=%s, ptr=%s\n", o->name, ptr);
+
        /*
         * See if we have a second set of parameters, hidden after a comma.
         * Do this before parsing the first round, to check if we should
@@ -661,6 +667,8 @@ void fill_default_options(void *data, struct fio_option *options)
 {
        struct fio_option *o;
 
+       dprint(FD_PARSE, "filling default options\n");
+
        for (o = &options[0]; o->name; o++)
                if (o->def)
                        handle_option(o, o->def, data);
@@ -674,6 +682,8 @@ void options_init(struct fio_option *options)
 {
        struct fio_option *o;
 
+       dprint(FD_PARSE, "init options\n");
+
        for (o = &options[0]; o->name; o++) {
                if (o->type == FIO_OPT_BOOL) {
                        o->minval = 0;