2017-05-07 18:55:42 +00:00
|
|
|
#include <functional>
|
2017-01-13 18:26:51 +00:00
|
|
|
#include <iostream>
|
2017-02-07 16:47:10 +00:00
|
|
|
#include <limits>
|
2017-05-07 18:55:42 +00:00
|
|
|
#include <regex>
|
2017-05-08 19:25:38 +00:00
|
|
|
#include <sys/sysinfo.h>
|
2017-02-24 22:02:08 +00:00
|
|
|
#include <unistd.h>
|
2017-01-13 18:26:51 +00:00
|
|
|
|
2017-01-20 12:36:16 +00:00
|
|
|
#include <boost/program_options.hpp>
|
2017-05-05 18:32:38 +00:00
|
|
|
#include <boost/filesystem.hpp>
|
2017-05-05 11:36:55 +00:00
|
|
|
#include <sys/stat.h>
|
2017-01-20 12:36:16 +00:00
|
|
|
|
2017-05-05 11:36:55 +00:00
|
|
|
#include <AggregateFunctions/ReservoirSampler.h>
|
2017-05-05 12:41:18 +00:00
|
|
|
#include <Client/Connection.h>
|
2017-05-05 11:36:55 +00:00
|
|
|
#include <Common/ConcurrentBoundedQueue.h>
|
|
|
|
#include <Common/Stopwatch.h>
|
|
|
|
#include <Common/ThreadPool.h>
|
|
|
|
#include <Core/Types.h>
|
|
|
|
#include <DataStreams/RemoteBlockInputStream.h>
|
2017-05-06 14:36:37 +00:00
|
|
|
#include <IO/ReadBufferFromFile.h>
|
2017-05-05 11:36:55 +00:00
|
|
|
#include <IO/ReadHelpers.h>
|
2017-05-08 19:25:38 +00:00
|
|
|
#include <IO/WriteBufferFromFile.h>
|
2017-05-05 11:36:55 +00:00
|
|
|
#include <Interpreters/Settings.h>
|
2017-01-31 16:48:36 +00:00
|
|
|
|
2017-02-07 16:47:10 +00:00
|
|
|
|
2017-01-20 12:36:16 +00:00
|
|
|
#include <Poco/AutoPtr.h>
|
2017-05-05 11:36:55 +00:00
|
|
|
#include <Poco/Exception.h>
|
2017-01-20 12:36:16 +00:00
|
|
|
#include <Poco/SAX/InputSource.h>
|
|
|
|
#include <Poco/Util/XMLConfiguration.h>
|
2017-05-05 11:36:55 +00:00
|
|
|
#include <Poco/XML/XMLStream.h>
|
2017-01-20 12:36:16 +00:00
|
|
|
|
2017-02-24 22:02:08 +00:00
|
|
|
#include "InterruptListener.h"
|
2017-01-20 12:36:16 +00:00
|
|
|
|
2017-01-13 18:26:51 +00:00
|
|
|
/** Tests launcher for ClickHouse.
|
|
|
|
* The tool walks through given or default folder in order to find files with
|
2017-04-07 19:01:41 +00:00
|
|
|
* tests' descriptions and launches it.
|
2017-01-13 18:26:51 +00:00
|
|
|
*/
|
2017-05-06 14:36:37 +00:00
|
|
|
namespace FS = boost::filesystem;
|
|
|
|
|
2017-01-13 18:26:51 +00:00
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
namespace ErrorCodes
|
|
|
|
{
|
2017-05-05 11:36:55 +00:00
|
|
|
extern const int POCO_EXCEPTION;
|
|
|
|
extern const int STD_EXCEPTION;
|
|
|
|
extern const int UNKNOWN_EXCEPTION;
|
2017-01-13 18:26:51 +00:00
|
|
|
}
|
|
|
|
|
2017-05-05 17:48:11 +00:00
|
|
|
const std::string FOUR_SPACES = " ";
|
2017-05-05 12:41:18 +00:00
|
|
|
|
2017-05-05 11:36:55 +00:00
|
|
|
bool isNumber(const std::string & str)
|
|
|
|
{
|
|
|
|
if (str.empty())
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
2017-03-13 16:24:50 +00:00
|
|
|
|
2017-05-05 17:48:11 +00:00
|
|
|
size_t dots_counter = 0;
|
2017-03-13 16:24:50 +00:00
|
|
|
|
2017-05-05 11:36:55 +00:00
|
|
|
if (str[0] == '.' || str[str.size() - 1] == '.')
|
|
|
|
{
|
2017-03-13 16:24:50 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-05-05 11:36:55 +00:00
|
|
|
for (char chr : str)
|
|
|
|
{
|
|
|
|
if (chr == '.')
|
|
|
|
{
|
2017-05-05 17:48:11 +00:00
|
|
|
if (dots_counter)
|
2017-03-13 16:24:50 +00:00
|
|
|
return false;
|
|
|
|
else
|
2017-05-05 17:48:11 +00:00
|
|
|
++dots_counter;
|
2017-03-13 16:24:50 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2017-05-05 11:36:55 +00:00
|
|
|
if (chr < '0' || chr > '9')
|
|
|
|
{
|
2017-03-13 16:24:50 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2017-05-05 11:36:55 +00:00
|
|
|
class JSONString
|
|
|
|
{
|
|
|
|
private:
|
2017-03-13 16:24:50 +00:00
|
|
|
std::map<std::string, std::string> content;
|
|
|
|
std::string current_key;
|
|
|
|
size_t _padding = 1;
|
2017-05-05 11:36:55 +00:00
|
|
|
|
|
|
|
public:
|
|
|
|
JSONString(){};
|
|
|
|
JSONString(size_t padding) : _padding(padding){};
|
2017-03-13 16:24:50 +00:00
|
|
|
|
|
|
|
JSONString & operator[](const std::string & key)
|
|
|
|
{
|
|
|
|
current_key = key;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename T>
|
2017-05-05 11:36:55 +00:00
|
|
|
typename std::enable_if<std::is_arithmetic<T>::value, JSONString &>::type operator[](const T key)
|
2017-03-13 16:24:50 +00:00
|
|
|
{
|
|
|
|
current_key = std::to_string(key);
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
void set(std::string value)
|
|
|
|
{
|
2017-05-05 11:36:55 +00:00
|
|
|
if (current_key.empty())
|
|
|
|
{
|
2017-03-13 16:24:50 +00:00
|
|
|
throw "cannot use set without key";
|
|
|
|
}
|
|
|
|
|
2017-05-05 11:36:55 +00:00
|
|
|
if (value.empty())
|
|
|
|
{
|
2017-03-13 16:24:50 +00:00
|
|
|
value = "null";
|
|
|
|
}
|
|
|
|
|
|
|
|
bool reserved = (value[0] == '[' || value[0] == '{' || value == "null");
|
|
|
|
|
2017-05-05 11:36:55 +00:00
|
|
|
if (!reserved && !isNumber(value))
|
|
|
|
{
|
2017-03-13 16:24:50 +00:00
|
|
|
value = '\"' + value + '\"';
|
|
|
|
}
|
|
|
|
|
|
|
|
content[current_key] = value;
|
|
|
|
current_key = "";
|
|
|
|
}
|
|
|
|
|
2017-05-05 17:48:11 +00:00
|
|
|
void set(const JSONString & inner_json)
|
2017-03-13 16:24:50 +00:00
|
|
|
{
|
2017-05-05 17:48:11 +00:00
|
|
|
set(inner_json.constructOutput());
|
2017-03-13 16:24:50 +00:00
|
|
|
}
|
|
|
|
|
2017-05-05 17:48:11 +00:00
|
|
|
void set(const std::vector<JSONString> & run_infos)
|
2017-03-13 16:24:50 +00:00
|
|
|
{
|
2017-05-05 11:36:55 +00:00
|
|
|
if (current_key.empty())
|
|
|
|
{
|
2017-03-13 16:24:50 +00:00
|
|
|
throw "cannot use set without key";
|
|
|
|
}
|
|
|
|
|
|
|
|
content[current_key] = "[\n";
|
|
|
|
|
2017-05-05 17:48:11 +00:00
|
|
|
for (size_t i = 0; i < run_infos.size(); ++i)
|
2017-05-05 11:36:55 +00:00
|
|
|
{
|
|
|
|
for (size_t i = 0; i < _padding + 1; ++i)
|
|
|
|
{
|
2017-05-05 17:48:11 +00:00
|
|
|
content[current_key] += FOUR_SPACES;
|
2017-05-05 11:36:55 +00:00
|
|
|
}
|
2017-05-05 17:48:11 +00:00
|
|
|
content[current_key] += run_infos[i].constructOutput(_padding + 2);
|
2017-03-13 16:24:50 +00:00
|
|
|
|
2017-05-05 17:48:11 +00:00
|
|
|
if (i != run_infos.size() - 1)
|
2017-05-05 11:36:55 +00:00
|
|
|
{
|
|
|
|
content[current_key] += ',';
|
|
|
|
}
|
2017-03-13 16:24:50 +00:00
|
|
|
|
2017-05-05 11:36:55 +00:00
|
|
|
content[current_key] += "\n";
|
2017-03-13 16:24:50 +00:00
|
|
|
}
|
|
|
|
|
2017-05-05 11:36:55 +00:00
|
|
|
for (size_t i = 0; i < _padding; ++i)
|
|
|
|
{
|
2017-05-05 17:48:11 +00:00
|
|
|
content[current_key] += FOUR_SPACES;
|
2017-03-13 16:24:50 +00:00
|
|
|
}
|
|
|
|
content[current_key] += ']';
|
|
|
|
current_key = "";
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
typename std::enable_if<std::is_arithmetic<T>::value, void>::type set(T value)
|
|
|
|
{
|
|
|
|
set(std::to_string(value));
|
|
|
|
}
|
|
|
|
std::string constructOutput() const
|
|
|
|
{
|
2017-05-05 11:36:55 +00:00
|
|
|
return constructOutput(_padding);
|
2017-03-13 16:24:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
std::string constructOutput(size_t padding) const
|
|
|
|
{
|
|
|
|
std::string output = "{";
|
|
|
|
|
|
|
|
bool first = true;
|
|
|
|
|
2017-05-05 11:36:55 +00:00
|
|
|
for (auto it = content.begin(); it != content.end(); ++it)
|
|
|
|
{
|
|
|
|
if (!first)
|
|
|
|
{
|
2017-03-13 16:24:50 +00:00
|
|
|
output += ',';
|
2017-05-05 11:36:55 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-03-13 16:24:50 +00:00
|
|
|
first = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
output += "\n";
|
2017-05-05 11:36:55 +00:00
|
|
|
for (size_t i = 0; i < padding; ++i)
|
|
|
|
{
|
2017-05-05 17:48:11 +00:00
|
|
|
output += FOUR_SPACES;
|
2017-03-13 16:24:50 +00:00
|
|
|
}
|
|
|
|
|
2017-05-05 11:36:55 +00:00
|
|
|
std::string key = '\"' + it->first + '\"';
|
2017-03-13 16:24:50 +00:00
|
|
|
std::string value = it->second;
|
|
|
|
|
|
|
|
output += key + ": " + value;
|
|
|
|
}
|
|
|
|
|
|
|
|
output += "\n";
|
2017-05-05 11:36:55 +00:00
|
|
|
for (size_t i = 0; i < padding - 1; ++i)
|
|
|
|
{
|
2017-05-05 17:48:11 +00:00
|
|
|
output += FOUR_SPACES;
|
2017-03-13 16:24:50 +00:00
|
|
|
}
|
|
|
|
output += "}";
|
|
|
|
return output;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2017-05-05 17:48:11 +00:00
|
|
|
std::ostream & operator<<(std::ostream & stream, const JSONString & json_obj)
|
2017-03-13 16:24:50 +00:00
|
|
|
{
|
2017-05-05 17:48:11 +00:00
|
|
|
stream << json_obj.constructOutput();
|
2017-03-13 16:24:50 +00:00
|
|
|
|
|
|
|
return stream;
|
|
|
|
}
|
|
|
|
|
2017-05-05 11:36:55 +00:00
|
|
|
enum PriorityType
|
|
|
|
{
|
|
|
|
min,
|
|
|
|
max
|
|
|
|
};
|
2017-03-27 18:25:42 +00:00
|
|
|
|
2017-05-05 11:36:55 +00:00
|
|
|
struct CriterionWithPriority
|
|
|
|
{
|
|
|
|
PriorityType priority;
|
|
|
|
size_t value;
|
|
|
|
bool fulfilled;
|
2017-03-27 18:25:42 +00:00
|
|
|
|
2017-05-05 11:36:55 +00:00
|
|
|
CriterionWithPriority() : value(0), fulfilled(false)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
CriterionWithPriority(const CriterionWithPriority &) = default;
|
2017-02-07 16:47:10 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/// Termination criterions. The running test will be terminated in either of two conditions:
|
|
|
|
/// 1. All criterions marked 'min' are fulfilled
|
|
|
|
/// or
|
|
|
|
/// 2. Any criterion marked 'max' is fulfilled
|
2017-05-05 11:36:55 +00:00
|
|
|
class StopCriterions
|
|
|
|
{
|
2017-02-07 16:47:10 +00:00
|
|
|
private:
|
2017-05-05 11:36:55 +00:00
|
|
|
using AbstractConfiguration = Poco::AutoPtr<Poco::Util::AbstractConfiguration>;
|
|
|
|
using Keys = std::vector<std::string>;
|
|
|
|
|
2017-05-05 17:48:11 +00:00
|
|
|
void initializeStruct(const std::string & priority, const AbstractConfiguration & stop_criterions_view)
|
2017-05-05 11:36:55 +00:00
|
|
|
{
|
|
|
|
Keys keys;
|
2017-05-05 17:48:11 +00:00
|
|
|
stop_criterions_view->keys(priority, keys);
|
2017-05-05 11:36:55 +00:00
|
|
|
|
2017-05-05 17:48:11 +00:00
|
|
|
PriorityType priority_type = (priority == "min" ? min : max);
|
2017-05-05 11:36:55 +00:00
|
|
|
|
|
|
|
for (const std::string & key : keys)
|
|
|
|
{
|
|
|
|
if (key == "timeout_ms")
|
|
|
|
{
|
2017-05-05 17:48:11 +00:00
|
|
|
timeout_ms.value = stop_criterions_view->getUInt64(priority + ".timeout_ms");
|
|
|
|
timeout_ms.priority = priority_type;
|
2017-05-05 11:36:55 +00:00
|
|
|
}
|
|
|
|
else if (key == "rows_read")
|
|
|
|
{
|
2017-05-05 17:48:11 +00:00
|
|
|
rows_read.value = stop_criterions_view->getUInt64(priority + ".rows_read");
|
|
|
|
rows_read.priority = priority_type;
|
2017-05-05 11:36:55 +00:00
|
|
|
}
|
|
|
|
else if (key == "bytes_read_uncompressed")
|
|
|
|
{
|
2017-05-05 17:48:11 +00:00
|
|
|
bytes_read_uncompressed.value = stop_criterions_view->getUInt64(priority + ".bytes_read_uncompressed");
|
|
|
|
bytes_read_uncompressed.priority = priority_type;
|
2017-05-05 11:36:55 +00:00
|
|
|
}
|
|
|
|
else if (key == "iterations")
|
|
|
|
{
|
2017-05-05 17:48:11 +00:00
|
|
|
iterations.value = stop_criterions_view->getUInt64(priority + ".iterations");
|
|
|
|
iterations.priority = priority_type;
|
2017-05-05 11:36:55 +00:00
|
|
|
}
|
|
|
|
else if (key == "min_time_not_changing_for_ms")
|
|
|
|
{
|
2017-05-05 17:48:11 +00:00
|
|
|
min_time_not_changing_for_ms.value = stop_criterions_view->getUInt64(priority + ".min_time_not_changing_for_ms");
|
|
|
|
min_time_not_changing_for_ms.priority = priority_type;
|
2017-05-05 11:36:55 +00:00
|
|
|
}
|
|
|
|
else if (key == "max_speed_not_changing_for_ms")
|
|
|
|
{
|
2017-05-05 17:48:11 +00:00
|
|
|
max_speed_not_changing_for_ms.value = stop_criterions_view->getUInt64(priority + ".max_speed_not_changing_for_ms");
|
|
|
|
max_speed_not_changing_for_ms.priority = priority_type;
|
2017-05-05 11:36:55 +00:00
|
|
|
}
|
|
|
|
else if (key == "average_speed_not_changing_for_ms")
|
|
|
|
{
|
2017-05-05 17:48:11 +00:00
|
|
|
average_speed_not_changing_for_ms.value = stop_criterions_view->getUInt64(priority + ".average_speed_not_changing_for_ms");
|
|
|
|
average_speed_not_changing_for_ms.priority = priority_type;
|
2017-05-05 11:36:55 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
throw Poco::Exception("Met unkown stop criterion: " + key, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (priority == "min")
|
|
|
|
{
|
|
|
|
++number_of_initialized_min;
|
|
|
|
};
|
|
|
|
if (priority == "max")
|
|
|
|
{
|
|
|
|
++number_of_initialized_max;
|
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
2017-02-07 16:47:10 +00:00
|
|
|
|
|
|
|
public:
|
2017-05-05 11:36:55 +00:00
|
|
|
StopCriterions() : number_of_initialized_min(0), number_of_initialized_max(0), fulfilled_criterions_min(0), fulfilled_criterions_max(0)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2017-05-05 17:48:11 +00:00
|
|
|
StopCriterions(const StopCriterions & another_criterions)
|
|
|
|
: timeout_ms(another_criterions.timeout_ms),
|
|
|
|
rows_read(another_criterions.rows_read),
|
|
|
|
bytes_read_uncompressed(another_criterions.bytes_read_uncompressed),
|
|
|
|
iterations(another_criterions.iterations),
|
|
|
|
min_time_not_changing_for_ms(another_criterions.min_time_not_changing_for_ms),
|
|
|
|
max_speed_not_changing_for_ms(another_criterions.max_speed_not_changing_for_ms),
|
|
|
|
average_speed_not_changing_for_ms(another_criterions.average_speed_not_changing_for_ms),
|
|
|
|
|
|
|
|
number_of_initialized_min(another_criterions.number_of_initialized_min),
|
|
|
|
number_of_initialized_max(another_criterions.number_of_initialized_max),
|
|
|
|
fulfilled_criterions_min(another_criterions.fulfilled_criterions_min),
|
|
|
|
fulfilled_criterions_max(another_criterions.fulfilled_criterions_max)
|
2017-05-05 11:36:55 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2017-05-05 17:48:11 +00:00
|
|
|
void loadFromConfig(const AbstractConfiguration & stop_criterions_view)
|
2017-05-05 11:36:55 +00:00
|
|
|
{
|
2017-05-05 17:48:11 +00:00
|
|
|
if (stop_criterions_view->has("min"))
|
2017-05-05 11:36:55 +00:00
|
|
|
{
|
2017-05-05 17:48:11 +00:00
|
|
|
initializeStruct("min", stop_criterions_view);
|
2017-05-05 11:36:55 +00:00
|
|
|
}
|
|
|
|
|
2017-05-05 17:48:11 +00:00
|
|
|
if (stop_criterions_view->has("max"))
|
2017-05-05 11:36:55 +00:00
|
|
|
{
|
2017-05-05 17:48:11 +00:00
|
|
|
initializeStruct("max", stop_criterions_view);
|
2017-05-05 11:36:55 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void reset()
|
|
|
|
{
|
|
|
|
timeout_ms.fulfilled = false;
|
|
|
|
rows_read.fulfilled = false;
|
|
|
|
bytes_read_uncompressed.fulfilled = false;
|
|
|
|
iterations.fulfilled = false;
|
|
|
|
min_time_not_changing_for_ms.fulfilled = false;
|
|
|
|
max_speed_not_changing_for_ms.fulfilled = false;
|
|
|
|
average_speed_not_changing_for_ms.fulfilled = false;
|
|
|
|
|
|
|
|
fulfilled_criterions_min = 0;
|
|
|
|
fulfilled_criterions_max = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
CriterionWithPriority timeout_ms;
|
|
|
|
CriterionWithPriority rows_read;
|
|
|
|
CriterionWithPriority bytes_read_uncompressed;
|
|
|
|
CriterionWithPriority iterations;
|
|
|
|
CriterionWithPriority min_time_not_changing_for_ms;
|
|
|
|
CriterionWithPriority max_speed_not_changing_for_ms;
|
|
|
|
CriterionWithPriority average_speed_not_changing_for_ms;
|
2017-02-07 16:47:10 +00:00
|
|
|
|
|
|
|
/// Hereafter 'min' and 'max', in context of critetions, mean a level of importance
|
2017-05-05 11:36:55 +00:00
|
|
|
/// Number of initialized properties met in configuration
|
2017-05-05 12:41:18 +00:00
|
|
|
size_t number_of_initialized_min;
|
|
|
|
size_t number_of_initialized_max;
|
2017-02-07 16:47:10 +00:00
|
|
|
|
2017-05-05 12:41:18 +00:00
|
|
|
size_t fulfilled_criterions_min;
|
|
|
|
size_t fulfilled_criterions_max;
|
2017-02-07 16:47:10 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct Stats
|
|
|
|
{
|
2017-05-05 11:36:55 +00:00
|
|
|
Stopwatch watch;
|
|
|
|
Stopwatch watch_per_query;
|
|
|
|
Stopwatch min_time_watch;
|
|
|
|
Stopwatch max_rows_speed_watch;
|
|
|
|
Stopwatch max_bytes_speed_watch;
|
|
|
|
Stopwatch avg_rows_speed_watch;
|
|
|
|
Stopwatch avg_bytes_speed_watch;
|
|
|
|
size_t queries;
|
|
|
|
size_t rows_read;
|
|
|
|
size_t bytes_read;
|
|
|
|
|
|
|
|
using Sampler = ReservoirSampler<double>;
|
|
|
|
Sampler sampler{1 << 16};
|
|
|
|
|
|
|
|
/// min_time in ms
|
|
|
|
UInt64 min_time = std::numeric_limits<UInt64>::max();
|
|
|
|
double total_time = 0;
|
|
|
|
|
|
|
|
double max_rows_speed = 0;
|
|
|
|
double max_bytes_speed = 0;
|
|
|
|
|
|
|
|
double avg_rows_speed_value = 0;
|
|
|
|
double avg_rows_speed_first = 0;
|
|
|
|
static double avg_rows_speed_precision;
|
|
|
|
|
|
|
|
double avg_bytes_speed_value = 0;
|
|
|
|
double avg_bytes_speed_first = 0;
|
|
|
|
static double avg_bytes_speed_precision;
|
|
|
|
|
|
|
|
size_t number_of_rows_speed_info_batches = 0;
|
|
|
|
size_t number_of_bytes_speed_info_batches = 0;
|
|
|
|
|
2017-05-05 12:41:18 +00:00
|
|
|
bool ready = false; // check if a query wasn't interrupted by SIGINT
|
2017-05-05 11:36:55 +00:00
|
|
|
|
2017-05-05 17:48:11 +00:00
|
|
|
std::string getStatisticByName(const std::string & statistic_name)
|
2017-05-05 11:36:55 +00:00
|
|
|
{
|
2017-05-05 17:48:11 +00:00
|
|
|
if (statistic_name == "min_time")
|
2017-05-05 11:36:55 +00:00
|
|
|
{
|
|
|
|
return std::to_string(min_time) + "ms";
|
|
|
|
}
|
2017-05-05 17:48:11 +00:00
|
|
|
if (statistic_name == "quantiles")
|
2017-05-05 11:36:55 +00:00
|
|
|
{
|
|
|
|
std::string result = "\n";
|
|
|
|
|
|
|
|
for (double percent = 10; percent <= 90; percent += 10)
|
|
|
|
{
|
2017-05-05 17:48:11 +00:00
|
|
|
result += FOUR_SPACES + std::to_string((percent / 100));
|
2017-05-05 11:36:55 +00:00
|
|
|
result += ": " + std::to_string(sampler.quantileInterpolated(percent / 100.0));
|
|
|
|
result += "\n";
|
|
|
|
}
|
2017-05-05 17:48:11 +00:00
|
|
|
result += FOUR_SPACES + "0.95: " + std::to_string(sampler.quantileInterpolated(95 / 100.0)) + "\n";
|
|
|
|
result += FOUR_SPACES + "0.99: " + std::to_string(sampler.quantileInterpolated(99 / 100.0)) + "\n";
|
|
|
|
result += FOUR_SPACES + "0.999: " + std::to_string(sampler.quantileInterpolated(99.9 / 100.)) + "\n";
|
|
|
|
result += FOUR_SPACES + "0.9999: " + std::to_string(sampler.quantileInterpolated(99.99 / 100.));
|
2017-05-05 11:36:55 +00:00
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
2017-05-05 17:48:11 +00:00
|
|
|
if (statistic_name == "total_time")
|
2017-05-05 11:36:55 +00:00
|
|
|
{
|
|
|
|
return std::to_string(total_time) + "s";
|
|
|
|
}
|
2017-05-05 17:48:11 +00:00
|
|
|
if (statistic_name == "queries_per_second")
|
2017-05-05 11:36:55 +00:00
|
|
|
{
|
|
|
|
return std::to_string(queries / total_time);
|
|
|
|
}
|
2017-05-05 17:48:11 +00:00
|
|
|
if (statistic_name == "rows_per_second")
|
2017-05-05 11:36:55 +00:00
|
|
|
{
|
|
|
|
return std::to_string(rows_read / total_time);
|
|
|
|
}
|
2017-05-05 17:48:11 +00:00
|
|
|
if (statistic_name == "bytes_per_second")
|
2017-05-05 11:36:55 +00:00
|
|
|
{
|
|
|
|
return std::to_string(bytes_read / total_time);
|
|
|
|
}
|
|
|
|
|
2017-05-05 17:48:11 +00:00
|
|
|
if (statistic_name == "max_rows_per_second")
|
2017-05-05 11:36:55 +00:00
|
|
|
{
|
|
|
|
return std::to_string(max_rows_speed);
|
|
|
|
}
|
2017-05-05 17:48:11 +00:00
|
|
|
if (statistic_name == "max_bytes_per_second")
|
2017-05-05 11:36:55 +00:00
|
|
|
{
|
|
|
|
return std::to_string(max_bytes_speed);
|
|
|
|
}
|
2017-05-05 17:48:11 +00:00
|
|
|
if (statistic_name == "avg_rows_per_second")
|
2017-05-05 11:36:55 +00:00
|
|
|
{
|
|
|
|
return std::to_string(avg_rows_speed_value);
|
|
|
|
}
|
2017-05-05 17:48:11 +00:00
|
|
|
if (statistic_name == "avg_bytes_per_second")
|
2017-05-05 11:36:55 +00:00
|
|
|
{
|
|
|
|
return std::to_string(avg_bytes_speed_value);
|
|
|
|
}
|
|
|
|
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
|
|
|
void update_min_time(const UInt64 min_time_candidate)
|
|
|
|
{
|
|
|
|
if (min_time_candidate < min_time)
|
|
|
|
{
|
|
|
|
min_time = min_time_candidate;
|
|
|
|
min_time_watch.restart();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void update_average_speed(const double new_speed_info,
|
|
|
|
Stopwatch & avg_speed_watch,
|
|
|
|
size_t & number_of_info_batches,
|
|
|
|
double precision,
|
|
|
|
double & avg_speed_first,
|
|
|
|
double & avg_speed_value)
|
|
|
|
{
|
|
|
|
avg_speed_value = ((avg_speed_value * number_of_info_batches) + new_speed_info);
|
|
|
|
avg_speed_value /= (++number_of_info_batches);
|
|
|
|
|
|
|
|
if (avg_speed_first == 0)
|
|
|
|
{
|
|
|
|
avg_speed_first = avg_speed_value;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (abs(avg_speed_value - avg_speed_first) >= precision)
|
|
|
|
{
|
|
|
|
avg_speed_first = avg_speed_value;
|
|
|
|
avg_speed_watch.restart();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void update_max_speed(const size_t max_speed_candidate, Stopwatch & max_speed_watch, double & max_speed)
|
|
|
|
{
|
|
|
|
if (max_speed_candidate > max_speed)
|
|
|
|
{
|
|
|
|
max_speed = max_speed_candidate;
|
|
|
|
max_speed_watch.restart();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void add(size_t rows_read_inc, size_t bytes_read_inc)
|
|
|
|
{
|
|
|
|
rows_read += rows_read_inc;
|
|
|
|
bytes_read += bytes_read_inc;
|
|
|
|
|
|
|
|
double new_rows_speed = rows_read_inc / watch_per_query.elapsedSeconds();
|
|
|
|
double new_bytes_speed = bytes_read_inc / watch_per_query.elapsedSeconds();
|
|
|
|
|
|
|
|
/// Update rows speed
|
|
|
|
update_max_speed(new_rows_speed, max_rows_speed_watch, max_rows_speed);
|
|
|
|
update_average_speed(new_rows_speed,
|
|
|
|
avg_rows_speed_watch,
|
|
|
|
number_of_rows_speed_info_batches,
|
|
|
|
avg_rows_speed_precision,
|
|
|
|
avg_rows_speed_first,
|
|
|
|
avg_rows_speed_value);
|
|
|
|
/// Update bytes speed
|
|
|
|
update_max_speed(new_bytes_speed, max_bytes_speed_watch, max_bytes_speed);
|
|
|
|
update_average_speed(new_bytes_speed,
|
|
|
|
avg_bytes_speed_watch,
|
|
|
|
number_of_bytes_speed_info_batches,
|
|
|
|
avg_bytes_speed_precision,
|
|
|
|
avg_bytes_speed_first,
|
|
|
|
avg_bytes_speed_value);
|
|
|
|
}
|
|
|
|
|
|
|
|
void updateQueryInfo()
|
|
|
|
{
|
|
|
|
++queries;
|
|
|
|
sampler.insert(watch_per_query.elapsedSeconds());
|
|
|
|
update_min_time(watch_per_query.elapsed() / (1000 * 1000)); /// ns to ms
|
|
|
|
}
|
|
|
|
|
|
|
|
void setTotalTime()
|
|
|
|
{
|
|
|
|
total_time = watch.elapsedSeconds();
|
|
|
|
}
|
|
|
|
|
|
|
|
void clear()
|
|
|
|
{
|
|
|
|
watch.restart();
|
|
|
|
watch_per_query.restart();
|
|
|
|
min_time_watch.restart();
|
|
|
|
max_rows_speed_watch.restart();
|
|
|
|
max_bytes_speed_watch.restart();
|
|
|
|
avg_rows_speed_watch.restart();
|
|
|
|
avg_bytes_speed_watch.restart();
|
|
|
|
|
|
|
|
sampler.clear();
|
|
|
|
|
|
|
|
queries = 0;
|
|
|
|
rows_read = 0;
|
|
|
|
bytes_read = 0;
|
|
|
|
|
|
|
|
min_time = std::numeric_limits<UInt64>::max();
|
|
|
|
total_time = 0;
|
|
|
|
max_rows_speed = 0;
|
|
|
|
max_bytes_speed = 0;
|
|
|
|
avg_rows_speed_value = 0;
|
|
|
|
avg_bytes_speed_value = 0;
|
|
|
|
avg_rows_speed_first = 0;
|
|
|
|
avg_bytes_speed_first = 0;
|
|
|
|
avg_rows_speed_precision = 0.001;
|
|
|
|
avg_bytes_speed_precision = 0.001;
|
|
|
|
number_of_rows_speed_info_batches = 0;
|
|
|
|
number_of_bytes_speed_info_batches = 0;
|
|
|
|
}
|
2017-02-07 16:47:10 +00:00
|
|
|
};
|
|
|
|
|
2017-05-05 11:36:55 +00:00
|
|
|
double Stats::avg_rows_speed_precision = 0.001;
|
2017-03-27 18:25:42 +00:00
|
|
|
double Stats::avg_bytes_speed_precision = 0.001;
|
|
|
|
|
2017-01-13 18:26:51 +00:00
|
|
|
class PerformanceTest
|
|
|
|
{
|
|
|
|
public:
|
2017-05-07 18:55:42 +00:00
|
|
|
using Strings = std::vector<std::string>;
|
|
|
|
|
2017-05-05 12:41:18 +00:00
|
|
|
PerformanceTest(
|
2017-05-05 11:36:55 +00:00
|
|
|
const String & host_,
|
|
|
|
const UInt16 port_,
|
|
|
|
const String & default_database_,
|
|
|
|
const String & user_,
|
|
|
|
const String & password_,
|
2017-05-05 15:58:25 +00:00
|
|
|
const bool & lite_output_,
|
2017-05-07 00:29:30 +00:00
|
|
|
const std::string & profiles_file_,
|
2017-05-07 18:55:42 +00:00
|
|
|
Strings && input_files_,
|
|
|
|
Strings && tests_tags_,
|
|
|
|
Strings && skip_tags_,
|
|
|
|
Strings && tests_names_,
|
|
|
|
Strings && skip_names_,
|
|
|
|
Strings && tests_names_regexp_,
|
|
|
|
Strings && skip_names_regexp_
|
|
|
|
)
|
2017-05-05 12:41:18 +00:00
|
|
|
: connection(host_, port_, default_database_, user_, password_),
|
2017-05-05 15:58:25 +00:00
|
|
|
gotSIGINT(false),
|
2017-05-07 00:29:30 +00:00
|
|
|
lite_output(lite_output_),
|
2017-05-07 18:55:42 +00:00
|
|
|
profiles_file(profiles_file_),
|
|
|
|
input_files(input_files_),
|
|
|
|
tests_tags(std::move(tests_tags_)),
|
|
|
|
skip_tags(std::move(skip_tags_)),
|
|
|
|
tests_names(std::move(tests_names_)),
|
|
|
|
skip_names(std::move(skip_names_)),
|
|
|
|
tests_names_regexp(std::move(tests_names_regexp_)),
|
|
|
|
skip_names_regexp(std::move(skip_names_regexp_))
|
2017-05-05 11:36:55 +00:00
|
|
|
{
|
|
|
|
if (input_files.size() < 1)
|
|
|
|
{
|
|
|
|
throw Poco::Exception("No tests were specified", 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
std::cerr << std::fixed << std::setprecision(3);
|
|
|
|
std::cout << std::fixed << std::setprecision(3);
|
2017-05-07 18:55:42 +00:00
|
|
|
processTestsConfigurations(input_files);
|
2017-05-05 11:36:55 +00:00
|
|
|
}
|
2017-01-13 18:26:51 +00:00
|
|
|
|
|
|
|
private:
|
2017-05-05 11:36:55 +00:00
|
|
|
unsigned concurrency;
|
2017-05-05 17:48:11 +00:00
|
|
|
std::string test_name;
|
2017-05-05 11:36:55 +00:00
|
|
|
|
|
|
|
using Query = std::string;
|
|
|
|
using Queries = std::vector<Query>;
|
|
|
|
using QueriesWithIndexes = std::vector<std::pair<Query, size_t>>;
|
|
|
|
Queries queries;
|
|
|
|
|
2017-05-05 12:41:18 +00:00
|
|
|
Connection connection;
|
2017-05-05 11:36:55 +00:00
|
|
|
|
|
|
|
using Keys = std::vector<std::string>;
|
|
|
|
|
|
|
|
Settings settings;
|
|
|
|
|
|
|
|
InterruptListener interrupt_listener;
|
|
|
|
|
|
|
|
double average_speed_precision = 0.001;
|
|
|
|
|
|
|
|
using XMLConfiguration = Poco::Util::XMLConfiguration;
|
|
|
|
using AbstractConfig = Poco::AutoPtr<Poco::Util::AbstractConfiguration>;
|
|
|
|
using Config = Poco::AutoPtr<XMLConfiguration>;
|
2017-05-07 18:55:42 +00:00
|
|
|
|
2017-05-05 11:36:55 +00:00
|
|
|
using Paths = std::vector<std::string>;
|
|
|
|
using StringToVector = std::map<std::string, std::vector<std::string>>;
|
|
|
|
StringToVector substitutions;
|
|
|
|
|
|
|
|
using StringKeyValue = std::map<std::string, std::string>;
|
2017-05-05 17:48:11 +00:00
|
|
|
std::vector<StringKeyValue> substitutions_maps;
|
2017-05-05 11:36:55 +00:00
|
|
|
|
2017-05-05 12:41:18 +00:00
|
|
|
bool gotSIGINT;
|
2017-05-05 17:48:11 +00:00
|
|
|
std::vector<StopCriterions> stop_criterions;
|
2017-05-05 12:41:18 +00:00
|
|
|
std::string main_metric;
|
2017-05-05 15:58:25 +00:00
|
|
|
bool lite_output;
|
2017-05-07 00:29:30 +00:00
|
|
|
std::string profiles_file;
|
2017-05-05 11:36:55 +00:00
|
|
|
|
2017-05-07 18:55:42 +00:00
|
|
|
Strings input_files;
|
|
|
|
std::vector<Config> tests_configurations;
|
|
|
|
|
|
|
|
Strings tests_tags;
|
|
|
|
Strings skip_tags;
|
|
|
|
Strings tests_names;
|
|
|
|
Strings skip_names;
|
|
|
|
Strings tests_names_regexp;
|
|
|
|
Strings skip_names_regexp;
|
|
|
|
|
|
|
|
#define incFulfilledCriterions(index, CRITERION) \
|
|
|
|
if (!stop_criterions[index].CRITERION.fulfilled) \
|
|
|
|
{ \
|
2017-05-05 17:48:11 +00:00
|
|
|
stop_criterions[index].CRITERION.priority == min ? ++stop_criterions[index].fulfilled_criterions_min \
|
2017-05-07 18:55:42 +00:00
|
|
|
: ++stop_criterions[index].fulfilled_criterions_max; \
|
|
|
|
stop_criterions[index].CRITERION.fulfilled = true; \
|
2017-05-05 11:36:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
enum ExecutionType
|
|
|
|
{
|
|
|
|
loop,
|
|
|
|
once
|
|
|
|
};
|
2017-05-05 17:48:11 +00:00
|
|
|
ExecutionType exec_type;
|
2017-05-05 11:36:55 +00:00
|
|
|
|
2017-05-07 18:55:42 +00:00
|
|
|
enum FilterType
|
|
|
|
{
|
|
|
|
tag,
|
|
|
|
name,
|
|
|
|
name_regexp
|
|
|
|
};
|
|
|
|
|
2017-05-05 16:49:14 +00:00
|
|
|
size_t times_to_run = 1;
|
2017-05-05 11:36:55 +00:00
|
|
|
std::vector<Stats> statistics;
|
|
|
|
|
2017-05-07 18:55:42 +00:00
|
|
|
/// Removes configurations that has a given value. If leave is true, the logic is reversed.
|
|
|
|
void removeConfigurationsIf(std::vector<Config> & configs, FilterType filter_type, const Strings & values, bool leave = false)
|
|
|
|
{
|
|
|
|
std::function<bool(Config &)> checker = [&filter_type, &values, &leave](Config & config) {
|
|
|
|
if (values.size() == 0)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
bool remove_or_not = false;
|
|
|
|
|
|
|
|
if (filter_type == tag)
|
|
|
|
{
|
|
|
|
Keys tags_keys;
|
|
|
|
config->keys("tags", tags_keys);
|
|
|
|
|
|
|
|
Strings tags(tags_keys.size());
|
|
|
|
for (size_t i = 0; i != tags_keys.size(); ++i)
|
|
|
|
tags[i] = config->getString("tags.tag[" + std::to_string(i) + "]");
|
|
|
|
|
|
|
|
for (const std::string & config_tag : tags) {
|
|
|
|
if (std::find(values.begin(), values.end(), config_tag) != values.end())
|
|
|
|
remove_or_not = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (filter_type == name)
|
|
|
|
{
|
|
|
|
remove_or_not = (std::find(values.begin(), values.end(), config->getString("name", "")) != values.end());
|
|
|
|
}
|
|
|
|
|
|
|
|
if (filter_type == name_regexp)
|
|
|
|
{
|
|
|
|
std::string config_name = config->getString("name", "");
|
|
|
|
std::function<bool(const std::string &)> regex_checker = [&config_name](const std::string & name_regexp) {
|
|
|
|
std::regex pattern(name_regexp);
|
|
|
|
return std::regex_search(config_name, pattern);
|
|
|
|
};
|
|
|
|
|
|
|
|
remove_or_not = config->has("name") ? (std::find_if(values.begin(), values.end(), regex_checker) != values.end())
|
|
|
|
: false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (leave)
|
|
|
|
remove_or_not = !remove_or_not;
|
|
|
|
return remove_or_not;
|
|
|
|
};
|
|
|
|
|
|
|
|
std::vector<Config>::iterator new_end = std::remove_if(configs.begin(), configs.end(), checker);
|
|
|
|
configs.erase(new_end, configs.end());
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Filter tests by tags, names, regexp matching, etc.
|
|
|
|
void filterConfigurations()
|
|
|
|
{
|
|
|
|
/// Leave tests:
|
|
|
|
removeConfigurationsIf(tests_configurations, FilterType::tag, tests_tags, true);
|
|
|
|
removeConfigurationsIf(tests_configurations, FilterType::name, tests_names, true);
|
|
|
|
removeConfigurationsIf(tests_configurations, FilterType::name_regexp, tests_names_regexp, true);
|
|
|
|
|
|
|
|
|
|
|
|
/// Skip tests
|
|
|
|
removeConfigurationsIf(tests_configurations, FilterType::tag, skip_tags, false);
|
|
|
|
removeConfigurationsIf(tests_configurations, FilterType::name, skip_names, false);
|
|
|
|
removeConfigurationsIf(tests_configurations, FilterType::name_regexp, skip_names_regexp, false);
|
|
|
|
}
|
|
|
|
|
2017-05-08 19:25:38 +00:00
|
|
|
/// Checks specified preconditions per test (process cache, table existence, etc.)
|
|
|
|
bool checkPreconditions(const Config & config)
|
|
|
|
{
|
|
|
|
if (!config->has("preconditions"))
|
|
|
|
return true;
|
|
|
|
|
|
|
|
Keys preconditions;
|
|
|
|
config->keys("preconditions", preconditions);
|
|
|
|
size_t table_precondition_index = 0;
|
|
|
|
|
|
|
|
for (const std::string & precondition : preconditions)
|
|
|
|
{
|
|
|
|
if (precondition == "reset_cpu_cache")
|
|
|
|
if (system("(>&2 echo 'Flushing cache...') && (sudo sh -c 'echo 3 > /proc/sys/vm/drop_caches') && (>&2 echo 'Flushed.')"))
|
|
|
|
std::cerr << "Failed to flush cache" << std::endl;
|
|
|
|
|
|
|
|
if (precondition == "ram_size")
|
|
|
|
{
|
|
|
|
struct sysinfo *system_information = new struct sysinfo();
|
|
|
|
if (sysinfo(system_information))
|
|
|
|
{
|
|
|
|
std::cerr << "Failed to check system RAM size" << std::endl;
|
|
|
|
delete system_information;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
size_t ram_size_needed = config->getUInt64("preconditions.ram_size");
|
|
|
|
size_t actual_ram = system_information->totalram / 1024 / 1024;
|
|
|
|
if (ram_size_needed > actual_ram)
|
|
|
|
{
|
|
|
|
std::cerr << "Not enough RAM" << std::endl;
|
|
|
|
delete system_information;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (precondition == "table_exists")
|
|
|
|
{
|
|
|
|
std::string precondition_key = "preconditions.table_exists[" + std::to_string(table_precondition_index++) + "]";
|
|
|
|
std::string table_to_check = config->getString(precondition_key);
|
|
|
|
std::string query = "EXISTS TABLE " + table_to_check + ";";
|
|
|
|
|
|
|
|
size_t exist = 0;
|
|
|
|
|
|
|
|
connection.sendQuery(query, "", QueryProcessingStage::Complete, &settings, nullptr, false);
|
|
|
|
|
|
|
|
while (true)
|
|
|
|
{
|
|
|
|
Connection::Packet packet = connection.receivePacket();
|
|
|
|
|
|
|
|
if (packet.type == Protocol::Server::Data) {
|
|
|
|
for (const ColumnWithTypeAndName & column : packet.block.getColumns())
|
|
|
|
{
|
|
|
|
if (column.name == "result" && column.column->getDataAt(0).data != nullptr) {
|
|
|
|
exist = column.column->get64(0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (packet.type == Protocol::Server::Exception || packet.type == Protocol::Server::EndOfStream)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (exist == 0) {
|
|
|
|
std::cerr << "Table " + table_to_check + " doesn't exist" << std::endl;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2017-05-07 18:55:42 +00:00
|
|
|
void processTestsConfigurations(const Paths & input_files)
|
2017-05-05 11:36:55 +00:00
|
|
|
{
|
2017-05-05 17:48:11 +00:00
|
|
|
tests_configurations.resize(input_files.size());
|
2017-05-05 11:36:55 +00:00
|
|
|
|
|
|
|
for (size_t i = 0; i != input_files.size(); ++i)
|
|
|
|
{
|
|
|
|
const std::string path = input_files[i];
|
2017-05-05 17:48:11 +00:00
|
|
|
tests_configurations[i] = Config(new XMLConfiguration(path));
|
2017-05-05 11:36:55 +00:00
|
|
|
}
|
|
|
|
|
2017-05-07 18:55:42 +00:00
|
|
|
filterConfigurations();
|
2017-05-05 11:36:55 +00:00
|
|
|
|
2017-05-05 17:48:11 +00:00
|
|
|
if (tests_configurations.size())
|
2017-05-05 11:36:55 +00:00
|
|
|
{
|
2017-05-07 01:29:24 +00:00
|
|
|
Strings outputs;
|
|
|
|
|
2017-05-05 17:48:11 +00:00
|
|
|
for (auto & test_config : tests_configurations)
|
2017-05-05 11:36:55 +00:00
|
|
|
{
|
2017-05-08 19:25:38 +00:00
|
|
|
if (!checkPreconditions(test_config))
|
|
|
|
{
|
|
|
|
std::cerr << "Preconditions are not fulfilled for test \"" + test_config->getString("name", "") + "\"";
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2017-05-07 01:29:24 +00:00
|
|
|
std::string output = runTest(test_config);
|
|
|
|
if (lite_output)
|
|
|
|
std::cout << output << std::endl;
|
|
|
|
else
|
|
|
|
outputs.push_back(output);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!lite_output && outputs.size())
|
|
|
|
{
|
|
|
|
std::cout << "[" << std::endl;
|
|
|
|
|
|
|
|
for (size_t i = 0; i != outputs.size(); ++i)
|
|
|
|
{
|
|
|
|
std::cout << outputs[i];
|
|
|
|
if (i != outputs.size() - 1)
|
|
|
|
std::cout << ",";
|
|
|
|
|
|
|
|
std::cout << std::endl;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::cout << "]" << std::endl;
|
2017-05-05 11:36:55 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-05-07 00:29:30 +00:00
|
|
|
void extractSettings(const Config & config, const std::string & key,
|
|
|
|
const Strings & settings_list,
|
|
|
|
std::map<std::string, std::string> settings_to_apply)
|
|
|
|
{
|
|
|
|
for (const std::string & setup : settings_list)
|
|
|
|
{
|
|
|
|
if (setup == "profile")
|
|
|
|
continue;
|
|
|
|
|
|
|
|
std::string value = config->getString(key + "." + setup);
|
|
|
|
if (value.empty())
|
|
|
|
value = "true";
|
|
|
|
|
|
|
|
settings_to_apply[setup] = value;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-05-07 01:29:24 +00:00
|
|
|
std::string runTest(Config & test_config)
|
2017-05-05 11:36:55 +00:00
|
|
|
{
|
2017-05-06 22:38:14 +00:00
|
|
|
queries.clear();
|
|
|
|
|
2017-05-05 17:48:11 +00:00
|
|
|
test_name = test_config->getString("name");
|
2017-05-07 01:29:24 +00:00
|
|
|
std::cerr << "Running: " << test_name << "\n";
|
2017-05-05 11:36:55 +00:00
|
|
|
|
2017-05-05 17:48:11 +00:00
|
|
|
if (test_config->has("settings"))
|
2017-05-05 11:36:55 +00:00
|
|
|
{
|
2017-05-07 00:29:30 +00:00
|
|
|
std::map<std::string, std::string> settings_to_apply;
|
2017-05-05 17:48:11 +00:00
|
|
|
Keys config_settings;
|
|
|
|
test_config->keys("settings", config_settings);
|
2017-05-05 11:36:55 +00:00
|
|
|
|
2017-05-07 00:29:30 +00:00
|
|
|
/// Preprocess configuration file
|
|
|
|
if (std::find(config_settings.begin(), config_settings.end(), "profile") != config_settings.end())
|
|
|
|
{
|
|
|
|
if (!profiles_file.empty())
|
|
|
|
{
|
|
|
|
std::string profile_name = test_config->getString("settings.profile");
|
|
|
|
Config profiles_config(new XMLConfiguration(profiles_file));
|
|
|
|
|
|
|
|
Keys profile_settings;
|
|
|
|
profiles_config->keys("profiles." + profile_name, profile_settings);
|
|
|
|
|
|
|
|
extractSettings(profiles_config, "profiles." + profile_name, profile_settings, settings_to_apply);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
extractSettings(test_config, "settings", config_settings, settings_to_apply);
|
|
|
|
|
2017-05-05 11:36:55 +00:00
|
|
|
/// This macro goes through all settings in the Settings.h
|
|
|
|
/// and, if found any settings in test's xml configuration
|
|
|
|
/// with the same name, sets its value to settings
|
2017-05-07 00:29:30 +00:00
|
|
|
std::map<std::string, std::string>::iterator it;
|
|
|
|
#define EXTRACT_SETTING(TYPE, NAME, DEFAULT) \
|
|
|
|
it = settings_to_apply.find(#NAME); \
|
|
|
|
if (it != settings_to_apply.end()) \
|
|
|
|
settings.set(#NAME, settings_to_apply[#NAME]);
|
2017-05-05 11:36:55 +00:00
|
|
|
|
2017-05-07 00:29:30 +00:00
|
|
|
APPLY_FOR_SETTINGS(EXTRACT_SETTING)
|
|
|
|
APPLY_FOR_LIMITS(EXTRACT_SETTING)
|
|
|
|
|
|
|
|
#undef EXTRACT_SETTING
|
2017-05-05 11:36:55 +00:00
|
|
|
|
2017-05-05 17:48:11 +00:00
|
|
|
if (std::find(config_settings.begin(), config_settings.end(), "average_rows_speed_precision") != config_settings.end())
|
2017-05-05 11:36:55 +00:00
|
|
|
{
|
2017-05-05 17:48:11 +00:00
|
|
|
Stats::avg_rows_speed_precision = test_config->getDouble("settings.average_rows_speed_precision");
|
2017-05-05 11:36:55 +00:00
|
|
|
}
|
|
|
|
|
2017-05-05 17:48:11 +00:00
|
|
|
if (std::find(config_settings.begin(), config_settings.end(), "average_bytes_speed_precision") != config_settings.end())
|
2017-05-05 11:36:55 +00:00
|
|
|
{
|
2017-05-05 17:48:11 +00:00
|
|
|
Stats::avg_bytes_speed_precision = test_config->getDouble("settings.average_bytes_speed_precision");
|
2017-05-05 11:36:55 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Query query;
|
|
|
|
|
2017-05-06 14:36:37 +00:00
|
|
|
if (!test_config->has("query") && !test_config->has("query_file"))
|
|
|
|
{
|
|
|
|
throw Poco::Exception("Missing query fields in test's config: " + test_name, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (test_config->has("query") && test_config->has("query_file"))
|
2017-05-05 11:36:55 +00:00
|
|
|
{
|
2017-05-06 14:36:37 +00:00
|
|
|
throw Poco::Exception("Found both query and query_file fields. Choose only one", 1);
|
2017-05-05 11:36:55 +00:00
|
|
|
}
|
|
|
|
|
2017-05-06 14:36:37 +00:00
|
|
|
if (test_config->has("query"))
|
|
|
|
queries.push_back(test_config->getString("query"));
|
|
|
|
|
|
|
|
if (test_config->has("query_file"))
|
|
|
|
{
|
|
|
|
const std::string filename = test_config->getString("query_file");
|
|
|
|
if (filename.empty())
|
|
|
|
throw Poco::Exception("Empty file name", 1);
|
|
|
|
|
|
|
|
bool tsv = FS::path(filename).extension().string() == ".tsv";
|
|
|
|
|
|
|
|
ReadBufferFromFile query_file(filename);
|
|
|
|
while (!query_file.eof())
|
|
|
|
{
|
2017-05-06 22:25:18 +00:00
|
|
|
tsv ? readEscapedString(query, query_file, true)
|
|
|
|
: readString(query, query_file, true);
|
|
|
|
|
|
|
|
if (!query.empty())
|
|
|
|
queries.push_back(query);
|
2017-05-06 14:36:37 +00:00
|
|
|
}
|
|
|
|
}
|
2017-05-05 11:36:55 +00:00
|
|
|
|
2017-05-06 14:36:37 +00:00
|
|
|
if (queries.empty())
|
2017-05-05 11:36:55 +00:00
|
|
|
{
|
2017-05-06 14:36:37 +00:00
|
|
|
throw Poco::Exception("Did not find any query to execute: " + test_name, 1);
|
2017-05-05 11:36:55 +00:00
|
|
|
}
|
|
|
|
|
2017-05-05 17:48:11 +00:00
|
|
|
if (test_config->has("substitutions"))
|
2017-05-05 11:36:55 +00:00
|
|
|
{
|
2017-05-06 22:38:14 +00:00
|
|
|
if (queries.size() > 1)
|
|
|
|
throw Poco::Exception("Only one query is allowed when using substitutions", 1);
|
|
|
|
|
2017-05-05 11:36:55 +00:00
|
|
|
/// Make "subconfig" of inner xml block
|
2017-05-05 17:48:11 +00:00
|
|
|
AbstractConfig substitutions_view(test_config->createView("substitutions"));
|
|
|
|
constructSubstitutions(substitutions_view, substitutions);
|
2017-05-05 11:36:55 +00:00
|
|
|
|
2017-05-06 22:38:14 +00:00
|
|
|
queries = formatQueries(queries[0], substitutions);
|
2017-05-05 11:36:55 +00:00
|
|
|
}
|
|
|
|
|
2017-05-05 17:48:11 +00:00
|
|
|
if (!test_config->has("type"))
|
2017-05-05 11:36:55 +00:00
|
|
|
{
|
2017-05-05 17:48:11 +00:00
|
|
|
throw Poco::Exception("Missing type property in config: " + test_name, 1);
|
2017-05-05 11:36:55 +00:00
|
|
|
}
|
|
|
|
|
2017-05-05 17:48:11 +00:00
|
|
|
std::string config_exec_type = test_config->getString("type");
|
|
|
|
if (config_exec_type == "loop")
|
|
|
|
exec_type = loop;
|
|
|
|
else if (config_exec_type == "once")
|
|
|
|
exec_type = once;
|
2017-05-05 11:36:55 +00:00
|
|
|
else
|
2017-05-05 17:48:11 +00:00
|
|
|
throw Poco::Exception("Unknown type " + config_exec_type + " in :" + test_name, 1);
|
2017-05-05 11:36:55 +00:00
|
|
|
|
2017-05-05 17:48:11 +00:00
|
|
|
if (test_config->has("times_to_run"))
|
2017-05-05 11:36:55 +00:00
|
|
|
{
|
2017-05-05 17:48:11 +00:00
|
|
|
times_to_run = test_config->getUInt("times_to_run");
|
2017-05-05 11:36:55 +00:00
|
|
|
}
|
|
|
|
|
2017-05-05 17:48:11 +00:00
|
|
|
stop_criterions.resize(times_to_run * queries.size());
|
2017-05-05 11:36:55 +00:00
|
|
|
|
2017-05-05 17:48:11 +00:00
|
|
|
if (test_config->has("stop"))
|
2017-05-05 11:36:55 +00:00
|
|
|
{
|
2017-05-05 17:48:11 +00:00
|
|
|
AbstractConfig stop_criterions_view(test_config->createView("stop"));
|
|
|
|
for (StopCriterions & stop_criterion : stop_criterions)
|
2017-05-05 11:36:55 +00:00
|
|
|
{
|
2017-05-05 17:48:11 +00:00
|
|
|
stop_criterion.loadFromConfig(stop_criterions_view);
|
2017-05-05 11:36:55 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
throw Poco::Exception("No termination conditions were found in config", 1);
|
|
|
|
}
|
|
|
|
|
2017-05-05 17:48:11 +00:00
|
|
|
AbstractConfig metrics_view(test_config->createView("metrics"));
|
2017-05-05 11:36:55 +00:00
|
|
|
Keys metrics;
|
2017-05-05 17:48:11 +00:00
|
|
|
metrics_view->keys(metrics);
|
2017-05-07 01:29:24 +00:00
|
|
|
|
|
|
|
if (test_config->has("main_metric"))
|
|
|
|
{
|
|
|
|
Keys main_metrics;
|
|
|
|
test_config->keys("main_metric", main_metrics);
|
|
|
|
if (main_metrics.size())
|
|
|
|
main_metric = main_metrics[0];
|
|
|
|
}
|
2017-05-05 11:36:55 +00:00
|
|
|
|
2017-05-08 19:25:38 +00:00
|
|
|
if (!main_metric.empty())
|
|
|
|
{
|
2017-05-05 15:58:25 +00:00
|
|
|
if (std::find(metrics.begin(), metrics.end(), main_metric) == metrics.end())
|
|
|
|
metrics.push_back(main_metric);
|
2017-05-08 19:25:38 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-05-05 15:58:25 +00:00
|
|
|
if (lite_output)
|
|
|
|
throw Poco::Exception("Specify main_metric for lite output", 1);
|
2017-05-05 11:36:55 +00:00
|
|
|
}
|
2017-05-05 15:58:25 +00:00
|
|
|
|
|
|
|
if (metrics.size() > 0)
|
|
|
|
checkMetricsInput(metrics);
|
2017-05-05 11:36:55 +00:00
|
|
|
|
2017-05-05 16:49:14 +00:00
|
|
|
statistics.resize(times_to_run * queries.size());
|
2017-05-05 17:48:11 +00:00
|
|
|
for (size_t number_of_launch = 0; number_of_launch < times_to_run; ++number_of_launch)
|
2017-05-05 11:36:55 +00:00
|
|
|
{
|
2017-05-05 17:48:11 +00:00
|
|
|
QueriesWithIndexes queries_with_indexes;
|
2017-05-05 11:36:55 +00:00
|
|
|
|
2017-05-05 17:48:11 +00:00
|
|
|
for (size_t query_index = 0; query_index < queries.size(); ++query_index)
|
2017-05-05 11:36:55 +00:00
|
|
|
{
|
2017-05-05 17:48:11 +00:00
|
|
|
size_t statistic_index = number_of_launch * queries.size() + query_index;
|
|
|
|
stop_criterions[statistic_index].reset();
|
2017-05-05 11:36:55 +00:00
|
|
|
|
2017-05-05 17:48:11 +00:00
|
|
|
queries_with_indexes.push_back({queries[query_index], statistic_index});
|
2017-05-05 11:36:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (interrupt_listener.check())
|
|
|
|
gotSIGINT = true;
|
|
|
|
|
|
|
|
if (gotSIGINT)
|
|
|
|
break;
|
|
|
|
|
2017-05-05 17:48:11 +00:00
|
|
|
runQueries(queries_with_indexes);
|
2017-05-05 11:36:55 +00:00
|
|
|
}
|
|
|
|
|
2017-05-05 15:58:25 +00:00
|
|
|
if (lite_output)
|
2017-05-07 01:29:24 +00:00
|
|
|
return minOutput(main_metric);
|
2017-05-05 11:36:55 +00:00
|
|
|
else
|
2017-05-09 17:17:24 +00:00
|
|
|
return constructTotalInfo(metrics);
|
2017-05-05 11:36:55 +00:00
|
|
|
}
|
|
|
|
|
2017-05-05 15:58:25 +00:00
|
|
|
void checkMetricsInput(const Strings & metrics) const
|
2017-05-05 11:36:55 +00:00
|
|
|
{
|
2017-05-05 17:48:11 +00:00
|
|
|
std::vector<std::string> loop_metrics
|
2017-05-05 11:36:55 +00:00
|
|
|
= {"min_time", "quantiles", "total_time", "queries_per_second", "rows_per_second", "bytes_per_second"};
|
|
|
|
|
2017-05-05 17:48:11 +00:00
|
|
|
std::vector<std::string> non_loop_metrics
|
2017-05-05 11:36:55 +00:00
|
|
|
= {"max_rows_per_second", "max_bytes_per_second", "avg_rows_per_second", "avg_bytes_per_second"};
|
|
|
|
|
2017-05-05 17:48:11 +00:00
|
|
|
if (exec_type == loop)
|
2017-05-05 11:36:55 +00:00
|
|
|
{
|
2017-05-05 12:41:18 +00:00
|
|
|
for (const std::string & metric : metrics)
|
2017-05-05 11:36:55 +00:00
|
|
|
{
|
2017-05-05 17:48:11 +00:00
|
|
|
if (std::find(non_loop_metrics.begin(), non_loop_metrics.end(), metric) != non_loop_metrics.end())
|
2017-05-05 12:41:18 +00:00
|
|
|
{
|
|
|
|
throw Poco::Exception("Wrong type of metric for loop execution type (" + metric + ")", 1);
|
|
|
|
}
|
2017-05-05 11:36:55 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-05-05 12:41:18 +00:00
|
|
|
for (const std::string & metric : metrics)
|
2017-05-05 11:36:55 +00:00
|
|
|
{
|
2017-05-05 17:48:11 +00:00
|
|
|
if (std::find(loop_metrics.begin(), loop_metrics.end(), metric) != loop_metrics.end())
|
2017-05-05 12:41:18 +00:00
|
|
|
{
|
|
|
|
throw Poco::Exception("Wrong type of metric for non-loop execution type (" + metric + ")", 1);
|
|
|
|
}
|
2017-05-05 11:36:55 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-05-05 17:48:11 +00:00
|
|
|
void runQueries(const QueriesWithIndexes & queries_with_indexes)
|
2017-05-05 11:36:55 +00:00
|
|
|
{
|
2017-05-05 17:48:11 +00:00
|
|
|
for (const std::pair<Query, const size_t> & query_and_index : queries_with_indexes)
|
2017-05-05 11:36:55 +00:00
|
|
|
{
|
2017-05-05 17:48:11 +00:00
|
|
|
Query query = query_and_index.first;
|
|
|
|
const size_t statistic_index = query_and_index.second;
|
2017-05-05 11:36:55 +00:00
|
|
|
|
2017-05-05 17:48:11 +00:00
|
|
|
size_t max_iterations = stop_criterions[statistic_index].iterations.value;
|
2017-05-05 11:36:55 +00:00
|
|
|
size_t iteration = 0;
|
|
|
|
|
2017-05-05 17:48:11 +00:00
|
|
|
statistics[statistic_index].clear();
|
|
|
|
execute(query, statistic_index);
|
2017-05-05 11:36:55 +00:00
|
|
|
|
2017-05-05 17:48:11 +00:00
|
|
|
if (exec_type == loop)
|
2017-05-05 11:36:55 +00:00
|
|
|
{
|
|
|
|
while (!gotSIGINT)
|
|
|
|
{
|
|
|
|
++iteration;
|
|
|
|
|
|
|
|
/// check stop criterions
|
|
|
|
if (max_iterations && iteration >= max_iterations)
|
|
|
|
{
|
2017-05-05 17:48:11 +00:00
|
|
|
incFulfilledCriterions(statistic_index, iterations);
|
2017-05-05 11:36:55 +00:00
|
|
|
}
|
|
|
|
|
2017-05-05 17:48:11 +00:00
|
|
|
if (stop_criterions[statistic_index].number_of_initialized_min
|
|
|
|
&& (stop_criterions[statistic_index].fulfilled_criterions_min
|
|
|
|
>= stop_criterions[statistic_index].number_of_initialized_min))
|
2017-05-05 11:36:55 +00:00
|
|
|
{
|
|
|
|
/// All 'min' criterions are fulfilled
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2017-05-05 17:48:11 +00:00
|
|
|
if (stop_criterions[statistic_index].number_of_initialized_max && stop_criterions[statistic_index].fulfilled_criterions_max)
|
2017-05-05 11:36:55 +00:00
|
|
|
{
|
|
|
|
/// Some 'max' criterions are fulfilled
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2017-05-05 17:48:11 +00:00
|
|
|
execute(query, statistic_index);
|
2017-05-05 11:36:55 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!gotSIGINT)
|
|
|
|
{
|
2017-05-05 17:48:11 +00:00
|
|
|
statistics[statistic_index].ready = true;
|
2017-05-05 11:36:55 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-05-05 17:48:11 +00:00
|
|
|
void execute(const Query & query, const size_t statistic_index)
|
2017-05-05 11:36:55 +00:00
|
|
|
{
|
2017-05-05 17:48:11 +00:00
|
|
|
statistics[statistic_index].watch_per_query.restart();
|
2017-05-05 11:36:55 +00:00
|
|
|
|
2017-05-05 12:41:18 +00:00
|
|
|
RemoteBlockInputStream stream(connection, query, &settings, nullptr, Tables() /*, query_processing_stage*/);
|
2017-05-05 11:36:55 +00:00
|
|
|
|
|
|
|
Progress progress;
|
2017-05-05 17:48:11 +00:00
|
|
|
stream.setProgressCallback([&progress, &stream, statistic_index, this](const Progress & value) {
|
2017-05-05 11:36:55 +00:00
|
|
|
progress.incrementPiecewiseAtomically(value);
|
|
|
|
|
2017-05-05 17:48:11 +00:00
|
|
|
this->checkFulfilledCriterionsAndUpdate(progress, stream, statistic_index);
|
2017-05-05 11:36:55 +00:00
|
|
|
});
|
|
|
|
|
2017-05-05 12:41:18 +00:00
|
|
|
stream.readPrefix();
|
|
|
|
while (Block block = stream.read())
|
2017-05-05 11:36:55 +00:00
|
|
|
;
|
2017-05-05 12:41:18 +00:00
|
|
|
stream.readSuffix();
|
2017-05-05 11:36:55 +00:00
|
|
|
|
2017-05-05 17:48:11 +00:00
|
|
|
statistics[statistic_index].updateQueryInfo();
|
|
|
|
statistics[statistic_index].setTotalTime();
|
2017-05-05 11:36:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void checkFulfilledCriterionsAndUpdate(const Progress & progress,
|
2017-05-05 12:41:18 +00:00
|
|
|
RemoteBlockInputStream & stream,
|
2017-05-05 17:48:11 +00:00
|
|
|
const size_t statistic_index)
|
2017-05-05 11:36:55 +00:00
|
|
|
{
|
2017-05-05 17:48:11 +00:00
|
|
|
statistics[statistic_index].add(progress.rows, progress.bytes);
|
2017-05-05 11:36:55 +00:00
|
|
|
|
2017-05-05 17:48:11 +00:00
|
|
|
size_t max_rows_to_read = stop_criterions[statistic_index].rows_read.value;
|
|
|
|
if (max_rows_to_read && statistics[statistic_index].rows_read >= max_rows_to_read)
|
2017-05-05 11:36:55 +00:00
|
|
|
{
|
2017-05-05 17:48:11 +00:00
|
|
|
incFulfilledCriterions(statistic_index, rows_read);
|
2017-05-05 11:36:55 +00:00
|
|
|
}
|
|
|
|
|
2017-05-05 17:48:11 +00:00
|
|
|
size_t max_bytes_to_read = stop_criterions[statistic_index].bytes_read_uncompressed.value;
|
|
|
|
if (max_bytes_to_read && statistics[statistic_index].bytes_read >= max_bytes_to_read)
|
2017-05-05 11:36:55 +00:00
|
|
|
{
|
2017-05-05 17:48:11 +00:00
|
|
|
incFulfilledCriterions(statistic_index, bytes_read_uncompressed);
|
2017-05-05 11:36:55 +00:00
|
|
|
}
|
|
|
|
|
2017-05-05 17:48:11 +00:00
|
|
|
if (UInt64 max_timeout_ms = stop_criterions[statistic_index].timeout_ms.value)
|
2017-05-05 11:36:55 +00:00
|
|
|
{
|
|
|
|
/// cast nanoseconds to ms
|
2017-05-05 17:48:11 +00:00
|
|
|
if ((statistics[statistic_index].watch.elapsed() / (1000 * 1000)) > max_timeout_ms)
|
2017-05-05 11:36:55 +00:00
|
|
|
{
|
2017-05-05 17:48:11 +00:00
|
|
|
incFulfilledCriterions(statistic_index, timeout_ms);
|
2017-05-05 11:36:55 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-05-05 17:48:11 +00:00
|
|
|
size_t min_time_not_changing_for_ms = stop_criterions[statistic_index].min_time_not_changing_for_ms.value;
|
2017-05-05 11:36:55 +00:00
|
|
|
if (min_time_not_changing_for_ms)
|
|
|
|
{
|
2017-05-05 17:48:11 +00:00
|
|
|
size_t min_time_did_not_change_for = statistics[statistic_index].min_time_watch.elapsed() / (1000 * 1000);
|
2017-05-05 11:36:55 +00:00
|
|
|
|
|
|
|
if (min_time_did_not_change_for >= min_time_not_changing_for_ms)
|
|
|
|
{
|
2017-05-05 17:48:11 +00:00
|
|
|
incFulfilledCriterions(statistic_index, min_time_not_changing_for_ms);
|
2017-05-05 11:36:55 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-05-05 17:48:11 +00:00
|
|
|
size_t max_speed_not_changing_for_ms = stop_criterions[statistic_index].max_speed_not_changing_for_ms.value;
|
2017-05-05 11:36:55 +00:00
|
|
|
if (max_speed_not_changing_for_ms)
|
|
|
|
{
|
2017-05-05 17:48:11 +00:00
|
|
|
UInt64 speed_not_changing_time = statistics[statistic_index].max_rows_speed_watch.elapsed() / (1000 * 1000);
|
2017-05-05 11:36:55 +00:00
|
|
|
if (speed_not_changing_time >= max_speed_not_changing_for_ms)
|
|
|
|
{
|
2017-05-05 17:48:11 +00:00
|
|
|
incFulfilledCriterions(statistic_index, max_speed_not_changing_for_ms);
|
2017-05-05 11:36:55 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-05-05 17:48:11 +00:00
|
|
|
size_t average_speed_not_changing_for_ms = stop_criterions[statistic_index].average_speed_not_changing_for_ms.value;
|
2017-05-05 11:36:55 +00:00
|
|
|
if (average_speed_not_changing_for_ms)
|
|
|
|
{
|
2017-05-05 17:48:11 +00:00
|
|
|
UInt64 speed_not_changing_time = statistics[statistic_index].avg_rows_speed_watch.elapsed() / (1000 * 1000);
|
2017-05-05 11:36:55 +00:00
|
|
|
if (speed_not_changing_time >= average_speed_not_changing_for_ms)
|
|
|
|
{
|
2017-05-05 17:48:11 +00:00
|
|
|
incFulfilledCriterions(statistic_index, average_speed_not_changing_for_ms);
|
2017-05-05 11:36:55 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-05-05 17:48:11 +00:00
|
|
|
if (stop_criterions[statistic_index].number_of_initialized_min
|
|
|
|
&& (stop_criterions[statistic_index].fulfilled_criterions_min >= stop_criterions[statistic_index].number_of_initialized_min))
|
2017-05-05 11:36:55 +00:00
|
|
|
{
|
|
|
|
/// All 'min' criterions are fulfilled
|
2017-05-05 12:41:18 +00:00
|
|
|
stream.cancel();
|
2017-05-05 11:36:55 +00:00
|
|
|
}
|
|
|
|
|
2017-05-05 17:48:11 +00:00
|
|
|
if (stop_criterions[statistic_index].number_of_initialized_max && stop_criterions[statistic_index].fulfilled_criterions_max)
|
2017-05-05 11:36:55 +00:00
|
|
|
{
|
|
|
|
/// Some 'max' criterions are fulfilled
|
2017-05-05 12:41:18 +00:00
|
|
|
stream.cancel();
|
2017-05-05 11:36:55 +00:00
|
|
|
}
|
|
|
|
|
2017-05-05 12:41:18 +00:00
|
|
|
if (interrupt_listener.check())
|
|
|
|
{
|
2017-05-05 11:36:55 +00:00
|
|
|
gotSIGINT = true;
|
2017-05-05 12:41:18 +00:00
|
|
|
stream.cancel();
|
2017-05-05 11:36:55 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-05-05 17:48:11 +00:00
|
|
|
void constructSubstitutions(AbstractConfig & substitutions_view, StringToVector & substitutions)
|
2017-05-05 11:36:55 +00:00
|
|
|
{
|
|
|
|
Keys xml_substitutions;
|
2017-05-05 17:48:11 +00:00
|
|
|
substitutions_view->keys(xml_substitutions);
|
2017-05-05 11:36:55 +00:00
|
|
|
|
|
|
|
for (size_t i = 0; i != xml_substitutions.size(); ++i)
|
|
|
|
{
|
2017-05-05 17:48:11 +00:00
|
|
|
const AbstractConfig xml_substitution(substitutions_view->createView("substitution[" + std::to_string(i) + "]"));
|
2017-05-05 11:36:55 +00:00
|
|
|
|
|
|
|
/// Property values for substitution will be stored in a vector
|
|
|
|
/// accessible by property name
|
|
|
|
std::vector<std::string> xml_values;
|
|
|
|
xml_substitution->keys("values", xml_values);
|
|
|
|
|
|
|
|
std::string name = xml_substitution->getString("name");
|
|
|
|
|
|
|
|
for (size_t j = 0; j != xml_values.size(); ++j)
|
|
|
|
{
|
|
|
|
substitutions[name].push_back(xml_substitution->getString("values.value[" + std::to_string(j) + "]"));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
std::vector<std::string> formatQueries(const std::string & query, StringToVector substitutions)
|
|
|
|
{
|
|
|
|
std::vector<std::string> queries;
|
|
|
|
|
|
|
|
StringToVector::iterator substitutions_first = substitutions.begin();
|
|
|
|
StringToVector::iterator substitutions_last = substitutions.end();
|
|
|
|
--substitutions_last;
|
|
|
|
|
2017-05-05 17:48:11 +00:00
|
|
|
std::map<std::string, std::string> substitutions_map;
|
2017-05-05 11:36:55 +00:00
|
|
|
|
2017-05-05 17:48:11 +00:00
|
|
|
runThroughAllOptionsAndPush(substitutions_first, substitutions_last, query, queries, substitutions_map);
|
2017-05-05 11:36:55 +00:00
|
|
|
|
|
|
|
return queries;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Recursive method which goes through all substitution blocks in xml
|
|
|
|
/// and replaces property {names} by their values
|
|
|
|
void runThroughAllOptionsAndPush(StringToVector::iterator substitutions_left,
|
|
|
|
StringToVector::iterator substitutions_right,
|
|
|
|
const std::string & template_query,
|
|
|
|
std::vector<std::string> & queries,
|
2017-05-05 17:48:11 +00:00
|
|
|
const StringKeyValue & template_substitutions_map = StringKeyValue())
|
2017-05-05 11:36:55 +00:00
|
|
|
{
|
|
|
|
std::string name = substitutions_left->first;
|
|
|
|
std::vector<std::string> values = substitutions_left->second;
|
|
|
|
|
|
|
|
for (const std::string & value : values)
|
|
|
|
{
|
|
|
|
/// Copy query string for each unique permutation
|
|
|
|
Query query = template_query;
|
2017-05-05 17:48:11 +00:00
|
|
|
StringKeyValue substitutions_map = template_substitutions_map;
|
|
|
|
size_t substr_pos = 0;
|
2017-05-05 11:36:55 +00:00
|
|
|
|
2017-05-05 17:48:11 +00:00
|
|
|
while (substr_pos != std::string::npos)
|
2017-05-05 11:36:55 +00:00
|
|
|
{
|
2017-05-05 17:48:11 +00:00
|
|
|
substr_pos = query.find("{" + name + "}");
|
2017-05-05 11:36:55 +00:00
|
|
|
|
2017-05-05 17:48:11 +00:00
|
|
|
if (substr_pos != std::string::npos)
|
2017-05-05 11:36:55 +00:00
|
|
|
{
|
2017-05-05 17:48:11 +00:00
|
|
|
query.replace(substr_pos, 1 + name.length() + 1, value);
|
2017-05-05 11:36:55 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-05-05 17:48:11 +00:00
|
|
|
substitutions_map[name] = value;
|
2017-05-05 11:36:55 +00:00
|
|
|
|
|
|
|
/// If we've reached the end of substitution chain
|
|
|
|
if (substitutions_left == substitutions_right)
|
|
|
|
{
|
|
|
|
queries.push_back(query);
|
2017-05-05 17:48:11 +00:00
|
|
|
substitutions_maps.push_back(substitutions_map);
|
2017-05-05 11:36:55 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
StringToVector::iterator next_it = substitutions_left;
|
|
|
|
++next_it;
|
|
|
|
|
2017-05-05 17:48:11 +00:00
|
|
|
runThroughAllOptionsAndPush(next_it, substitutions_right, query, queries, substitutions_map);
|
2017-05-05 11:36:55 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2017-02-24 22:02:08 +00:00
|
|
|
|
|
|
|
public:
|
2017-05-09 17:17:24 +00:00
|
|
|
std::string constructTotalInfo(Strings metrics)
|
2017-05-05 11:36:55 +00:00
|
|
|
{
|
2017-05-05 17:48:11 +00:00
|
|
|
JSONString json_output;
|
2017-05-05 11:36:55 +00:00
|
|
|
std::string hostname;
|
|
|
|
|
|
|
|
char hostname_buffer[256];
|
|
|
|
if (gethostname(hostname_buffer, 256) == 0)
|
|
|
|
{
|
|
|
|
hostname = std::string(hostname_buffer);
|
|
|
|
}
|
|
|
|
|
2017-05-05 17:48:11 +00:00
|
|
|
json_output["hostname"].set(hostname);
|
|
|
|
json_output["Number of CPUs"].set(sysconf(_SC_NPROCESSORS_ONLN));
|
|
|
|
json_output["test_name"].set(test_name);
|
|
|
|
json_output["main_metric"].set(main_metric);
|
2017-05-05 11:36:55 +00:00
|
|
|
|
|
|
|
if (substitutions.size())
|
|
|
|
{
|
2017-05-05 17:48:11 +00:00
|
|
|
JSONString json_parameters(2); /// here, 2 is the size of \t padding
|
2017-05-05 11:36:55 +00:00
|
|
|
|
|
|
|
for (auto it = substitutions.begin(); it != substitutions.end(); ++it)
|
|
|
|
{
|
|
|
|
std::string parameter = it->first;
|
|
|
|
std::vector<std::string> values = it->second;
|
|
|
|
|
2017-05-05 17:48:11 +00:00
|
|
|
std::string array_string = "[";
|
2017-05-05 11:36:55 +00:00
|
|
|
for (size_t i = 0; i != values.size(); ++i)
|
|
|
|
{
|
2017-05-05 17:48:11 +00:00
|
|
|
array_string += '\"' + values[i] + '\"';
|
2017-05-05 11:36:55 +00:00
|
|
|
if (i != values.size() - 1)
|
|
|
|
{
|
2017-05-05 17:48:11 +00:00
|
|
|
array_string += ", ";
|
2017-05-05 11:36:55 +00:00
|
|
|
}
|
|
|
|
}
|
2017-05-05 17:48:11 +00:00
|
|
|
array_string += ']';
|
2017-05-05 11:36:55 +00:00
|
|
|
|
2017-05-05 17:48:11 +00:00
|
|
|
json_parameters[parameter].set(array_string);
|
2017-05-05 11:36:55 +00:00
|
|
|
}
|
|
|
|
|
2017-05-05 17:48:11 +00:00
|
|
|
json_output["parameters"].set(json_parameters);
|
2017-05-05 11:36:55 +00:00
|
|
|
}
|
|
|
|
|
2017-05-05 17:48:11 +00:00
|
|
|
std::vector<JSONString> run_infos;
|
|
|
|
for (size_t query_index = 0; query_index < queries.size(); ++query_index)
|
2017-05-05 11:36:55 +00:00
|
|
|
{
|
2017-05-05 17:48:11 +00:00
|
|
|
for (size_t number_of_launch = 0; number_of_launch < statistics.size(); ++number_of_launch)
|
2017-05-05 11:36:55 +00:00
|
|
|
{
|
2017-05-05 17:48:11 +00:00
|
|
|
if (!statistics[number_of_launch].ready)
|
2017-05-05 16:49:14 +00:00
|
|
|
continue;
|
|
|
|
|
|
|
|
JSONString runJSON;
|
2017-05-05 11:36:55 +00:00
|
|
|
|
2017-05-05 17:48:11 +00:00
|
|
|
if (substitutions_maps.size())
|
2017-05-05 11:36:55 +00:00
|
|
|
{
|
2017-05-05 16:49:14 +00:00
|
|
|
JSONString parameters(4);
|
|
|
|
|
2017-05-05 17:48:11 +00:00
|
|
|
for (auto it = substitutions_maps[query_index].begin(); it != substitutions_maps[query_index].end(); ++it)
|
2017-05-05 16:49:14 +00:00
|
|
|
{
|
|
|
|
parameters[it->first].set(it->second);
|
|
|
|
}
|
|
|
|
|
|
|
|
runJSON["parameters"].set(parameters);
|
2017-05-05 11:36:55 +00:00
|
|
|
}
|
|
|
|
|
2017-05-05 17:48:11 +00:00
|
|
|
if (exec_type == loop)
|
2017-05-05 16:49:14 +00:00
|
|
|
{
|
|
|
|
/// in seconds
|
2017-05-09 17:17:24 +00:00
|
|
|
if (std::find(metrics.begin(), metrics.end(), "min_time") != metrics.end())
|
|
|
|
runJSON["min_time"].set(statistics[number_of_launch].min_time / double(1000));
|
2017-05-05 11:36:55 +00:00
|
|
|
|
2017-05-09 17:17:24 +00:00
|
|
|
if (std::find(metrics.begin(), metrics.end(), "quantiles") != metrics.end())
|
2017-05-05 16:49:14 +00:00
|
|
|
{
|
2017-05-09 17:17:24 +00:00
|
|
|
JSONString quantiles(4); /// here, 4 is the size of \t padding
|
|
|
|
for (double percent = 10; percent <= 90; percent += 10)
|
|
|
|
{
|
|
|
|
quantiles[percent / 100].set(statistics[number_of_launch].sampler.quantileInterpolated(percent / 100.0));
|
|
|
|
}
|
|
|
|
quantiles[0.95].set(statistics[number_of_launch].sampler.quantileInterpolated(95 / 100.0));
|
|
|
|
quantiles[0.99].set(statistics[number_of_launch].sampler.quantileInterpolated(99 / 100.0));
|
|
|
|
quantiles[0.999].set(statistics[number_of_launch].sampler.quantileInterpolated(99.9 / 100.0));
|
|
|
|
quantiles[0.9999].set(statistics[number_of_launch].sampler.quantileInterpolated(99.99 / 100.0));
|
|
|
|
|
|
|
|
runJSON["quantiles"].set(quantiles);
|
2017-05-05 16:49:14 +00:00
|
|
|
}
|
2017-05-05 11:36:55 +00:00
|
|
|
|
2017-05-09 17:17:24 +00:00
|
|
|
if (std::find(metrics.begin(), metrics.end(), "total_time") != metrics.end())
|
|
|
|
runJSON["total_time"].set(statistics[number_of_launch].total_time);
|
|
|
|
|
|
|
|
if (std::find(metrics.begin(), metrics.end(), "queries_per_second") != metrics.end())
|
|
|
|
runJSON["queries_per_second"].set(double(statistics[number_of_launch].queries) /
|
|
|
|
statistics[number_of_launch].total_time);
|
2017-05-05 16:49:14 +00:00
|
|
|
|
2017-05-09 17:17:24 +00:00
|
|
|
if (std::find(metrics.begin(), metrics.end(), "rows_per_second") != metrics.end())
|
|
|
|
runJSON["rows_per_second"].set(double(statistics[number_of_launch].rows_read) /
|
|
|
|
statistics[number_of_launch].total_time);
|
|
|
|
|
|
|
|
if (std::find(metrics.begin(), metrics.end(), "bytes_per_second") != metrics.end())
|
|
|
|
runJSON["bytes_per_second"].set(double(statistics[number_of_launch].bytes_read) /
|
|
|
|
statistics[number_of_launch].total_time);
|
2017-05-05 16:49:14 +00:00
|
|
|
}
|
|
|
|
else
|
2017-05-05 11:36:55 +00:00
|
|
|
{
|
2017-05-09 17:17:24 +00:00
|
|
|
if (std::find(metrics.begin(), metrics.end(), "max_rows_per_second") != metrics.end())
|
|
|
|
runJSON["max_rows_per_second"].set(statistics[number_of_launch].max_rows_speed);
|
|
|
|
|
|
|
|
if (std::find(metrics.begin(), metrics.end(), "max_bytes_per_second") != metrics.end())
|
|
|
|
runJSON["max_bytes_per_second"].set(statistics[number_of_launch].max_bytes_speed);
|
|
|
|
|
|
|
|
if (std::find(metrics.begin(), metrics.end(), "avg_rows_per_second") != metrics.end())
|
|
|
|
runJSON["avg_rows_per_second"].set(statistics[number_of_launch].avg_rows_speed_value);
|
|
|
|
|
|
|
|
if (std::find(metrics.begin(), metrics.end(), "avg_bytes_per_second") != metrics.end())
|
|
|
|
runJSON["avg_bytes_per_second"].set(statistics[number_of_launch].avg_bytes_speed_value);
|
2017-05-05 11:36:55 +00:00
|
|
|
}
|
|
|
|
|
2017-05-05 17:48:11 +00:00
|
|
|
run_infos.push_back(runJSON);
|
2017-05-05 11:36:55 +00:00
|
|
|
}
|
|
|
|
}
|
2017-01-13 18:26:51 +00:00
|
|
|
|
2017-05-05 17:48:11 +00:00
|
|
|
json_output["runs"].set(run_infos);
|
2017-05-05 11:36:55 +00:00
|
|
|
|
2017-05-07 01:29:24 +00:00
|
|
|
return json_output.constructOutput();
|
2017-05-05 11:36:55 +00:00
|
|
|
}
|
|
|
|
|
2017-05-07 01:29:24 +00:00
|
|
|
std::string minOutput(const std::string & main_metric)
|
2017-05-05 11:36:55 +00:00
|
|
|
{
|
2017-05-07 01:29:24 +00:00
|
|
|
std::string output;
|
|
|
|
|
2017-05-05 17:48:11 +00:00
|
|
|
for (size_t query_index = 0; query_index < queries.size(); ++query_index)
|
2017-05-05 11:36:55 +00:00
|
|
|
{
|
2017-05-05 17:48:11 +00:00
|
|
|
for (size_t number_of_launch = 0; number_of_launch < times_to_run; ++number_of_launch)
|
2017-05-05 11:36:55 +00:00
|
|
|
{
|
2017-05-07 01:29:24 +00:00
|
|
|
output += test_name + ", ";
|
2017-05-05 11:36:55 +00:00
|
|
|
|
2017-05-05 17:48:11 +00:00
|
|
|
if (substitutions_maps.size())
|
2017-05-05 11:36:55 +00:00
|
|
|
{
|
2017-05-05 17:48:11 +00:00
|
|
|
for (auto it = substitutions_maps[query_index].begin(); it != substitutions_maps[query_index].end(); ++it)
|
2017-05-05 11:36:55 +00:00
|
|
|
{
|
2017-05-07 01:29:24 +00:00
|
|
|
output += it->first + " = " + it->second + ", ";
|
2017-05-05 11:36:55 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-05-07 01:29:24 +00:00
|
|
|
output += "run " + std::to_string(number_of_launch + 1) + ": ";
|
|
|
|
output += main_metric + " = ";
|
|
|
|
output += statistics[number_of_launch * queries.size() + query_index].getStatisticByName(main_metric);
|
|
|
|
output += "\n";
|
2017-05-05 11:36:55 +00:00
|
|
|
}
|
|
|
|
}
|
2017-05-07 01:29:24 +00:00
|
|
|
|
|
|
|
return output;
|
2017-05-05 11:36:55 +00:00
|
|
|
}
|
|
|
|
};
|
2017-01-13 18:26:51 +00:00
|
|
|
}
|
|
|
|
|
2017-05-06 14:36:37 +00:00
|
|
|
void getFilesFromDir(FS::path && dir, std::vector<std::string> & input_files)
|
2017-05-05 18:32:38 +00:00
|
|
|
{
|
|
|
|
if (dir.extension().string() == ".xml")
|
|
|
|
std::cerr << "Warning: \"" + dir.string() + "\" is a directory, but has .xml extension" << std::endl;
|
|
|
|
|
2017-05-06 14:36:37 +00:00
|
|
|
FS::directory_iterator end;
|
|
|
|
for (FS::directory_iterator it(dir); it != end; ++it)
|
2017-05-05 18:32:38 +00:00
|
|
|
{
|
2017-05-06 14:36:37 +00:00
|
|
|
const FS::path file = (*it);
|
|
|
|
if (!FS::is_directory(file) && file.extension().string() == ".xml")
|
2017-05-05 18:32:38 +00:00
|
|
|
input_files.push_back(file.string());
|
|
|
|
}
|
|
|
|
}
|
2017-01-20 18:34:06 +00:00
|
|
|
|
2017-05-05 11:36:55 +00:00
|
|
|
int mainEntryClickhousePerformanceTest(int argc, char ** argv)
|
|
|
|
{
|
|
|
|
using namespace DB;
|
|
|
|
|
|
|
|
try
|
|
|
|
{
|
|
|
|
using boost::program_options::value;
|
|
|
|
using Strings = std::vector<std::string>;
|
|
|
|
|
|
|
|
boost::program_options::options_description desc("Allowed options");
|
2017-05-05 12:41:18 +00:00
|
|
|
desc.add_options()
|
2017-05-07 00:29:30 +00:00
|
|
|
("help", "produce help message")
|
|
|
|
("lite", "use lite version of output")
|
2017-05-07 18:55:42 +00:00
|
|
|
("profiles-file", value<std::string>()->default_value(""), "Specify a file with global profiles")
|
|
|
|
("host,h", value<std::string>()->default_value("localhost"), "")
|
|
|
|
("port", value<UInt16>()->default_value(9000), "")
|
|
|
|
("database", value<std::string>()->default_value("default"), "")
|
|
|
|
("user", value<std::string>()->default_value("default"), "")
|
|
|
|
("password", value<std::string>()->default_value(""), "")
|
|
|
|
("tags", value<Strings>()->multitoken(), "Run only tests with tag")
|
|
|
|
("skip-tags", value<Strings>()->multitoken(), "Do not run tests with tag")
|
|
|
|
("names", value<Strings>()->multitoken(), "Run tests with specific name")
|
|
|
|
("skip-names", value<Strings>()->multitoken(), "Do not run tests with name")
|
|
|
|
("names-regexp", value<Strings>()->multitoken(), "Run tests with names matching regexp")
|
|
|
|
("skip-names-regexp", value<Strings>()->multitoken(), "Do not run tests with names matching regexp");
|
2017-05-05 11:36:55 +00:00
|
|
|
|
|
|
|
/// These options will not be displayed in --help
|
|
|
|
boost::program_options::options_description hidden("Hidden options");
|
|
|
|
hidden.add_options()("input-files", value<std::vector<std::string>>(), "");
|
|
|
|
|
|
|
|
/// But they will be legit, though. And they must be given without name
|
|
|
|
boost::program_options::positional_options_description positional;
|
|
|
|
positional.add("input-files", -1);
|
|
|
|
|
|
|
|
boost::program_options::options_description cmdline_options;
|
|
|
|
cmdline_options.add(desc).add(hidden);
|
|
|
|
|
|
|
|
boost::program_options::variables_map options;
|
|
|
|
boost::program_options::store(
|
|
|
|
boost::program_options::command_line_parser(argc, argv).options(cmdline_options).positional(positional).run(), options);
|
|
|
|
boost::program_options::notify(options);
|
|
|
|
|
|
|
|
if (options.count("help"))
|
|
|
|
{
|
|
|
|
std::cout << "Usage: " << argv[0] << " [options] [test_file ...] [tests_folder]\n";
|
|
|
|
std::cout << desc << "\n";
|
2017-05-05 15:58:25 +00:00
|
|
|
return 0;
|
2017-05-05 11:36:55 +00:00
|
|
|
}
|
|
|
|
|
2017-05-05 18:32:38 +00:00
|
|
|
Strings input_files;
|
|
|
|
|
2017-05-05 11:36:55 +00:00
|
|
|
if (!options.count("input-files"))
|
|
|
|
{
|
2017-05-08 19:25:38 +00:00
|
|
|
std::cerr << "Trying to find tests in current folder" << std::endl;
|
2017-05-05 18:32:38 +00:00
|
|
|
|
2017-05-06 14:36:37 +00:00
|
|
|
getFilesFromDir(FS::path("."), input_files);
|
2017-05-05 18:32:38 +00:00
|
|
|
|
|
|
|
if (input_files.empty())
|
|
|
|
throw Poco::Exception("Did not find any xml files", 1);
|
2017-05-08 19:25:38 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-05-05 18:32:38 +00:00
|
|
|
input_files = options["input-files"].as<Strings>();
|
|
|
|
|
2017-05-06 14:36:37 +00:00
|
|
|
for (const std::string filename : input_files)
|
2017-05-05 18:32:38 +00:00
|
|
|
{
|
2017-05-06 14:36:37 +00:00
|
|
|
FS::path file(filename);
|
2017-05-05 18:32:38 +00:00
|
|
|
|
2017-05-06 14:36:37 +00:00
|
|
|
if (!FS::exists(file))
|
|
|
|
throw Poco::Exception("File \"" + filename + "\" does not exist", 1);
|
2017-05-05 18:32:38 +00:00
|
|
|
|
2017-05-06 14:36:37 +00:00
|
|
|
if (FS::is_directory(file))
|
2017-05-05 18:32:38 +00:00
|
|
|
{
|
2017-05-06 14:36:37 +00:00
|
|
|
input_files.erase( std::remove(input_files.begin(), input_files.end(), filename) , input_files.end());
|
2017-05-05 18:32:38 +00:00
|
|
|
getFilesFromDir(std::move(file), input_files);
|
2017-05-08 19:25:38 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-05-05 18:32:38 +00:00
|
|
|
if (file.extension().string() != ".xml")
|
2017-05-06 14:36:37 +00:00
|
|
|
throw Poco::Exception("File \"" + filename + "\" does not have .xml extension", 1);
|
2017-05-05 18:32:38 +00:00
|
|
|
}
|
|
|
|
}
|
2017-05-05 11:36:55 +00:00
|
|
|
}
|
|
|
|
|
2017-05-07 18:55:42 +00:00
|
|
|
Strings tests_tags = options.count("tags")
|
|
|
|
? options["tags"].as<Strings>()
|
|
|
|
: Strings({});
|
|
|
|
Strings skip_tags = options.count("skip-tags")
|
|
|
|
? options["skip-tags"].as<Strings>()
|
|
|
|
: Strings({});
|
|
|
|
Strings tests_names = options.count("names")
|
|
|
|
? options["names"].as<Strings>()
|
|
|
|
: Strings({});
|
|
|
|
Strings skip_names = options.count("skip-names")
|
|
|
|
? options["skip-names"].as<Strings>()
|
|
|
|
: Strings({});
|
|
|
|
Strings tests_names_regexp = options.count("names-regexp")
|
|
|
|
? options["names-regexp"].as<Strings>()
|
|
|
|
: Strings({});
|
|
|
|
Strings skip_names_regexp = options.count("skip-names-regexp")
|
|
|
|
? options["skip-names-regexp"].as<Strings>()
|
|
|
|
: Strings({});
|
2017-05-05 11:36:55 +00:00
|
|
|
|
2017-05-05 12:41:18 +00:00
|
|
|
PerformanceTest performanceTest(
|
2017-05-05 11:36:55 +00:00
|
|
|
options["host"].as<std::string>(),
|
|
|
|
options["port"].as<UInt16>(),
|
|
|
|
options["database"].as<std::string>(),
|
|
|
|
options["user"].as<std::string>(),
|
|
|
|
options["password"].as<std::string>(),
|
2017-05-05 15:58:25 +00:00
|
|
|
options.count("lite") > 0,
|
2017-05-07 00:29:30 +00:00
|
|
|
options["profiles-file"].as<std::string>(),
|
2017-05-07 18:55:42 +00:00
|
|
|
std::move(input_files),
|
|
|
|
std::move(tests_tags),
|
|
|
|
std::move(skip_tags),
|
|
|
|
std::move(tests_names),
|
|
|
|
std::move(skip_names),
|
|
|
|
std::move(tests_names_regexp),
|
|
|
|
std::move(skip_names_regexp)
|
|
|
|
);
|
2017-05-05 11:36:55 +00:00
|
|
|
}
|
|
|
|
catch (const Exception & e)
|
|
|
|
{
|
|
|
|
std::string text = e.displayText();
|
|
|
|
|
|
|
|
std::cerr << "Code: " << e.code() << ". " << text << "\n\n";
|
|
|
|
|
|
|
|
/// Если есть стек-трейс на сервере, то не будем писать стек-трейс на клиенте.
|
|
|
|
if (std::string::npos == text.find("Stack trace"))
|
|
|
|
std::cerr << "Stack trace:\n" << e.getStackTrace().toString();
|
|
|
|
|
|
|
|
return e.code();
|
|
|
|
}
|
|
|
|
catch (const Poco::Exception & e)
|
|
|
|
{
|
|
|
|
std::cerr << "Poco::Exception: " << e.displayText() << "\n";
|
|
|
|
return ErrorCodes::POCO_EXCEPTION;
|
|
|
|
}
|
|
|
|
catch (const std::exception & e)
|
|
|
|
{
|
|
|
|
std::cerr << "std::exception: " << e.what() << "\n";
|
|
|
|
return ErrorCodes::STD_EXCEPTION;
|
|
|
|
}
|
|
|
|
catch (...)
|
|
|
|
{
|
|
|
|
std::cerr << "Unknown exception\n";
|
|
|
|
return ErrorCodes::UNKNOWN_EXCEPTION;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
2017-01-13 18:26:51 +00:00
|
|
|
}
|