2021-10-15 20:18:20 +00:00
|
|
|
#include <Client/InternalTextLogs.h>
|
2018-06-06 20:57:07 +00:00
|
|
|
#include <Core/Block.h>
|
2018-06-15 17:32:35 +00:00
|
|
|
#include <Interpreters/InternalTextLogsQueue.h>
|
2021-10-12 18:03:54 +00:00
|
|
|
#include <Interpreters/ProfileEventsExt.h>
|
2018-06-06 20:57:07 +00:00
|
|
|
#include <Common/typeid_cast.h>
|
2020-02-21 20:01:38 +00:00
|
|
|
#include <Common/HashTable/Hash.h>
|
2018-06-06 20:57:07 +00:00
|
|
|
#include <DataTypes/IDataType.h>
|
|
|
|
#include <Columns/ColumnsNumber.h>
|
|
|
|
#include <Columns/ColumnString.h>
|
|
|
|
#include <IO/WriteHelpers.h>
|
2021-10-02 07:13:14 +00:00
|
|
|
#include <base/terminalColors.h>
|
2018-06-06 20:57:07 +00:00
|
|
|
|
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
2021-10-12 18:03:54 +00:00
|
|
|
void InternalTextLogs::writeLogs(const Block & block)
|
2018-06-06 20:57:07 +00:00
|
|
|
{
|
2020-04-22 05:39:31 +00:00
|
|
|
const auto & array_event_time = typeid_cast<const ColumnUInt32 &>(*block.getByName("event_time").column).getData();
|
|
|
|
const auto & array_microseconds = typeid_cast<const ColumnUInt32 &>(*block.getByName("event_time_microseconds").column).getData();
|
2018-06-06 20:57:07 +00:00
|
|
|
|
2020-04-22 05:39:31 +00:00
|
|
|
const auto & column_host_name = typeid_cast<const ColumnString &>(*block.getByName("host_name").column);
|
|
|
|
const auto & column_query_id = typeid_cast<const ColumnString &>(*block.getByName("query_id").column);
|
2018-06-06 20:57:07 +00:00
|
|
|
|
2020-04-22 05:39:31 +00:00
|
|
|
const auto & array_thread_id = typeid_cast<const ColumnUInt64 &>(*block.getByName("thread_id").column).getData();
|
|
|
|
const auto & array_priority = typeid_cast<const ColumnInt8 &>(*block.getByName("priority").column).getData();
|
|
|
|
const auto & column_source = typeid_cast<const ColumnString &>(*block.getByName("source").column);
|
|
|
|
const auto & column_text = typeid_cast<const ColumnString &>(*block.getByName("text").column);
|
2018-06-06 20:57:07 +00:00
|
|
|
|
2018-06-15 13:45:19 +00:00
|
|
|
for (size_t row_num = 0; row_num < block.rows(); ++row_num)
|
|
|
|
{
|
2018-06-15 17:32:35 +00:00
|
|
|
auto host_name = column_host_name.getDataAt(row_num);
|
|
|
|
if (host_name.size)
|
|
|
|
{
|
|
|
|
writeCString("[", wb);
|
2020-02-21 20:01:38 +00:00
|
|
|
if (color)
|
|
|
|
writeString(setColor(StringRefHash()(host_name)), wb);
|
2018-06-15 17:32:35 +00:00
|
|
|
writeString(host_name, wb);
|
2020-02-21 20:01:38 +00:00
|
|
|
if (color)
|
|
|
|
writeCString(resetColor(), wb);
|
2018-06-15 17:32:35 +00:00
|
|
|
writeCString("] ", wb);
|
|
|
|
}
|
|
|
|
|
2018-06-15 13:45:19 +00:00
|
|
|
auto event_time = array_event_time[row_num];
|
|
|
|
writeDateTimeText<'.', ':'>(event_time, wb);
|
|
|
|
|
|
|
|
auto microseconds = array_microseconds[row_num];
|
|
|
|
writeChar('.', wb);
|
|
|
|
writeChar('0' + ((microseconds / 100000) % 10), wb);
|
|
|
|
writeChar('0' + ((microseconds / 10000) % 10), wb);
|
|
|
|
writeChar('0' + ((microseconds / 1000) % 10), wb);
|
|
|
|
writeChar('0' + ((microseconds / 100) % 10), wb);
|
|
|
|
writeChar('0' + ((microseconds / 10) % 10), wb);
|
|
|
|
writeChar('0' + ((microseconds / 1) % 10), wb);
|
|
|
|
|
2020-02-21 20:01:38 +00:00
|
|
|
UInt64 thread_id = array_thread_id[row_num];
|
|
|
|
writeCString(" [ ", wb);
|
|
|
|
if (color)
|
|
|
|
writeString(setColor(intHash64(thread_id)), wb);
|
|
|
|
writeIntText(thread_id, wb);
|
|
|
|
if (color)
|
|
|
|
writeCString(resetColor(), wb);
|
|
|
|
writeCString(" ]", wb);
|
|
|
|
|
2018-06-15 13:45:19 +00:00
|
|
|
auto query_id = column_query_id.getDataAt(row_num);
|
|
|
|
if (query_id.size)
|
|
|
|
{
|
2018-06-15 17:32:35 +00:00
|
|
|
writeCString(" {", wb);
|
2020-02-21 20:01:38 +00:00
|
|
|
if (color)
|
|
|
|
writeString(setColor(StringRefHash()(query_id)), wb);
|
2018-06-15 13:45:19 +00:00
|
|
|
writeString(query_id, wb);
|
2020-02-21 20:01:38 +00:00
|
|
|
if (color)
|
|
|
|
writeCString(resetColor(), wb);
|
2018-06-15 17:32:35 +00:00
|
|
|
writeCString("}", wb);
|
2018-06-15 13:45:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Int8 priority = array_priority[row_num];
|
2020-02-21 20:01:38 +00:00
|
|
|
writeCString(" <", wb);
|
|
|
|
if (color)
|
|
|
|
writeCString(setColorForLogPriority(priority), wb);
|
2018-06-15 17:32:35 +00:00
|
|
|
writeString(InternalTextLogsQueue::getPriorityName(priority), wb);
|
2020-02-21 20:01:38 +00:00
|
|
|
if (color)
|
|
|
|
writeCString(resetColor(), wb);
|
2018-06-15 13:45:19 +00:00
|
|
|
writeCString("> ", wb);
|
|
|
|
|
|
|
|
auto source = column_source.getDataAt(row_num);
|
2020-04-22 19:34:35 +00:00
|
|
|
if (color)
|
|
|
|
writeString(setColor(StringRefHash()(source)), wb);
|
|
|
|
DB::writeString(source, wb);
|
|
|
|
if (color)
|
|
|
|
writeCString(resetColor(), wb);
|
2018-06-15 13:45:19 +00:00
|
|
|
writeCString(": ", wb);
|
|
|
|
|
|
|
|
auto text = column_text.getDataAt(row_num);
|
|
|
|
writeString(text, wb);
|
|
|
|
|
|
|
|
writeChar('\n', wb);
|
|
|
|
}
|
2018-06-06 20:57:07 +00:00
|
|
|
}
|
|
|
|
|
2021-10-12 18:03:54 +00:00
|
|
|
void InternalTextLogs::writeProfileEvents(const Block & block)
|
|
|
|
{
|
|
|
|
const auto & column_host_name = typeid_cast<const ColumnString &>(*block.getByName("host_name").column);
|
|
|
|
const auto & array_current_time = typeid_cast<const ColumnUInt32 &>(*block.getByName("current_time").column).getData();
|
|
|
|
const auto & array_thread_id = typeid_cast<const ColumnUInt64 &>(*block.getByName("thread_id").column).getData();
|
|
|
|
const auto & array_type = typeid_cast<const ColumnInt8 &>(*block.getByName("type").column).getData();
|
|
|
|
const auto & column_name = typeid_cast<const ColumnString &>(*block.getByName("name").column);
|
2021-11-08 13:38:31 +00:00
|
|
|
const auto & array_value = typeid_cast<const ColumnInt64 &>(*block.getByName("value").column).getData();
|
2021-10-12 18:03:54 +00:00
|
|
|
|
|
|
|
for (size_t row_num = 0; row_num < block.rows(); ++row_num)
|
|
|
|
{
|
|
|
|
/// host_name
|
|
|
|
auto host_name = column_host_name.getDataAt(row_num);
|
|
|
|
if (host_name.size)
|
|
|
|
{
|
|
|
|
writeCString("[", wb);
|
|
|
|
if (color)
|
|
|
|
writeString(setColor(StringRefHash()(host_name)), wb);
|
|
|
|
writeString(host_name, wb);
|
|
|
|
if (color)
|
|
|
|
writeCString(resetColor(), wb);
|
|
|
|
writeCString("] ", wb);
|
|
|
|
}
|
|
|
|
|
|
|
|
/// current_time
|
|
|
|
auto current_time = array_current_time[row_num];
|
|
|
|
writeDateTimeText<'.', ':'>(current_time, wb);
|
|
|
|
|
|
|
|
/// thread_id
|
|
|
|
UInt64 thread_id = array_thread_id[row_num];
|
|
|
|
writeCString(" [ ", wb);
|
|
|
|
if (color)
|
|
|
|
writeString(setColor(intHash64(thread_id)), wb);
|
|
|
|
writeIntText(thread_id, wb);
|
|
|
|
if (color)
|
|
|
|
writeCString(resetColor(), wb);
|
|
|
|
writeCString(" ] ", wb);
|
|
|
|
|
|
|
|
/// name
|
|
|
|
auto name = column_name.getDataAt(row_num);
|
|
|
|
if (color)
|
|
|
|
writeString(setColor(StringRefHash()(name)), wb);
|
|
|
|
DB::writeString(name, wb);
|
|
|
|
if (color)
|
|
|
|
writeCString(resetColor(), wb);
|
|
|
|
writeCString(": ", wb);
|
|
|
|
|
|
|
|
/// value
|
2021-11-08 13:38:31 +00:00
|
|
|
Int64 value = array_value[row_num];
|
2021-10-12 18:03:54 +00:00
|
|
|
writeIntText(value, wb);
|
|
|
|
|
|
|
|
//// type
|
|
|
|
Int8 type = array_type[row_num];
|
|
|
|
writeCString(" (", wb);
|
|
|
|
if (color)
|
|
|
|
writeString(setColor(intHash64(type)), wb);
|
|
|
|
writeString(toString(ProfileEvents::TypeEnum->castToName(type)), wb);
|
|
|
|
if (color)
|
|
|
|
writeCString(resetColor(), wb);
|
|
|
|
writeCString(")", wb);
|
|
|
|
|
|
|
|
writeChar('\n', wb);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-06-06 20:57:07 +00:00
|
|
|
}
|