2020-07-31 13:53:42 +00:00
|
|
|
#include <Interpreters/CrashLog.h>
|
|
|
|
#include <DataTypes/DataTypeArray.h>
|
|
|
|
#include <DataTypes/DataTypeString.h>
|
|
|
|
#include <DataTypes/DataTypesNumber.h>
|
|
|
|
#include <DataTypes/DataTypeDate.h>
|
|
|
|
#include <DataTypes/DataTypeDateTime.h>
|
|
|
|
#include <Common/ClickHouseRevision.h>
|
|
|
|
#include <Common/SymbolIndex.h>
|
2021-08-11 14:19:45 +00:00
|
|
|
#include <Common/Stopwatch.h>
|
2020-07-31 13:53:42 +00:00
|
|
|
|
2021-10-27 23:10:39 +00:00
|
|
|
#include <Common/config_version.h>
|
2020-07-31 13:53:42 +00:00
|
|
|
|
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
|
|
|
std::weak_ptr<CrashLog> CrashLog::crash_log;
|
|
|
|
|
|
|
|
|
2021-06-28 11:42:21 +00:00
|
|
|
NamesAndTypesList CrashLogElement::getNamesAndTypes()
|
2020-07-31 13:53:42 +00:00
|
|
|
{
|
|
|
|
return
|
|
|
|
{
|
2021-06-28 11:42:21 +00:00
|
|
|
{"event_date", std::make_shared<DataTypeDate>()},
|
|
|
|
{"event_time", std::make_shared<DataTypeDateTime>()},
|
|
|
|
{"timestamp_ns", std::make_shared<DataTypeUInt64>()},
|
|
|
|
{"signal", std::make_shared<DataTypeInt32>()},
|
|
|
|
{"thread_id", std::make_shared<DataTypeUInt64>()},
|
|
|
|
{"query_id", std::make_shared<DataTypeString>()},
|
|
|
|
{"trace", std::make_shared<DataTypeArray>(std::make_shared<DataTypeUInt64>())},
|
|
|
|
{"trace_full", std::make_shared<DataTypeArray>(std::make_shared<DataTypeString>())},
|
|
|
|
{"version", std::make_shared<DataTypeString>()},
|
|
|
|
{"revision", std::make_shared<DataTypeUInt32>()},
|
|
|
|
{"build_id", std::make_shared<DataTypeString>()},
|
2020-07-31 13:53:42 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
void CrashLogElement::appendToBlock(MutableColumns & columns) const
|
|
|
|
{
|
|
|
|
size_t i = 0;
|
|
|
|
|
2020-04-17 13:26:44 +00:00
|
|
|
columns[i++]->insert(DateLUT::instance().toDayNum(event_time).toUnderType());
|
2020-07-31 13:53:42 +00:00
|
|
|
columns[i++]->insert(event_time);
|
|
|
|
columns[i++]->insert(timestamp_ns);
|
|
|
|
columns[i++]->insert(signal);
|
|
|
|
columns[i++]->insert(thread_id);
|
|
|
|
columns[i++]->insertData(query_id.data(), query_id.size());
|
|
|
|
columns[i++]->insert(trace);
|
|
|
|
columns[i++]->insert(trace_full);
|
|
|
|
columns[i++]->insert(VERSION_FULL);
|
2020-09-17 12:15:05 +00:00
|
|
|
columns[i++]->insert(ClickHouseRevision::getVersionRevision());
|
2020-07-31 13:53:42 +00:00
|
|
|
|
|
|
|
String build_id_hex;
|
2022-06-10 08:22:31 +00:00
|
|
|
#if defined(__ELF__) && !defined(OS_FREEBSD)
|
2020-11-30 14:30:55 +00:00
|
|
|
build_id_hex = SymbolIndex::instance()->getBuildIDHex();
|
2020-07-31 13:53:42 +00:00
|
|
|
#endif
|
|
|
|
columns[i++]->insert(build_id_hex);
|
|
|
|
}
|
|
|
|
|
2020-08-01 15:54:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void collectCrashLog(Int32 signal, UInt64 thread_id, const String & query_id, const StackTrace & stack_trace)
|
2020-07-31 20:16:31 +00:00
|
|
|
{
|
2020-08-01 15:54:44 +00:00
|
|
|
using namespace DB;
|
|
|
|
|
|
|
|
if (auto crash_log_owned = CrashLog::crash_log.lock())
|
2020-07-31 20:25:15 +00:00
|
|
|
{
|
2020-08-01 15:54:44 +00:00
|
|
|
UInt64 time = clock_gettime_ns(CLOCK_REALTIME);
|
2020-07-31 20:16:31 +00:00
|
|
|
|
2020-07-31 20:25:15 +00:00
|
|
|
size_t stack_trace_size = stack_trace.getSize();
|
|
|
|
size_t stack_trace_offset = stack_trace.getOffset();
|
|
|
|
size_t num_frames = stack_trace_size - stack_trace_offset;
|
2020-07-31 20:16:31 +00:00
|
|
|
|
2020-07-31 20:25:15 +00:00
|
|
|
Array trace;
|
|
|
|
Array trace_full;
|
2020-07-31 20:16:31 +00:00
|
|
|
|
2020-07-31 20:25:15 +00:00
|
|
|
trace.reserve(num_frames);
|
|
|
|
trace_full.reserve(num_frames);
|
2020-07-31 20:16:31 +00:00
|
|
|
|
2020-07-31 20:25:15 +00:00
|
|
|
for (size_t i = stack_trace_offset; i < stack_trace_size; ++i)
|
|
|
|
trace.push_back(reinterpret_cast<uintptr_t>(stack_trace.getFramePointers()[i]));
|
2020-07-31 20:16:31 +00:00
|
|
|
|
2020-07-31 20:25:15 +00:00
|
|
|
stack_trace.toStringEveryLine([&trace_full](const std::string & line) { trace_full.push_back(line); });
|
2020-07-31 20:16:31 +00:00
|
|
|
|
2022-04-18 08:18:31 +00:00
|
|
|
CrashLogElement element{static_cast<time_t>(time / 1000000000), time, signal, thread_id, query_id, trace, trace_full};
|
2020-07-31 20:25:15 +00:00
|
|
|
crash_log_owned->add(element);
|
|
|
|
}
|
2020-07-31 20:16:31 +00:00
|
|
|
}
|