shared one binary for all backends
authorAndrew Tridgell <tridge@samba.org>
Fri, 25 Jul 2008 07:30:58 +0000 (17:30 +1000)
committerAndrew Tridgell <tridge@samba.org>
Fri, 25 Jul 2008 07:30:58 +0000 (17:30 +1000)
.gitignore
Makefile.in
child.c
dbench.c
dbench.h
fileio.c
nfsio.c
sockio.c

index f147ab77e231895ce03828c9240fe6fc230cdc90..7770a40b5f457b284e6d1e105e0220aee70d53fd 100644 (file)
@@ -17,4 +17,5 @@ mount_client.c
 nfs_client.c
 nfs_xdr.c
 Makefile
-
+prefix
+clients
index e5fb28931cc8090bb17fe5a52dd50ce3563604f0..45685ee3832cdda2400d566dcf141b609c773ee5 100644 (file)
@@ -17,26 +17,17 @@ EXEEXT=@EXEEXT@
 
 LIBNFS_OBJ = libnfs.o mount_client.o nfs_client.o mount_xdr.o nfs_xdr.o
 
-DB_OBJS = fileio.o util.o dbench.o child.o system.o snprintf.o
-TB_OBJS = sockio.o util.o dbench.o child.o socklib.o snprintf.o
-NFS_OBJS = nfsio.o util.o dbench.o child.o socklib.o snprintf.o libnfs.a
+DB_OBJS = fileio.o util.o dbench.o child.o system.o snprintf.o sockio.o nfsio.o libnfs.a socklib.o
 SRV_OBJS = util.o tbench_srv.o socklib.o
 
-all: dbench tbench tbench_srv nfsbench
+all: dbench tbench_srv
 
 dbench: $(DB_OBJS)
        $(CC) -o $@ $(DB_OBJS) $(LIBS)
 
-tbench: $(TB_OBJS)
-       $(CC) -o $@ $(TB_OBJS) $(LIBS)
-
 tbench_srv: $(SRV_OBJS)
        $(CC) -o $@ $(SRV_OBJS) $(LIBS)
 
-nfsbench: $(NFS_OBJS)
-       $(CC) -o $@ $(NFS_OBJS) $(LIBS)
-
-
 libnfs.a: $(LIBNFS_OBJ) 
        @echo Creating library $@
        ar r libnfs.a $(LIBNFS_OBJ) 
@@ -94,15 +85,17 @@ nfs_client.c: nfs.x
 # Careful here: don't install client.txt over itself.
 install: all
        ${INSTALLCMD} -d $(bindir) $(datadir) $(mandir)
-       ${INSTALLCMD} dbench tbench tbench_srv $(bindir)
+       ${INSTALLCMD} dbench tbench_srv $(bindir)
        ${INSTALLCMD} loadfiles/client.txt $(datadir)
        ${INSTALLCMD} loadfiles/nfs.txt $(datadir)
        ${INSTALLCMD} -m644 dbench.1 $(mandir)
        ln -sf dbench.1 $(mandir)/tbench.1
        ln -sf dbench.1 $(mandir)/tbench_srv.1
+       ln -sf $(bindir)/dbench $(bindir)/tbench 
+       ln -sf $(bindir)/dbench $(bindir)/nfsbench 
 
 clean:
-       rm -f *.o *~ dbench tbench tbench_srv libnfs.a 
+       rm -f *.[ao] *~ dbench tbench_srv
        rm -f mount.h mount_xdr.c mount_client.c
        rm -f nfs.h nfs_xdr.c nfs_client.c 
 
diff --git a/child.c b/child.c
index e6b4845ad395a75ce9a5512bd59ba3bc4aa53562..e2895c7c134075c3c7d07afe0a60e0dc99cf2cfa 100644 (file)
--- a/child.c
+++ b/child.c
@@ -116,9 +116,9 @@ static void child_op(struct child_struct *child, const char *opname,
                return;
        }
 
