ClickHouse/dbms/src/Interpreters/TraceCollector.cpp

52 lines
1.3 KiB
C++
Raw Normal View History

2019-02-03 09:57:12 +00:00
#include "TraceCollector.h"
2019-02-03 21:30:45 +00:00
#include <common/Backtrace.h>
2019-02-03 09:57:12 +00:00
#include <common/logger_useful.h>
#include <IO/ReadHelpers.h>
2019-02-03 21:30:45 +00:00
#include <ctime>
2019-02-03 09:57:12 +00:00
namespace DB {
2019-02-03 21:30:45 +00:00
const size_t TraceCollector::buf_size = sizeof(int) + sizeof(siginfo_t) + sizeof(ucontext_t);
2019-02-03 09:57:12 +00:00
2019-02-03 21:30:45 +00:00
TraceCollector::TraceCollector(TraceLog * trace_log)
2019-02-03 09:57:12 +00:00
: log(&Logger::get("TraceCollector"))
2019-02-03 21:30:45 +00:00
, trace_log(trace_log)
2019-02-03 09:57:12 +00:00
{
}
void TraceCollector::run()
{
2019-02-03 21:30:45 +00:00
DB::ReadBufferFromFileDescriptor in(TracePipe::instance().read_fd);
2019-02-03 09:57:12 +00:00
while (true)
{
2019-02-03 21:30:45 +00:00
ucontext_t context;
std::string queryID;
DB::readPODBinary(context, in);
DB::readStringBinary(queryID, in);
LOG_INFO(log, queryID);
if (trace_log != nullptr) {
std::vector<void *> frames = getBacktraceFrames(context);
std::vector<UInt64> trace;
trace.reserve(frames.size());
for (void * frame : frames) {
trace.push_back(reinterpret_cast<uintptr_t>(frame));
}
TraceLogElement element{std::time(nullptr), queryID, trace};
trace_log->add(element);
2019-02-03 09:57:12 +00:00
2019-02-03 21:30:45 +00:00
LOG_INFO(log, "TraceCollector added row");
}
2019-02-03 09:57:12 +00:00
}
LOG_INFO(log, "TraceCollector exited");
}
}