do not run trace collector without trace_log. do not run query profilers without trace collector.

This commit is contained in:
Nikita Lapkov 2019-07-06 20:29:00 +00:00
parent 17e3542a5a
commit ef1d84b35a
3 changed files with 19 additions and 5 deletions

View File

@ -292,7 +292,7 @@ struct ContextShared
ddl_worker.reset();
/// Trace collector is only initialized in server program
if (trace_collector != nullptr)
if (hasTraceCollector())
{
/// Stop trace collector
NotifyTraceCollectorToStop();
@ -304,8 +304,15 @@ struct ContextShared
}
}
bool hasTraceCollector() {
return trace_collector != nullptr;
}
void initializeTraceCollector(std::shared_ptr<TraceLog> trace_log)
{
if (trace_log == nullptr)
return;
trace_pipe.open();
trace_collector.reset(new TraceCollector(trace_log));
trace_collector_thread.start(*trace_collector);
@ -1646,6 +1653,11 @@ void Context::initializeSystemLogs()
shared->system_logs.emplace(*global_context, getConfigRef());
}
bool Context::hasTraceCollector()
{
return shared->hasTraceCollector();
}
void Context::initializeTraceCollector()
{
shared->initializeTraceCollector(getTraceLog());

View File

@ -416,6 +416,7 @@ public:
void initializeSystemLogs();
void initializeTraceCollector();
bool hasTraceCollector();
/// Nullptr if the query log is not ready for this moment.
std::shared_ptr<QueryLog> getQueryLog();

View File

@ -126,8 +126,9 @@ void ThreadStatus::finalizePerformanceCounters()
void ThreadStatus::initQueryProfiler()
{
if (!query_context)
throw Exception("Can't init query profiler without query context", ErrorCodes::LOGICAL_ERROR);
/// query profilers are useless without trace collector
if (!global_context->hasTraceCollector())
return;
auto & settings = query_context->getSettingsRef();
@ -146,8 +147,8 @@ void ThreadStatus::initQueryProfiler()
void ThreadStatus::finalizeQueryProfiler()
{
query_profiler_real.reset(nullptr);
query_profiler_cpu.reset(nullptr);
query_profiler_real.reset();
query_profiler_cpu.reset();
}
void ThreadStatus::detachQuery(bool exit_if_already_detached, bool thread_exits)