From c566f406c57479f9d617bbcc2b42c3a507a94373 Mon Sep 17 00:00:00 2001 From: Ivan Lezhankin Date: Wed, 15 Jan 2020 13:51:51 +0300 Subject: [PATCH] Add new trace type to system.trace_log table --- dbms/src/Common/QueryProfiler.cpp | 10 +++++----- dbms/src/Common/QueryProfiler.h | 7 ++++--- dbms/src/Common/TraceCollector.cpp | 6 +++--- dbms/src/Interpreters/TraceLog.cpp | 13 +++++++------ dbms/src/Interpreters/TraceLog.h | 14 +++++++------- 5 files changed, 26 insertions(+), 24 deletions(-) diff --git a/dbms/src/Common/QueryProfiler.cpp b/dbms/src/Common/QueryProfiler.cpp index e142be2e4d9..ea2638f8544 100644 --- a/dbms/src/Common/QueryProfiler.cpp +++ b/dbms/src/Common/QueryProfiler.cpp @@ -34,7 +34,7 @@ namespace thread_local size_t write_trace_iteration = 0; #endif - void writeTraceInfo(TimerType timer_type, int /* sig */, siginfo_t * info, void * context) + void writeTraceInfo(TraceType trace_type, int /* sig */, siginfo_t * info, void * context) { #if defined(OS_LINUX) /// Quickly drop if signal handler is called too frequently. @@ -62,7 +62,7 @@ namespace QUERY_ID_MAX_LEN * sizeof(char) + // maximum query_id length sizeof(UInt8) + // number of stack frames sizeof(StackTrace::Frames) + // collected stack trace, maximum capacity - sizeof(TimerType) + // timer type + sizeof(TraceType) + // timer type sizeof(UInt32); // thread_number char buffer[buf_size]; WriteBufferFromFileDescriptorDiscardOnFailure out(trace_pipe.fds_rw[1], buf_size, buffer); @@ -84,7 +84,7 @@ namespace for (size_t i = stack_trace_offset; i < stack_trace_size; ++i) writePODBinary(stack_trace.getFrames()[i], out); - writePODBinary(timer_type, out); + writePODBinary(trace_type, out); writePODBinary(thread_number, out); out.next(); } @@ -198,7 +198,7 @@ QueryProfilerReal::QueryProfilerReal(const Int32 thread_id, const UInt32 period) void QueryProfilerReal::signalHandler(int sig, siginfo_t * info, void * context) { - writeTraceInfo(TimerType::Real, sig, info, context); + writeTraceInfo(TraceType::REAL_TIME, sig, info, context); } QueryProfilerCpu::QueryProfilerCpu(const Int32 thread_id, const UInt32 period) @@ -207,7 +207,7 @@ QueryProfilerCpu::QueryProfilerCpu(const Int32 thread_id, const UInt32 period) void QueryProfilerCpu::signalHandler(int sig, siginfo_t * info, void * context) { - writeTraceInfo(TimerType::Cpu, sig, info, context); + writeTraceInfo(TraceType::CPU_TIME, sig, info, context); } } diff --git a/dbms/src/Common/QueryProfiler.h b/dbms/src/Common/QueryProfiler.h index abbff6f6c0e..dbe65b06898 100644 --- a/dbms/src/Common/QueryProfiler.h +++ b/dbms/src/Common/QueryProfiler.h @@ -15,10 +15,11 @@ namespace Poco namespace DB { -enum class TimerType : UInt8 +enum class TraceType : UInt8 { - Real, - Cpu, + REAL_TIME, + CPU_TIME, + MEMORY, }; /** diff --git a/dbms/src/Common/TraceCollector.cpp b/dbms/src/Common/TraceCollector.cpp index 4b582c5ad4f..6aeae2fb9f3 100644 --- a/dbms/src/Common/TraceCollector.cpp +++ b/dbms/src/Common/TraceCollector.cpp @@ -102,13 +102,13 @@ void TraceCollector::run() trace.emplace_back(UInt64(addr)); } - TimerType timer_type; - readPODBinary(timer_type, in); + TraceType trace_type; + readPODBinary(trace_type, in); UInt32 thread_number; readPODBinary(thread_number, in); - TraceLogElement element{std::time(nullptr), timer_type, thread_number, query_id, trace}; + TraceLogElement element{std::time(nullptr), trace_type, thread_number, query_id, trace}; trace_log->add(element); } } diff --git a/dbms/src/Interpreters/TraceLog.cpp b/dbms/src/Interpreters/TraceLog.cpp index 5cde9d30f0f..577bc6e22cc 100644 --- a/dbms/src/Interpreters/TraceLog.cpp +++ b/dbms/src/Interpreters/TraceLog.cpp @@ -9,11 +9,12 @@ using namespace DB; -using TimerDataType = TraceLogElement::TimerDataType; +using TraceDataType = TraceLogElement::TraceDataType; -const TimerDataType::Values TraceLogElement::timer_values = { - {"Real", static_cast(TimerType::Real)}, - {"CPU", static_cast(TimerType::Cpu)} +const TraceDataType::Values TraceLogElement::trace_values = { + {"Real", static_cast(TraceType::REAL_TIME)}, + {"CPU", static_cast(TraceType::CPU_TIME)}, + {"Memory", static_cast(TraceType::MEMORY)}, }; Block TraceLogElement::createBlock() @@ -23,7 +24,7 @@ Block TraceLogElement::createBlock() {std::make_shared(), "event_date"}, {std::make_shared(), "event_time"}, {std::make_shared(), "revision"}, - {std::make_shared(timer_values), "timer_type"}, + {std::make_shared(trace_values), "trace_type"}, {std::make_shared(), "thread_number"}, {std::make_shared(), "query_id"}, {std::make_shared(std::make_shared()), "trace"} @@ -39,7 +40,7 @@ void TraceLogElement::appendToBlock(Block & block) const columns[i++]->insert(DateLUT::instance().toDayNum(event_time)); columns[i++]->insert(event_time); columns[i++]->insert(ClickHouseRevision::get()); - columns[i++]->insert(static_cast(timer_type)); + columns[i++]->insert(static_cast(trace_type)); columns[i++]->insert(thread_number); columns[i++]->insertData(query_id.data(), query_id.size()); columns[i++]->insert(trace); diff --git a/dbms/src/Interpreters/TraceLog.h b/dbms/src/Interpreters/TraceLog.h index f5df349656a..52583bd996a 100644 --- a/dbms/src/Interpreters/TraceLog.h +++ b/dbms/src/Interpreters/TraceLog.h @@ -10,14 +10,14 @@ namespace DB struct TraceLogElement { - using TimerDataType = DataTypeEnum8; - static const TimerDataType::Values timer_values; + using TraceDataType = DataTypeEnum8; + static const TraceDataType::Values trace_values; - time_t event_time{}; - TimerType timer_type{}; - UInt32 thread_number{}; - String query_id{}; - Array trace{}; + time_t event_time; + TraceType trace_type; + UInt32 thread_number; + String query_id; + Array trace; static std::string name() { return "TraceLog"; } static Block createBlock();