ClickHouse/dbms/src/Common/CurrentThread.cpp

91 lines
2.2 KiB
C++
Raw Normal View History

#include <memory>
2018-05-29 18:14:31 +00:00
#include "CurrentThread.h"
#include <common/logger_useful.h>
2019-01-13 18:51:57 +00:00
#include <common/likely.h>
#include <Common/ThreadStatus.h>
#include <Common/TaskStatsInfoGetter.h>
2018-05-29 18:14:31 +00:00
#include <Interpreters/ProcessList.h>
#include <Interpreters/Context.h>
#include <common/getThreadNumber.h>
#include <Poco/Logger.h>
2018-05-29 18:14:31 +00:00
namespace DB
{
namespace ErrorCodes
{
extern const int LOGICAL_ERROR;
}
void CurrentThread::updatePerformanceCounters()
{
if (unlikely(!current_thread))
return;
current_thread->updatePerformanceCounters();
}
2018-05-29 18:14:31 +00:00
2019-01-13 18:51:57 +00:00
ThreadStatus & CurrentThread::get()
2018-05-29 18:14:31 +00:00
{
2019-01-13 18:51:57 +00:00
if (unlikely(!current_thread))
throw Exception("Thread #" + std::to_string(getThreadNumber()) + " status was not initialized", ErrorCodes::LOGICAL_ERROR);
2018-05-29 18:14:31 +00:00
2019-01-13 18:51:57 +00:00
return *current_thread;
}
2018-05-29 18:14:31 +00:00
ProfileEvents::Counters & CurrentThread::getProfileEvents()
{
return current_thread ? current_thread->performance_counters : ProfileEvents::global_counters;
2018-05-29 18:14:31 +00:00
}
MemoryTracker * CurrentThread::getMemoryTracker()
2018-05-29 18:14:31 +00:00
{
if (unlikely(!current_thread))
return nullptr;
return &current_thread->memory_tracker;
2018-05-29 18:14:31 +00:00
}
void CurrentThread::updateProgressIn(const Progress & value)
{
if (unlikely(!current_thread))
return;
current_thread->progress_in.incrementPiecewiseAtomically(value);
}
void CurrentThread::updateProgressOut(const Progress & value)
{
if (unlikely(!current_thread))
return;
current_thread->progress_out.incrementPiecewiseAtomically(value);
}
void CurrentThread::attachInternalTextLogsQueue(const std::shared_ptr<InternalTextLogsQueue> & logs_queue)
{
if (unlikely(!current_thread))
return;
current_thread->attachInternalTextLogsQueue(logs_queue);
}
std::shared_ptr<InternalTextLogsQueue> CurrentThread::getInternalTextLogsQueue()
{
/// NOTE: this method could be called at early server startup stage
if (unlikely(!current_thread))
return nullptr;
if (current_thread->getCurrentState() == ThreadStatus::ThreadState::Died)
return nullptr;
return current_thread->getInternalTextLogsQueue();
2018-05-29 18:14:31 +00:00
}
ThreadGroupStatusPtr CurrentThread::getGroup()
{
if (unlikely(!current_thread))
2019-01-25 18:44:30 +00:00
return nullptr;
return current_thread->getThreadGroup();
}
2018-05-29 18:14:31 +00:00
}