9d9885a35788d4249652d511a0e176f532962def
[fio.git] / profiles / tiobench.c
1 #include "../fio.h"
2 #include "../profile.h"
3 #include "../parse.h"
4 #include "../optgroup.h"
5
6 static unsigned long long size;
7 static unsigned int loops = 1;
8 static unsigned int bs = 4096;
9 static unsigned int nthreads = 1;
10 static char *dir;
11
12 static char sz_idx[80], bs_idx[80], loop_idx[80], dir_idx[80], t_idx[80];
13
14 static const char *tb_opts[] = {
15         "buffered=0", sz_idx, bs_idx, loop_idx, dir_idx, t_idx,
16         "timeout=600", "group_reporting", "thread", "overwrite=1",
17         "filename=.fio.tio.1:.fio.tio.2:.fio.tio.3:.fio.tio.4",
18         "ioengine=sync",
19         "name=seqwrite", "rw=write", "end_fsync=1",
20         "name=randwrite", "stonewall", "rw=randwrite", "end_fsync=1",
21         "name=seqread", "stonewall", "rw=read",
22         "name=randread", "stonewall", "rw=randread", NULL,
23 };
24
25 struct tiobench_options {
26         unsigned int pad;
27         unsigned long long size;
28         unsigned int loops;
29         unsigned int bs;
30         unsigned int nthreads;
31         char *dir;
32 };
33
34 static struct tiobench_options tiobench_options;
35
36 static struct fio_option options[] = {
37         {
38                 .name   = "size",
39                 .lname  = "Tiobench size",
40                 .type   = FIO_OPT_STR_VAL,
41                 .off1   = offsetof(struct tiobench_options, size),
42                 .help   = "Size in MiB",
43                 .category = FIO_OPT_C_PROFILE,
44                 .group  = FIO_OPT_G_TIOBENCH,
45         },
46         {
47                 .name   = "block",
48                 .lname  = "Tiobench block",
49                 .type   = FIO_OPT_INT,
50                 .off1   = offsetof(struct tiobench_options, bs),
51                 .help   = "Block size in bytes",
52                 .def    = "4096",
53                 .category = FIO_OPT_C_PROFILE,
54                 .group  = FIO_OPT_G_TIOBENCH,
55         },
56         {
57                 .name   = "numruns",
58                 .lname  = "Tiobench numruns",
59                 .type   = FIO_OPT_INT,
60                 .off1   = offsetof(struct tiobench_options, loops),
61                 .help   = "Number of runs",
62                 .category = FIO_OPT_C_PROFILE,
63                 .group  = FIO_OPT_G_TIOBENCH,
64         },
65         {
66                 .name   = "dir",
67                 .lname  = "Tiobench directory",
68                 .type   = FIO_OPT_STR_STORE,
69                 .off1   = offsetof(struct tiobench_options, dir),
70                 .help   = "Test directory",
71                 .category = FIO_OPT_C_PROFILE,
72                 .group  = FIO_OPT_G_TIOBENCH,
73         },
74         {
75                 .name   = "threads",
76                 .lname  = "Tiobench threads",
77                 .type   = FIO_OPT_INT,
78                 .off1   = offsetof(struct tiobench_options, nthreads),
79                 .help   = "Number of Threads",
80                 .category = FIO_OPT_C_PROFILE,
81                 .group  = FIO_OPT_G_TIOBENCH,
82         },
83         {
84                 .name   = NULL,
85         },
86 };
87
88 /*
89  * Fill our private options into the command line
90  */
91 static int tb_prep_cmdline(void)
92 {
93         /*
94          * tiobench uses size as MiB, so multiply up
95          */
96         size *= 1024 * 1024ULL;
97         if (size)
98                 sprintf(sz_idx, "size=%llu", size);
99         else
100                 strcpy(sz_idx, "size=4*1024*$mb_memory");
101
102         sprintf(bs_idx, "bs=%u", bs);
103         sprintf(loop_idx, "loops=%u", loops);
104
105         if (dir)
106                 sprintf(dir_idx, "directory=%s", dir);
107         else
108                 sprintf(dir_idx, "directory=./");
109
110         sprintf(t_idx, "numjobs=%u", nthreads);
111         return 0;
112 }
113
114 static struct profile_ops tiobench_profile = {
115         .name           = "tiobench",
116         .desc           = "tiotest/tiobench benchmark",
117         .prep_cmd       = tb_prep_cmdline,
118         .cmdline        = tb_opts,
119         .options        = options,
120         .opt_data       = &tiobench_options,
121 };
122
123 static void fio_init tiobench_register(void)
124 {
125         if (register_profile(&tiobench_profile))
126                 log_err("fio: failed to register profile 'tiobench'\n");
127 }
128
129 static void fio_exit tiobench_unregister(void)
130 {
131         unregister_profile(&tiobench_profile);
132 }