2018-02-01 17:55:08 +00:00
|
|
|
#pragma once
|
|
|
|
#include <Common/ProfileEvents.h>
|
|
|
|
#include <Common/MemoryTracker.h>
|
|
|
|
#include <memory>
|
2018-03-01 16:52:24 +00:00
|
|
|
#include <mutex>
|
|
|
|
|
2018-02-01 17:55:08 +00:00
|
|
|
|
|
|
|
namespace Poco
|
|
|
|
{
|
|
|
|
class Logger;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
2018-05-17 16:01:41 +00:00
|
|
|
class QueryStatus;
|
|
|
|
class ThreadStatus;
|
2018-05-29 18:14:31 +00:00
|
|
|
class ScopeCurrentThread;
|
2018-02-01 17:55:08 +00:00
|
|
|
using ThreadStatusPtr = std::shared_ptr<ThreadStatus>;
|
|
|
|
|
|
|
|
|
2018-05-29 18:14:31 +00:00
|
|
|
extern thread_local ThreadStatusPtr current_thread;
|
|
|
|
|
|
|
|
|
|
|
|
class ThreadStatus
|
2018-02-01 17:55:08 +00:00
|
|
|
{
|
2018-05-17 16:01:41 +00:00
|
|
|
public:
|
|
|
|
|
2018-02-01 17:55:08 +00:00
|
|
|
UInt32 poco_thread_number = 0;
|
|
|
|
QueryStatus * parent_query = nullptr;
|
|
|
|
ProfileEvents::Counters performance_counters;
|
|
|
|
MemoryTracker memory_tracker;
|
2018-05-17 16:01:41 +00:00
|
|
|
int os_thread_id = -1;
|
2018-03-01 16:52:24 +00:00
|
|
|
std::mutex mutex;
|
2018-02-01 17:55:08 +00:00
|
|
|
|
2018-05-29 18:14:31 +00:00
|
|
|
public:
|
|
|
|
|
|
|
|
/// A constructor
|
|
|
|
static ThreadStatusPtr create();
|
2018-02-01 17:55:08 +00:00
|
|
|
|
|
|
|
/// Reset all references and metrics
|
|
|
|
void reset();
|
|
|
|
|
|
|
|
~ThreadStatus();
|
|
|
|
|
2018-05-29 18:14:31 +00:00
|
|
|
protected:
|
2018-03-01 16:52:24 +00:00
|
|
|
|
2018-02-01 17:55:08 +00:00
|
|
|
ThreadStatus();
|
2018-05-29 18:14:31 +00:00
|
|
|
void attachQuery(
|
|
|
|
QueryStatus *parent_query_,
|
|
|
|
ProfileEvents::Counters *parent_counters,
|
|
|
|
MemoryTracker *parent_memory_tracker,
|
|
|
|
bool check_detached = true);
|
|
|
|
void detachQuery();
|
|
|
|
void updatePerfomanceCountersImpl();
|
|
|
|
|
|
|
|
bool is_active_query = false;
|
|
|
|
bool is_active_thread = false;
|
|
|
|
bool is_first_query_of_the_thread = true;
|
2018-02-01 17:55:08 +00:00
|
|
|
Poco::Logger * log;
|
|
|
|
|
2018-05-29 18:14:31 +00:00
|
|
|
friend class CurrentThreadScope;
|
|
|
|
friend class CurrentThread;
|
|
|
|
friend struct TasksStatsCounters;
|
|
|
|
|
2018-03-01 16:52:24 +00:00
|
|
|
struct Impl;
|
2018-05-29 18:14:31 +00:00
|
|
|
std::unique_ptr<Impl> impl;
|
|
|
|
Impl & getImpl() { return *impl; }
|
2018-02-01 17:55:08 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|