1 | #include <Interpreters/TraceLog.h> |
2 | #include <DataTypes/DataTypeArray.h> |
3 | #include <DataTypes/DataTypeString.h> |
4 | #include <DataTypes/DataTypesNumber.h> |
5 | #include <DataTypes/DataTypeDate.h> |
6 | #include <DataTypes/DataTypeDateTime.h> |
7 | #include <Common/ClickHouseRevision.h> |
8 | |
9 | |
10 | using namespace DB; |
11 | |
12 | using TimerDataType = TraceLogElement::TimerDataType; |
13 | |
14 | const TimerDataType::Values TraceLogElement::timer_values = { |
15 | {"Real" , static_cast<UInt8>(TimerType::Real)}, |
16 | {"CPU" , static_cast<UInt8>(TimerType::Cpu)} |
17 | }; |
18 | |
19 | Block TraceLogElement::createBlock() |
20 | { |
21 | return |
22 | { |
23 | {std::make_shared<DataTypeDate>(), "event_date" }, |
24 | {std::make_shared<DataTypeDateTime>(), "event_time" }, |
25 | {std::make_shared<DataTypeUInt32>(), "revision" }, |
26 | {std::make_shared<TimerDataType>(timer_values), "timer_type" }, |
27 | {std::make_shared<DataTypeUInt32>(), "thread_number" }, |
28 | {std::make_shared<DataTypeString>(), "query_id" }, |
29 | {std::make_shared<DataTypeArray>(std::make_shared<DataTypeUInt64>()), "trace" } |
30 | }; |
31 | } |
32 | |
33 | void TraceLogElement::appendToBlock(Block & block) const |
34 | { |
35 | MutableColumns columns = block.mutateColumns(); |
36 | |
37 | size_t i = 0; |
38 | |
39 | columns[i++]->insert(DateLUT::instance().toDayNum(event_time)); |
40 | columns[i++]->insert(event_time); |
41 | columns[i++]->insert(ClickHouseRevision::get()); |
42 | columns[i++]->insert(static_cast<UInt8>(timer_type)); |
43 | columns[i++]->insert(thread_number); |
44 | columns[i++]->insertData(query_id.data(), query_id.size()); |
45 | columns[i++]->insert(trace); |
46 | |
47 | block.setColumns(std::move(columns)); |
48 | } |
49 | |