2022-01-11 19:30:55 +00:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <Common/PipeFDs.h>
|
2022-11-24 19:54:39 +00:00
|
|
|
#include <Common/ProfileEvents.h>
|
2022-01-11 19:30:55 +00:00
|
|
|
#include <base/types.h>
|
|
|
|
|
|
|
|
class StackTrace;
|
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
2022-03-11 21:47:28 +00:00
|
|
|
class TraceCollector;
|
|
|
|
|
2022-01-11 19:30:55 +00:00
|
|
|
enum class TraceType : uint8_t
|
|
|
|
{
|
|
|
|
Real,
|
|
|
|
CPU,
|
|
|
|
Memory,
|
|
|
|
MemorySample,
|
|
|
|
MemoryPeak,
|
2022-11-24 19:54:39 +00:00
|
|
|
ProfileEvent,
|
2022-01-11 19:30:55 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/// This is the second part of TraceCollector, that sends stacktrace to the pipe.
|
|
|
|
/// It has been split out to avoid dependency from interpreters part.
|
|
|
|
class TraceSender
|
|
|
|
{
|
|
|
|
public:
|
2022-11-24 19:54:39 +00:00
|
|
|
struct Extras
|
|
|
|
{
|
2022-12-06 16:09:54 +00:00
|
|
|
/// size, ptr - for memory tracing is the amount of memory allocated; for other trace types it is 0.
|
2022-11-24 19:54:39 +00:00
|
|
|
Int64 size{};
|
2022-12-06 16:09:54 +00:00
|
|
|
void * ptr = nullptr;
|
2022-11-24 19:54:39 +00:00
|
|
|
/// Event type and increment for 'ProfileEvent' trace type; for other trace types defaults.
|
|
|
|
ProfileEvents::Event event{ProfileEvents::end()};
|
|
|
|
ProfileEvents::Count increment{};
|
|
|
|
};
|
|
|
|
|
2022-01-11 19:30:55 +00:00
|
|
|
/// Collect a stack trace. This method is signal safe.
|
|
|
|
/// Precondition: the TraceCollector object must be created.
|
2022-11-24 19:54:39 +00:00
|
|
|
static void send(TraceType trace_type, const StackTrace & stack_trace, Extras extras);
|
2022-01-11 19:30:55 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
friend class TraceCollector;
|
|
|
|
static LazyPipeFDs pipe;
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|