2021-04-12 08:10:23 +00:00
|
|
|
#include <iostream>
|
2021-04-12 15:40:42 +00:00
|
|
|
#include <boost/program_options.hpp>
|
|
|
|
#include "Runner.h"
|
|
|
|
#include "Stats.h"
|
|
|
|
#include "Generator.h"
|
2023-04-07 14:14:39 +00:00
|
|
|
#include "Common/Exception.h"
|
2021-04-12 15:40:42 +00:00
|
|
|
#include <Common/TerminalSize.h>
|
|
|
|
#include <Core/Types.h>
|
2023-04-07 14:14:39 +00:00
|
|
|
#include <boost/program_options/variables_map.hpp>
|
2021-04-12 08:10:23 +00:00
|
|
|
|
2023-04-07 14:14:39 +00:00
|
|
|
namespace
|
|
|
|
{
|
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
std::optional<T> valueToOptional(const boost::program_options::variable_value & value)
|
|
|
|
{
|
|
|
|
if (value.empty())
|
|
|
|
return std::nullopt;
|
|
|
|
|
|
|
|
return value.as<T>();
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2021-04-12 08:10:23 +00:00
|
|
|
|
|
|
|
int main(int argc, char *argv[])
|
|
|
|
{
|
|
|
|
|
2021-04-12 15:40:42 +00:00
|
|
|
bool print_stacktrace = true;
|
2021-04-12 08:10:23 +00:00
|
|
|
|
2021-04-12 15:40:42 +00:00
|
|
|
try
|
|
|
|
{
|
|
|
|
using boost::program_options::value;
|
|
|
|
|
|
|
|
boost::program_options::options_description desc = createOptionsDescription("Allowed options", getTerminalWidth());
|
|
|
|
desc.add_options()
|
2023-04-07 14:14:39 +00:00
|
|
|
("help", "produce help message")
|
|
|
|
("config", value<std::string>()->default_value(""), "yaml/xml file containing configuration")
|
|
|
|
("concurrency,c", value<unsigned>(), "number of parallel queries")
|
|
|
|
("report-delay,d", value<double>(), "delay between intermediate reports in seconds (set 0 to disable reports)")
|
|
|
|
("iterations,i", value<size_t>(), "amount of queries to be executed")
|
|
|
|
("time-limit,t", value<double>(), "stop launch of queries after specified time limit")
|
|
|
|
("hosts,h", value<Strings>()->multitoken()->default_value(Strings{}, ""), "")
|
2021-04-12 15:40:42 +00:00
|
|
|
("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;
|
|
|
|
}
|
|
|
|
|
2023-04-07 14:14:39 +00:00
|
|
|
Runner runner(valueToOptional<unsigned>(options["concurrency"]),
|
|
|
|
options["config"].as<std::string>(),
|
|
|
|
options["hosts"].as<Strings>(),
|
|
|
|
valueToOptional<double>(options["time-limit"]),
|
|
|
|
valueToOptional<double>(options["report-delay"]),
|
|
|
|
options.count("continue_on_errors") ? std::optional<bool>(true) : std::nullopt,
|
|
|
|
valueToOptional<size_t>(options["iterations"]));
|
2021-04-12 15:40:42 +00:00
|
|
|
|
2023-04-07 14:14:39 +00:00
|
|
|
try
|
|
|
|
{
|
|
|
|
runner.runBenchmark();
|
|
|
|
}
|
|
|
|
catch (const DB::Exception & e)
|
|
|
|
{
|
|
|
|
std::cout << "Got exception while trying to run benchmark: " << e.message() << std::endl;
|
|
|
|
}
|
2021-04-12 15:40:42 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
catch (...)
|
|
|
|
{
|
|
|
|
std::cerr << DB::getCurrentExceptionMessage(print_stacktrace, true) << std::endl;
|
|
|
|
return DB::getCurrentExceptionCode();
|
|
|
|
}
|
2021-04-12 08:10:23 +00:00
|
|
|
}
|