-       for (i=0;nb_ops.ops[i].name;i++) {
-               if (strcasecmp(op.op, nb_ops.ops[i].name) == 0) {
-                       nb_ops.ops[i].fn(&op);
+       for (i=0;nb_ops->ops[i].name;i++) {
+               if (strcasecmp(op.op, nb_ops->ops[i].name) == 0) {
+                       nb_ops->ops[i].fn(&op);
                        finish_op(child, &child->ops[i]);
                        return;
                }
@@ -245,7 +245,7 @@ done:
                child->cleanup = 1;
                fflush(stdout);
                if (!options.skip_cleanup) {
-                       nb_ops.cleanup(child);
+                       nb_ops->cleanup(child);
                }
                child->cleanup_finished = 1;
        }
index bfedb140d5cc91688851a3b9ce9ba305b0192192..a542c2f976cf7c2aecf0e1e55273029864144277 100644 (file)
--- a/dbench.c
+++ b/dbench.c
@@ -27,6 +27,7 @@
 #include <sys/sem.h>
 
 struct options options = {
+       .backend             = "fileio",
        .timelimit           = 600,
        .loadfile            = DATADIR "/client.txt",
        .directory           = ".",
@@ -49,6 +50,7 @@ static struct timeval tv_start;
 static struct timeval tv_end;
 static int barrier=-1;
 static double throughput;
+struct nb_operations *nb_ops;
 
 static FILE *open_loadfile(void)
 {
@@ -164,13 +166,13 @@ static void show_one_latency(struct op *ops, struct op *ops_all)
        int i;
        printf(" Operation                Count    AvgLat    MaxLat\n");
        printf(" --------------------------------------------------\n");
-       for (i=0;nb_ops.ops[i].name;i++) {
+       for (i=0;nb_ops->ops[i].name;i++) {
                struct op *op1, *op_all;
                op1    = &ops[i];
                op_all = &ops_all[i];
                if (op_all->count == 0) continue;
                printf(" %-22s %7u %9.03f %9.03f\n",
-                      nb_ops.ops[i].name, op1->count, 
+                      nb_ops->ops[i].name, op1->count, 
                       1000*op1->total_time/op1->count,
                       op1->max_latency*1000);
        }
@@ -185,7 +187,7 @@ static void report_latencies(void)
        struct child_struct *child;
 
        memset(sum, 0, sizeof(sum));
-       for (i=0;nb_ops.ops[i].name;i++) {
+       for (i=0;nb_ops->ops[i].name;i++) {
                op1 = &sum[i];
                for (j=0;j<options.nprocs * options.clients_per_process;j++) {
                        child = &children[j];
@@ -273,7 +275,7 @@ static void create_procs(int nprocs, void (*fn)(struct child_struct *, const cha
                        setlinebuf(stdout);
 
                        for (j=0;j<options.clients_per_process;j++) {
-                               nb_ops.setup(&children[i*options.clients_per_process + j]);
+                               nb_ops->setup(&children[i*options.clients_per_process + j]);
                        }
 
                        sbuf.sem_op = 0;
@@ -336,32 +338,15 @@ static void create_procs(int nprocs, void (*fn)(struct child_struct *, const cha
 }
 
 
-static void show_usage(void)
-{
-       printf("usage: dbench [OPTIONS] nprocs\n" \
-              "usage: tbench [OPTIONS] nprocs <server>\n" \
-              "options:\n" \
-              "  -v               show version\n" \
-              "  -t timelimit     run time in seconds (default 600)\n" \
-              "  -D directory     base directory to run in\n" \
-              "  -c loadfile      set location of the loadfile\n" \
-              "  -R               target rate (MByte/sec)\n" \
-              "  -s               synchronous file IO\n" \
-              "  -F               fsync on write\n" \
-              "  -S               synchronous directories (mkdir, unlink...)\n" \
-              "  -x               enable EA support\n" \
-              "  -T options       set socket options for tbench\n");
-       exit(1);
-}
-
 
-
-static int process_opts(int argc, const char **argv)
+static void process_opts(int argc, const char **argv)
 {
        const char **extra_argv;
        int extra_argc = 0;
        struct poptOption popt_options[] = {
                POPT_AUTOHELP
+               { "backend", 'B', POPT_ARG_STRING, &options.backend, 0, 
+                 "dbench backend (fileio, sockio, nfs)", "string" },
                { "timelimit", 't', POPT_ARG_INT, &options.timelimit, 0, 
                  "timelimit", "integer" },
                { "loadfile",  'c', POPT_ARG_STRING, &options.loadfile, 0, 
@@ -408,12 +393,13 @@ static int process_opts(int argc, const char **argv)
        pc = poptGetContext(argv[0], argc, argv, popt_options, POPT_CONTEXT_KEEP_FIRST);
 
        while ((opt = poptGetNextOpt(pc)) != -1) {
-               switch (opt) {
-               default:
-                       fprintf(stderr, "Invalid option %s: %s\n", 
-                               poptBadOption(pc, 0), poptStrerror(opt));
+               if (strcmp(poptBadOption(pc, 0), "-h") == 0) {
+                       poptPrintHelp(pc, stdout, 0);
                        exit(1);
                }
+               fprintf(stderr, "Invalid option %s: %s\n", 
+                       poptBadOption(pc, 0), poptStrerror(opt));
+               exit(1);
        }
 
        /* setup the remaining options for the main program to use */
@@ -441,8 +427,6 @@ static int process_opts(int argc, const char **argv)
        if (extra_argc >= 2) {
                options.server = extra_argv[1];
        }
-
-       return 1;
 }
 
 
@@ -457,8 +441,29 @@ static int process_opts(int argc, const char **argv)
 
        printf("dbench version %s - Copyright Andrew Tridgell 1999-2004\n\n", VERSION);
 
-       if (!process_opts(argc, argv))
-               show_usage();
+       if (strstr(argv[0], "dbench")) {
+               options.backend = "fileio";
+       } else if (strstr(argv[0], "tbench")) {
+               options.backend = "sockio";
+       } else if (strstr(argv[0], "nfsbench")) {
+               options.backend = "nfs";
+       }
+
+       process_opts(argc, argv);
+
+       if (strcmp(options.backend, "fileio") == 0) {
+               extern struct nb_operations fileio_ops;
+               nb_ops = &fileio_ops;
+       } else if (strcmp(options.backend, "sockio") == 0) {
+               extern struct nb_operations sockio_ops;
+               nb_ops = &sockio_ops;
+       } else if (strcmp(options.backend, "nfs") == 0) {
+               extern struct nb_operations nfs_ops;
+               nb_ops = &nfs_ops;
+       } else {
+               printf("Unknown backend '%s'\n", options.backend);
+               exit(1);
+       }
 
        if (options.warmup == -1) {
                options.warmup = options.timelimit / 5;
index c9aada6841fc034acdb21171031088b4ca2e3e27..8ea69ad981e47eb7254b03ff5bdcdd2bcf9250e9 100644 (file)
--- a/dbench.h
+++ b/dbench.h
@@ -127,6 +127,7 @@ struct child_struct {
 };
 
 struct options {
+       const char *backend;
        int nprocs;
        int sync_open;
        int sync_dirs;
@@ -172,7 +173,7 @@ struct nb_operations {
        void (*setup)(struct child_struct *child);
        void (*cleanup)(struct child_struct *child);
 };
-extern struct nb_operations nb_ops;
+extern struct nb_operations *nb_ops;
 
 /* CreateDisposition field. */
 #define FILE_SUPERSEDE 0
index d67a1e1620a110469c2d0d33d7328928eecbed4c..9b3159edfb2a4710e9922cef524beb268ae7120e 100644 (file)
--- a/fileio.c
+++ b/fileio.c
@@ -642,7 +642,7 @@ static struct backend_op ops[] = {
        { NULL, NULL}
 };
 
-struct nb_operations nb_ops = {
+struct nb_operations fileio_ops = {
        .backend_name = "dbench",
        .setup          = fio_setup,
        .cleanup        = fio_cleanup,
diff --git a/nfsio.c b/nfsio.c
index c95f8c3519edff1db34add82cde1aba6fc7e6317..497d4d3e96f914287906640690a0bb6617fa846e 100644 (file)
--- a/nfsio.c
+++ b/nfsio.c
@@ -401,7 +401,7 @@ static struct backend_op ops[] = {
        { NULL, NULL}
 };
 
-struct nb_operations nb_ops = {
+struct nb_operations nfs_ops = {
        .backend_name = "nfsbench",
        .setup        = nfs3_setup,
        .cleanup      = nfs3_cleanup,
index 16c19447312391805035d25c9d37ed36d55b4ec3..6eb9e0f771bc6d85aa10f2f2a80c3281db16e858 100644 (file)
--- a/sockio.c
+++ b/sockio.c
@@ -200,7 +200,7 @@ static struct backend_op ops[] = {
        { NULL, NULL}
 };
 
-struct nb_operations nb_ops = {
+struct nb_operations sockio_ops = {
        .backend_name = "tbench",
        .setup        = sio_setup,
        .cleanup      = sio_cleanup,