Query,QueryThread Logs - add event_time_microseconds field

This commit is contained in:
bharatnc 2020-09-11 09:51:24 -07:00 committed by alesapin
parent c6b5ef1174
commit 1830df1d6b
6 changed files with 11 additions and 0 deletions

View File

@ -39,6 +39,7 @@ Block QueryLogElement::createBlock()
{std::move(query_status_datatype), "type"},
{std::make_shared<DataTypeDate>(), "event_date"},
{std::make_shared<DataTypeDateTime>(), "event_time"},
{std::make_shared<DataTypeDateTime64>(6), "event_time_microseconds"},
{std::make_shared<DataTypeDateTime>(), "query_start_time"},
{std::make_shared<DataTypeDateTime64>(6), "query_start_time_microseconds"},
{std::make_shared<DataTypeUInt64>(), "query_duration_ms"},
@ -97,6 +98,7 @@ void QueryLogElement::appendToBlock(MutableColumns & columns) const
columns[i++]->insert(type);
columns[i++]->insert(DateLUT::instance().toDayNum(event_time));
columns[i++]->insert(event_time);
columns[i++]->insert(event_time_microseconds);
columns[i++]->insert(query_start_time);
columns[i++]->insert(query_start_time_microseconds);
columns[i++]->insert(query_duration_ms);

View File

@ -30,6 +30,7 @@ struct QueryLogElement
/// Depending on the type of query and type of stage, not all the fields may be filled.
time_t event_time{};
UInt64 event_time_microseconds{};
time_t query_start_time{};
UInt64 query_start_time_microseconds{};
UInt64 query_duration_ms{};

View File

@ -23,6 +23,7 @@ Block QueryThreadLogElement::createBlock()
return {
{std::make_shared<DataTypeDate>(), "event_date"},
{std::make_shared<DataTypeDateTime>(), "event_time"},
{std::make_shared<DataTypeDateTime64>(6), "event_time_microseconds"},
{std::make_shared<DataTypeDateTime>(), "query_start_time"},
{std::make_shared<DataTypeDateTime64>(6), "query_start_time_microseconds"},
{std::make_shared<DataTypeUInt64>(), "query_duration_ms"},
@ -73,6 +74,7 @@ void QueryThreadLogElement::appendToBlock(MutableColumns & columns) const
columns[i++]->insert(DateLUT::instance().toDayNum(event_time));
columns[i++]->insert(event_time);
columns[i++]->insert(event_time_microseconds);
columns[i++]->insert(query_start_time);
columns[i++]->insert(query_start_time_microseconds);
columns[i++]->insert(query_duration_ms);

View File

@ -16,6 +16,7 @@ namespace DB
struct QueryThreadLogElement
{
time_t event_time{};
UInt64 event_time_microseconds{};
/// When query was attached to current thread
time_t query_start_time{};
/// same as above but adds microsecond precision

View File

@ -323,6 +323,7 @@ void ThreadStatus::logToQueryThreadLog(QueryThreadLog & thread_log)
QueryThreadLogElement elem;
elem.event_time = time(nullptr);
elem.event_time_microseconds = getCurrentTimeMicroseconds();
elem.query_start_time = query_start_time;
elem.query_start_time_microseconds = query_start_time_microseconds;
elem.query_duration_ms = (getCurrentTimeNanoseconds() - query_start_time_nanoseconds) / 1000000U;

View File

@ -210,6 +210,7 @@ static void onExceptionBeforeStart(const String & query_for_logging, Context & c
// event_time_microseconds from the same timespec. So it can be assumed that both of these
// times are equal upto the precision of a second.
elem.event_time = current_time;
elem.event_time_microseconds = current_time_microseconds;
elem.query_start_time = current_time;
elem.query_start_time_microseconds = current_time_microseconds;
@ -484,6 +485,7 @@ static std::tuple<ASTPtr, BlockIO> executeQueryImpl(
elem.type = QueryLogElementType::QUERY_START;
elem.event_time = current_time;
elem.event_time_microseconds = current_time_microseconds;
elem.query_start_time = current_time;
elem.query_start_time_microseconds = current_time_microseconds;
@ -555,6 +557,7 @@ static std::tuple<ASTPtr, BlockIO> executeQueryImpl(
elem.type = QueryLogElementType::QUERY_FINISH;
elem.event_time = time(nullptr);
elem.event_time_microseconds = getCurrentTimeMicroseconds();
status_info_to_query_log(elem, info, ast);
@ -616,6 +619,7 @@ static std::tuple<ASTPtr, BlockIO> executeQueryImpl(
elem.type = QueryLogElementType::EXCEPTION_WHILE_PROCESSING;
elem.event_time = time(nullptr);
elem.event_time_microseconds = getCurrentTimeMicroseconds();
elem.query_duration_ms = 1000 * (elem.event_time - elem.query_start_time);
elem.exception_code = getCurrentExceptionCode();
elem.exception = getCurrentExceptionMessage(false);