ClickHouse/dbms/Common/TraceCollector.h

45 lines
785 B
C++
Raw Normal View History

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;
enum class TraceType : uint8_t
2020-01-16 12:37:29 +00:00
{
Real,
CPU,
Memory,
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:
TraceCollector(std::shared_ptr<TraceLog> trace_log_);
2020-01-16 12:37:29 +00:00
~TraceCollector();
/// 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.
static void collect(TraceType trace_type, const StackTrace & stack_trace, UInt64 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();
void stop();
2019-07-10 20:47:39 +00:00
};
}