2018-05-29 18:14:31 +00:00
|
|
|
#pragma once
|
|
|
|
#include <memory>
|
|
|
|
|
|
|
|
|
|
|
|
namespace ProfileEvents
|
|
|
|
{
|
2018-05-31 15:54:08 +00:00
|
|
|
class Counters;
|
2018-05-29 18:14:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
class MemoryTracker;
|
|
|
|
|
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
|
|
|
class QueryStatus;
|
|
|
|
class ThreadStatus;
|
2018-05-31 15:54:08 +00:00
|
|
|
struct Progress;
|
2018-05-29 18:14:31 +00:00
|
|
|
using ThreadStatusPtr = std::shared_ptr<ThreadStatus>;
|
|
|
|
|
|
|
|
|
|
|
|
class CurrentThread
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
|
|
|
static ThreadStatusPtr get();
|
|
|
|
|
2018-06-01 19:39:32 +00:00
|
|
|
/// Call when thread accepted connection (but haven't called executeQuery())
|
|
|
|
/// Currently it is used only for debugging
|
|
|
|
static void initializeQuery();
|
2018-05-29 18:14:31 +00:00
|
|
|
|
2018-06-01 19:39:32 +00:00
|
|
|
/// You must call one of these methods when create a child thread:
|
2018-05-29 18:14:31 +00:00
|
|
|
/// Bundles the current thread with a query
|
|
|
|
static void attachQuery(QueryStatus * parent_process);
|
|
|
|
/// Bundles the current thread with a query bundled to the sibling thread
|
|
|
|
static void attachQueryFromSiblingThread(const ThreadStatusPtr & sibling_thread);
|
|
|
|
/// Is useful for a ThreadPool tasks
|
|
|
|
static void attachQueryFromSiblingThreadIfDetached(const ThreadStatusPtr & sibling_thread);
|
|
|
|
|
2018-06-01 19:39:32 +00:00
|
|
|
/// Makes system calls to update ProfileEvents derived from rusage and taskstats
|
2018-05-29 18:14:31 +00:00
|
|
|
static void updatePerformanceCounters();
|
2018-06-01 19:39:32 +00:00
|
|
|
|
2018-05-29 18:14:31 +00:00
|
|
|
static ProfileEvents::Counters & getProfileEvents();
|
|
|
|
static MemoryTracker & getMemoryTracker();
|
2018-05-31 15:54:08 +00:00
|
|
|
static void updateProgressIn(const Progress & value);
|
|
|
|
static void updateProgressOut(const Progress & value);
|
2018-05-29 18:14:31 +00:00
|
|
|
|
2018-05-31 15:54:08 +00:00
|
|
|
/// Non-master threads call this method in destructor automatically
|
2018-05-29 18:14:31 +00:00
|
|
|
static void detachQuery();
|
|
|
|
|
|
|
|
private:
|
2018-05-31 15:54:08 +00:00
|
|
|
static void attachQueryFromSiblingThreadImpl(ThreadStatusPtr sibling_thread, bool check_detached = true);
|
2018-05-29 18:14:31 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|