|
35 | 35 | #include "runtime/etcd/etcd_rt.h" |
36 | 36 | #include "utils/utils.h" |
37 | 37 |
|
| 38 | +enum xferBenchParamType |
| 39 | +{ |
| 40 | + XBPT_STRING, |
| 41 | + XBPT_BOOL, |
| 42 | + XBPT_UINT64, |
| 43 | + XBPT_INT32, |
| 44 | + __XBPT_LAST |
| 45 | +}; |
| 46 | + |
| 47 | +struct xferBenchParamInfo |
| 48 | +{ |
| 49 | + const char *name; |
| 50 | + const char *help; |
| 51 | + xferBenchParamType type; |
| 52 | + union { |
| 53 | + const char *str; |
| 54 | + bool b; |
| 55 | + uint64_t u64; |
| 56 | + int32_t i32; |
| 57 | + } def_value; |
| 58 | +}; |
| 59 | + |
38 | 60 | // Define gflags params |
39 | 61 | #define NB_ARG_STRING(param_name, def_val, help_text) \ |
40 | | - DEFINE_string(param_name, def_val, help_text); |
| 62 | + { .name = # param_name, .help = help_text, .type = XBPT_STRING, .def_value = { .str = def_val } }, |
41 | 63 | #define NB_ARG_BOOL(param_name, def_val, help_text) \ |
42 | | - DEFINE_bool(param_name, def_val, help_text); |
| 64 | + { .name = # param_name, .help = help_text, .type = XBPT_BOOL, .def_value = { .b = def_val } }, |
43 | 65 | #define NB_ARG_UINT64(param_name, def_val, help_text) \ |
44 | | - DEFINE_uint64(param_name, def_val, help_text); |
| 66 | + { .name = # param_name, .help = help_text, .type = XBPT_UINT64, .def_value = { .u64 = def_val} }, |
45 | 67 | #define NB_ARG_INT32(param_name, def_val, help_text) \ |
46 | | - DEFINE_int32(param_name, def_val, help_text); |
| 68 | + { .name = # param_name, .help = help_text, .type = XBPT_INT32, .def_value = { .i32 = def_val } }, |
47 | 69 |
|
48 | 70 | /********** |
49 | 71 | * xferBench Config |
50 | 72 | **********/ |
| 73 | +const xferBenchParamInfo xbench_params[] = { |
51 | 74 | NB_ARG_STRING(benchmark_group, "default", \ |
52 | 75 | "Name of benchmark group. Use different names to run multiple benchmarks in parallel " \ |
53 | 76 | "(Default: default)") |
@@ -135,6 +158,7 @@ NB_ARG_STRING(gusli_device_security, "", \ |
135 | 158 | "If empty or fewer than devices, uses 'sec=0x3' as default. " \ |
136 | 159 | "For GUSLI backend, use device_list in format 'id:type:path' where type is F (file) " \ |
137 | 160 | "or K (kernel device).") |
| 161 | +}; |
138 | 162 |
|
139 | 163 | #undef NB_ARG_INT32 |
140 | 164 | #undef NB_ARG_UINT64 |
@@ -196,9 +220,52 @@ uint64_t xferBenchConfig::gusli_bdev_byte_offset = 0; |
196 | 220 | std::string xferBenchConfig::gusli_device_security = ""; |
197 | 221 |
|
198 | 222 | int |
199 | | -xferBenchConfig::loadFromFlags() { |
| 223 | +xferBenchConfig::parseConfig(int argc, char *argv[]) |
| 224 | +{ |
| 225 | + cxxopts::Options options("nixlbench", "NIXL Benchmark Tool"); |
| 226 | + |
| 227 | + options.add_options() |
| 228 | + ("help", "Print usage"); |
| 229 | + |
| 230 | + for (size_t i = 0; i < sizeof(xbench_params) / sizeof(xbench_params[0]); i++) { |
| 231 | + const xferBenchParamInfo *param = &xbench_params[i]; |
| 232 | + |
| 233 | + switch (param->type) { |
| 234 | + case XBPT_STRING: |
| 235 | + options.add_options() |
| 236 | + (param->name, param->help, cxxopts::value<std::string>()->default_value(param->def_value.str)); |
| 237 | + break; |
| 238 | + case XBPT_BOOL: |
| 239 | + options.add_options() |
| 240 | + (param->name, param->help, cxxopts::value<bool>()->default_value(param->def_value.b ? "true" : "false")); |
| 241 | + break; |
| 242 | + case XBPT_UINT64: |
| 243 | + options.add_options() |
| 244 | + (param->name, param->help, cxxopts::value<uint64_t>()->default_value(std::to_string(param->def_value.u64))); |
| 245 | + break; |
| 246 | + case XBPT_INT32: |
| 247 | + options.add_options() |
| 248 | + (param->name, param->help, cxxopts::value<int32_t>()->default_value(std::to_string(param->def_value.i32))); |
| 249 | + break; |
| 250 | + default: |
| 251 | + std::cerr << param->name << ": unsupported param type: " << param->type << std::endl; |
| 252 | + return -1; |
| 253 | + } |
| 254 | + } |
| 255 | + |
| 256 | + auto result = options.parse(argc, argv); |
| 257 | + if (result.count("help")) { |
| 258 | + std::cout << options.help() << std::endl; |
| 259 | + return -1; |
| 260 | + } |
| 261 | + |
| 262 | + return loadParams(result); |
| 263 | +} |
| 264 | + |
| 265 | +int |
| 266 | +xferBenchConfig::loadParams(cxxopts::ParseResult &result) { |
200 | 267 | #define NB_ARG(name) \ |
201 | | - FLAGS_ ##name |
| 268 | + result[#name].as<decltype(name)>() |
202 | 269 |
|
203 | 270 | benchmark_group = NB_ARG(benchmark_group); |
204 | 271 | runtime_type = NB_ARG(runtime_type); |
|
0 commit comments