2019-07-10 20:47:39 +00:00
|
|
|
#pragma once
|
|
|
|
|
2020-01-16 12:37:29 +00:00
|
|
|
#include "Common/PipeFDs.h"
|
2019-07-10 20:47:39 +00:00
|
|
|
#include <Common/ThreadPool.h>
|
|
|
|
|
2020-01-16 12:37:29 +00:00
|
|
|
class StackTrace;
|
|
|
|
|
2019-07-10 20:47:39 +00:00
|
|
|
namespace Poco
|
|
|
|
{
|
|
|
|
class Logger;
|
|
|
|
}
|
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
|
|
|
class TraceLog;
|
|
|
|
|
2020-03-03 00:24:44 +00:00
|
|
|
enum class TraceType : uint8_t
|
2020-01-16 12:37:29 +00:00
|
|
|
{
|
2020-03-03 00:24:44 +00:00
|
|
|
Real,
|
|
|
|
CPU,
|
|
|
|
Memory,
|
2021-10-07 18:13:56 +00:00
|
|
|
MemorySample,
|
|
|
|
MemoryPeak,
|
2020-01-16 12:37:29 +00:00
|
|
|
};
|
|
|
|
|
2019-07-10 20:47:39 +00:00
|
|
|
class TraceCollector
|
|
|
|
{
|
2020-01-16 12:37:29 +00:00
|
|
|
public:
|
2020-03-03 00:24:44 +00:00
|
|
|
TraceCollector(std::shared_ptr<TraceLog> trace_log_);
|
2020-01-16 12:37:29 +00:00
|
|
|
~TraceCollector();
|
|
|
|
|
2020-03-03 00:24:44 +00:00
|
|
|
/// Collect a stack trace. This method is signal safe.
|
|
|
|
/// Precondition: the TraceCollector object must be created.
|
|
|
|
/// size - for memory tracing is the amount of memory allocated; for other trace types it is 0.
|
2020-04-30 13:25:17 +00:00
|
|
|
static void collect(TraceType trace_type, const StackTrace & stack_trace, Int64 size);
|
2020-01-16 12:37:29 +00:00
|
|
|
|
2019-07-10 20:47:39 +00:00
|
|
|
private:
|
|
|
|
std::shared_ptr<TraceLog> trace_log;
|
|
|
|
ThreadFromGlobalPool thread;
|
|
|
|
|
|
|
|
void run();
|
2020-02-11 15:16:53 +00:00
|
|
|
void stop();
|
2019-07-10 20:47:39 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|