mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-12-16 19:32:07 +00:00
d09c5c871b
* Fix build * cmake: fix cpuinfo * Fix includes after processors merge Conflicts: dbms/src/Processors/Formats/Impl/CapnProtoRowInputFormat.cpp dbms/src/Processors/Formats/Impl/ParquetBlockOutputFormat.cpp dbms/src/Processors/Formats/Impl/ProtobufRowInputFormat.cpp dbms/src/Processors/Formats/Impl/ProtobufRowOutputFormat.cpp * Fix build in gcc8 * fix test link * fix test link * Fix test link * link fix * Fix includes after processors merge 2 Conflicts: dbms/src/Processors/Formats/Impl/ParquetBlockInputFormat.cpp * Fix includes after processors merge 3 * link fix * Fix likely/unlikely conflict with cython * Fix conflict with protobuf/stubs/atomicops.h * remove unlikely.h * Fix macos build (do not use timer_t)
77 lines
1.8 KiB
C++
77 lines
1.8 KiB
C++
#pragma once
|
|
|
|
#include <Core/Types.h>
|
|
#include <common/config_common.h>
|
|
#include <signal.h>
|
|
#include <time.h>
|
|
|
|
|
|
namespace Poco
|
|
{
|
|
class Logger;
|
|
}
|
|
|
|
namespace DB
|
|
{
|
|
|
|
enum class TimerType : UInt8
|
|
{
|
|
Real,
|
|
Cpu,
|
|
};
|
|
|
|
/**
|
|
* Query profiler implementation for selected thread.
|
|
*
|
|
* This class installs timer and signal handler on creation to:
|
|
* 1. periodically pause given thread
|
|
* 2. collect thread's current stack trace
|
|
* 3. write collected stack trace to trace_pipe for TraceCollector
|
|
*
|
|
* Desctructor tries to unset timer and restore previous signal handler.
|
|
* Note that signal handler implementation is defined by template parameter. See QueryProfilerReal and QueryProfilerCpu.
|
|
*/
|
|
template <typename ProfilerImpl>
|
|
class QueryProfilerBase
|
|
{
|
|
public:
|
|
QueryProfilerBase(const Int32 thread_id, const int clock_type, UInt32 period, const int pause_signal_);
|
|
~QueryProfilerBase();
|
|
|
|
private:
|
|
void tryCleanup();
|
|
|
|
Poco::Logger * log;
|
|
|
|
#if USE_INTERNAL_UNWIND_LIBRARY
|
|
/// Timer id from timer_create(2)
|
|
timer_t timer_id = nullptr;
|
|
#endif
|
|
|
|
/// Pause signal to interrupt threads to get traces
|
|
int pause_signal;
|
|
|
|
/// Previous signal handler to restore after query profiler exits
|
|
struct sigaction * previous_handler = nullptr;
|
|
};
|
|
|
|
/// Query profiler with timer based on real clock
|
|
class QueryProfilerReal : public QueryProfilerBase<QueryProfilerReal>
|
|
{
|
|
public:
|
|
QueryProfilerReal(const Int32 thread_id, const UInt32 period);
|
|
|
|
static void signalHandler(int sig, siginfo_t * info, void * context);
|
|
};
|
|
|
|
/// Query profiler with timer based on CPU clock
|
|
class QueryProfilerCpu : public QueryProfilerBase<QueryProfilerCpu>
|
|
{
|
|
public:
|
|
QueryProfilerCpu(const Int32 thread_id, const UInt32 period);
|
|
|
|
static void signalHandler(int sig, siginfo_t * info, void * context);
|
|
};
|
|
|
|
}
|