Simple protection from too frequent profiler signals

This commit is contained in:
Alexey Milovidov 2019-07-23 21:45:54 +03:00
parent 1913bfa276
commit 02fb67dc8a

View File

@ -20,8 +20,13 @@ namespace
/// Thus upper bound on query_id length should be introduced to avoid buffer overflow in signal handler.
constexpr size_t QUERY_ID_MAX_LEN = 1024;
void writeTraceInfo(TimerType timer_type, int /* sig */, siginfo_t * /* info */, void * context)
void writeTraceInfo(TimerType timer_type, int /* sig */, siginfo_t * info, void * context)
{
/// Quickly drop if signal handler is called too frequently.
/// Otherwise we may end up infinitelly processing signals instead of doing any useful work.
if (info && info->si_overrun > 0)
return;
constexpr size_t buf_size = sizeof(char) + // TraceCollector stop flag
8 * sizeof(char) + // maximum VarUInt length for string size
QUERY_ID_MAX_LEN * sizeof(char) + // maximum query_id length