Motr  M0
m0ub.c
Go to the documentation of this file.
1 /* -*- C -*- */
2 /*
3  * Copyright (c) 2013-2021 Seagate Technology LLC and/or its Affiliates
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  * For any questions about this software or licensing,
18  * please email opensource@seagate.com or cortx-questions@seagate.com.
19  *
20  */
21 
22 
23 #include "lib/string.h" /* m0_strdup */
24 #include "lib/memory.h"
25 #include "lib/thread.h" /* LAMBDA */
26 #include "lib/getopts.h"
27 #include "lib/ub.h"
28 #include "ut/ut.h" /* m0_ut_init */
29 #include "ut/module.h" /* m0_ut_module */
30 #include "module/instance.h" /* m0 */
31 
32 extern struct m0_ub_set m0_ad_ub;
33 extern struct m0_ub_set m0_adieu_ub;
34 extern struct m0_ub_set m0_atomic_ub;
35 extern struct m0_ub_set m0_bitmap_ub;
36 extern struct m0_ub_set m0_fol_ub;
37 extern struct m0_ub_set m0_fom_ub;
38 extern struct m0_ub_set m0_list_ub;
39 extern struct m0_ub_set m0_memory_ub;
40 extern struct m0_ub_set m0_parity_math_ub;
41 extern struct m0_ub_set m0_parity_math_mt_ub;
42 //extern struct m0_ub_set m0_rpc_ub;
43 extern struct m0_ub_set m0_thread_ub;
44 extern struct m0_ub_set m0_time_ub;
45 extern struct m0_ub_set m0_timer_ub;
46 extern struct m0_ub_set m0_tlist_ub;
47 extern struct m0_ub_set m0_trace_ub;
48 extern struct m0_ub_set m0_varr_ub;
49 
50 #define UB_SANDBOX "./ub-sandbox"
51 
52 struct ub_args {
53  uint32_t ua_rounds;
54  char *ua_name;
55  char *ua_opts;
56  bool ua_ub_list;
57 };
58 
59 static void ub_args_fini(struct ub_args *args)
60 {
61  m0_free(args->ua_opts);
62  m0_free(args->ua_name);
63 }
64 
65 static int ub_args_parse(int argc, char *argv[], struct ub_args *out)
66 {
67  out->ua_rounds = 1;
68  out->ua_name = NULL;
69  out->ua_opts = NULL;
70  out->ua_ub_list = false;
71 
72  return M0_GETOPTS("ub", argc, argv,
73  M0_HELPARG('h'),
74  M0_VOIDARG('l', "List available benchmarks and exit",
75  LAMBDA(void, (void) {
76  out->ua_ub_list = true;
77  })),
78  M0_NUMBERARG('r', "Number of rounds a benchmark has to run",
79  LAMBDA(void, (int64_t rounds) {
80  out->ua_rounds = rounds;
81  })),
82  M0_STRINGARG('t', "Benchmark to run",
83  LAMBDA(void, (const char *str) {
84  out->ua_name = m0_strdup(str);
85  })),
86  M0_STRINGARG('o', "Optional parameters (ignored by most"
87  " benchmarks)",
88  LAMBDA(void, (const char *str) {
89  out->ua_opts = m0_strdup(str);
90  }))
91  );
92 }
93 
94 static void ub_add(const struct ub_args *args)
95 {
96  /*
97  * Please maintain _reversed_ sorting order.
98  *
99  * These benchmarks are executed in reverse order from the way
100  * they are listed here.
101  */
108 // m0_ub_set_add(&m0_rpc_ub);
115 //XXX_BE_DB m0_ub_set_add(&m0_bitmap_ub);
116 //XXX_BE_DB m0_ub_set_add(&m0_atomic_ub);
119 }
120 
121 static int ub_run(const struct ub_args *args)
122 {
123  int rc = 0;
124 
125  M0_PRE(!args->ua_ub_list);
126 
127  if (args->ua_name != NULL)
128  rc = m0_ub_set_select(args->ua_name);
129 
130  return rc ?: m0_ub_run(args->ua_rounds, args->ua_opts);
131 }
132 
133 int main(int argc, char *argv[])
134 {
135  static struct m0 instance;
136  struct ub_args args;
137  int rc;
138 
141 
142  ((struct m0_ut_module *)instance.i_moddata[M0_MODULE_UT])->ut_sandbox =
143  UB_SANDBOX;
144 
145  rc = m0_ut_init(&instance);
146  if (rc != 0)
147  return rc;
148 
149  rc = ub_args_parse(argc, argv, &args);
150  if (rc == 0) {
151  ub_add(&args);
152 
153  if (args.ua_ub_list)
154  m0_ub_set_print();
155  else
156  rc = ub_run(&args);
157  }
158  ub_args_fini(&args);
159  m0_ut_fini();
160 
161  return rc;
162 }
163 
164 /*
165  * Local variables:
166  * c-indentation-style: "K&R"
167  * c-basic-offset: 8
168  * tab-width: 8
169  * fill-column: 80
170  * scroll-step: 1
171  * End:
172  */
#define M0_GETOPTS(progname, argc, argv,...)
Definition: getopts.h:169
struct m0_ub_set m0_memory_ub
Definition: memory.c:117
#define M0_PRE(cond)
#define m0_strdup(s)
Definition: string.h:43
struct m0_ub_set m0_parity_math_mt_ub
#define NULL
Definition: misc.h:38
struct m0_ub_set m0_ad_ub
Definition: ad.c:648
struct m0_ub_set m0_time_ub
Definition: time.c:244
static int ub_run(const struct ub_args *args)
Definition: m0ub.c:121
struct m0_ub_set m0_bitmap_ub
Definition: bitmap.c:187
static void ub_add(const struct ub_args *args)
Definition: m0ub.c:94
M0_INTERNAL void m0_instance_setup(struct m0 *instance)
Definition: instance.c:110
struct m0_ub_set m0_adieu_ub
Definition: adieu.c:398
Definition: ub.c:49
struct m0_ub_set m0_atomic_ub
Definition: atomic.c:266
struct m0_module *(* mt_create)(struct m0 *instance)
Definition: module.h:199
#define M0_VOIDARG(ch, desc, func)
Definition: getopts.h:177
#define M0_NUMBERARG(ch, desc, func)
Definition: getopts.h:187
M0_INTERNAL void m0_ut_fini(void)
Definition: ut.c:95
char * ua_opts
Definition: m0ub.c:55
#define M0_STRINGARG(ch, desc, func)
Definition: getopts.h:207
#define LAMBDA(T,...)
Definition: thread.h:153
struct m0_ub_set m0_trace_ub
Definition: trace.c:97
M0_INTERNAL int m0_ub_run(uint32_t rounds, const char *opts)
Definition: ub.c:182
M0_INTERNAL int m0_ut_init(struct m0 *instance)
Definition: ut.c:64
struct m0_ub_set m0_fom_ub
Definition: ub.c:474
struct m0_ub_set m0_timer_ub
Definition: timer.c:737
Definition: instance.h:80
int main(int argc, char *argv[])
Definition: m0ub.c:133
struct m0_ub_set m0_varr_ub
Definition: varr.c:421
char * ua_name
Definition: m0ub.c:54
static void ub_args_fini(struct ub_args *args)
Definition: m0ub.c:59
const struct m0_module_type m0_ut_module_type
Definition: module.c:37
Definition: m0ub.c:52
M0_INTERNAL int m0_ub_set_select(const char *name)
Definition: ub.c:54
#define UB_SANDBOX
Definition: m0ub.c:50
M0_INTERNAL void m0_ub_set_print(void)
Definition: ub.c:45
struct m0_ub_set m0_thread_ub
Definition: thread.c:223
void * i_moddata[M0_MODULE_NR]
Definition: instance.h:94
#define M0_HELPARG(ch)
Definition: getopts.h:242
static struct m0 instance
Definition: main.c:78
uint32_t ua_rounds
Definition: m0ub.c:53
struct m0_ub_set m0_list_ub
Definition: list.c:175
#define out(...)
Definition: gen.c:41
void m0_free(void *data)
Definition: memory.c:146
int32_t rc
Definition: trigger_fop.h:47
struct m0_ub_set m0_fol_ub
Definition: fol.c:220
bool ua_ub_list
Definition: m0ub.c:56
struct m0_ub_set m0_parity_math_ub
static int ub_args_parse(int argc, char *argv[], struct ub_args *out)
Definition: m0ub.c:65
Definition: ub.h:74
M0_INTERNAL void m0_ub_set_add(struct m0_ub_set *set)
Definition: ub.c:69
struct m0_ub_set m0_tlist_ub
Definition: tlist.c:333