2018-02-01 17:55:08 +00:00
|
|
|
#pragma once
|
|
|
|
#include <Common/ProfileEvents.h>
|
|
|
|
#include <Common/MemoryTracker.h>
|
|
|
|
#include <memory>
|
|
|
|
#include <ext/shared_ptr_helper.h>
|
2018-03-01 16:52:24 +00:00
|
|
|
#include <mutex>
|
|
|
|
|
2018-02-01 17:55:08 +00:00
|
|
|
|
|
|
|
namespace Poco
|
|
|
|
{
|
|
|
|
class Logger;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
|
|
|
struct QueryStatus;
|
|
|
|
struct ThreadStatus;
|
2018-03-01 16:52:24 +00:00
|
|
|
struct ScopeCurrentThread;
|
2018-02-01 17:55:08 +00:00
|
|
|
using ThreadStatusPtr = std::shared_ptr<ThreadStatus>;
|
|
|
|
|
|
|
|
|
2018-03-01 16:52:24 +00:00
|
|
|
struct ThreadStatus : public ext::shared_ptr_helper<ThreadStatus>
|
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-03-01 16:52:24 +00:00
|
|
|
bool thread_exited = false;
|
|
|
|
std::mutex mutex;
|
2018-02-01 17:55:08 +00:00
|
|
|
|
|
|
|
void init(QueryStatus * parent_query_, ProfileEvents::Counters * parent_counters, MemoryTracker * parent_memory_tracker);
|
|
|
|
void onStart();
|
|
|
|
void onExit();
|
|
|
|
|
|
|
|
/// Reset all references and metrics
|
|
|
|
void reset();
|
|
|
|
|
|
|
|
static void setCurrentThreadParentQuery(QueryStatus * parent_process);
|
|
|
|
static void setCurrentThreadFromSibling(const ThreadStatusPtr & sibling_thread);
|
|
|
|
|
|
|
|
~ThreadStatus();
|
|
|
|
|
2018-03-01 16:52:24 +00:00
|
|
|
friend struct ScopeCurrentThread;
|
|
|
|
|
|
|
|
//protected:
|
2018-02-01 17:55:08 +00:00
|
|
|
ThreadStatus();
|
|
|
|
|
|
|
|
bool initialized = false;
|
|
|
|
Poco::Logger * log;
|
|
|
|
|
2018-03-01 16:52:24 +00:00
|
|
|
struct Impl;
|
|
|
|
std::shared_ptr<Impl> impl;
|
2018-02-01 17:55:08 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
extern thread_local ThreadStatusPtr current_thread;
|
|
|
|
|
|
|
|
}
|