#include #include #include "Runner.h" #include "Stats.h" #include "Generator.h" #include "Common/Exception.h" #include #include #include namespace { template std::optional valueToOptional(const boost::program_options::variable_value & value) { if (value.empty()) return std::nullopt; return value.as(); } } int main(int argc, char *argv[]) { bool print_stacktrace = true; try { using boost::program_options::value; boost::program_options::options_description desc = createOptionsDescription("Allowed options", getTerminalWidth()); desc.add_options() ("help", "produce help message") ("config", value()->default_value(""), "yaml/xml file containing configuration") ("concurrency,c", value(), "number of parallel queries") ("report-delay,d", value(), "delay between intermediate reports in seconds (set 0 to disable reports)") ("iterations,i", value(), "amount of queries to be executed") ("time-limit,t", value(), "stop launch of queries after specified time limit") ("hosts,h", value()->multitoken()->default_value(Strings{}, ""), "") ("continue_on_errors", "continue testing even if a query fails") ; boost::program_options::variables_map options; boost::program_options::store(boost::program_options::parse_command_line(argc, argv, desc), options); boost::program_options::notify(options); if (options.count("help")) { std::cout << "Usage: " << argv[0] << " [options] < queries.txt\n"; std::cout << desc << "\n"; return 1; } Runner runner(valueToOptional(options["concurrency"]), options["config"].as(), options["hosts"].as(), valueToOptional(options["time-limit"]), valueToOptional(options["report-delay"]), options.count("continue_on_errors") ? std::optional(true) : std::nullopt, valueToOptional(options["iterations"])); try { runner.runBenchmark(); } catch (const DB::Exception & e) { std::cout << "Got exception while trying to run benchmark: " << e.message() << std::endl; } return 0; } catch (...) { std::cerr << DB::getCurrentExceptionMessage(print_stacktrace, true) << std::endl; return DB::getCurrentExceptionCode(); } }