Make the dprint() processing out-of-line
authorJens Axboe <jens.axboe@oracle.com>
Fri, 19 Mar 2010 15:41:52 +0000 (16:41 +0100)
committerJens Axboe <jens.axboe@oracle.com>
Fri, 19 Mar 2010 15:41:52 +0000 (16:41 +0100)
Instead of having the big macro inlined everywhere, only
inline the mask check and put the rest out-of-line. This reduces
the size of fio with 4% here, and speeds it up.

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

index ce2374b62c9ad89777f983ecc30166be0f16181f..12042f4a92683a38cdf0cd62cbba27e7a198ba6f 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -7,7 +7,7 @@ SCRIPTS = fio_generate_plots
 OBJS = gettime.o fio.o ioengines.o init.o stat.o log.o time.o filesetup.o \
        eta.o verify.o memory.o io_u.o parse.o mutex.o options.o \
        rbtree.o diskutil.o fifo.o blktrace.o smalloc.o filehash.o helpers.o \
 OBJS = gettime.o fio.o ioengines.o init.o stat.o log.o time.o filesetup.o \
        eta.o verify.o memory.o io_u.o parse.o mutex.o options.o \
        rbtree.o diskutil.o fifo.o blktrace.o smalloc.o filehash.o helpers.o \
-       cgroup.o profile.o
+       cgroup.o profile.o debug.o
 
 OBJS += crc/crc7.o
 OBJS += crc/crc16.o
 
 OBJS += crc/crc7.o
 OBJS += crc/crc16.o
diff --git a/debug.c b/debug.c
new file mode 100644 (file)
index 0000000..2eb3b6f
--- /dev/null
+++ b/debug.c
@@ -0,0 +1,27 @@
+#include <stdarg.h>
+#include <sys/types.h>
+#include <unistd.h>
+#include "debug.h"
+
+void __dprint(int type, const char *str, ...)
+{
+       va_list args;
+       pid_t pid;
+
+       assert(type < FD_DEBUG_MAX);
+
+       if ((((1 << type)) & fio_debug) == 0)
+               return;
+
+       pid = getpid();
+       if (fio_debug_jobp && *fio_debug_jobp != -1U
+           && pid != *fio_debug_jobp)
+               return;
+
+       log_info("%-8s ", debug_levels[(type)].name);
+       log_info("%-5u ", (int) pid);
+
+       va_start(args, str);
+       vfprintf(f_out, str, args);
+       va_end(args);
+}
diff --git a/debug.h b/debug.h
index 891c254ebcf35e596904577e62f5965b231916f4..e51d8b202ab5318fa128346c47fd97833df60bf0 100644 (file)
--- a/debug.h
+++ b/debug.h
@@ -32,24 +32,20 @@ extern struct debug_level debug_levels[];
 
 extern unsigned long fio_debug;
 
 
 extern unsigned long fio_debug;
 
-#define dprint(type, str, args...)                             \
-       do {                                                    \
-               pid_t __pid;                                    \
-               assert(type < FD_DEBUG_MAX);                    \
-               if ((((1 << type)) & fio_debug) == 0)           \
-                       break;                                  \
-               __pid = getpid();                               \
-               if (fio_debug_jobp && *fio_debug_jobp != -1U    \
-                   && __pid != *fio_debug_jobp)                \
-                       break;                                  \
-               log_info("%-8s ", debug_levels[(type)].name);   \
-               log_info("%-5u ", (int) __pid);                 \
-               log_info(str, ##args);                          \
-       } while (0)
+void __dprint(int type, const char *str, ...);
+
+#define dprint(type, str, args...)                     \
+       do {                                            \
+               if ((((1 << type)) & fio_debug) == 0)   \
+                       break;                          \
+               __dprint((type), (str), ##args);        \
+       } while (0)                                     \
 
 #else
 
 
 #else
 
-#define dprint(type, str, args...)
+static inline void dprint(int type, const char *str, ...)
+{
+}
 #endif
 
 #endif
 #endif
 
 #endif
diff --git a/log.h b/log.h
index 12c9a55242df84570adf16c5ef06d551ff8a303b..5ca37b391a454cbc29a2992ab5bc9b382a328b99 100644 (file)
--- a/log.h
+++ b/log.h
@@ -1,6 +1,8 @@
 #ifndef FIO_LOG_H
 #define FIO_LOG_H
 
 #ifndef FIO_LOG_H
 #define FIO_LOG_H
 
+#include <stdio.h>
+
 extern FILE *f_out;
 extern FILE *f_err;
 
 extern FILE *f_out;
 extern FILE *f_err;