mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-10 01:25:21 +00:00
Attempt to fix
This commit is contained in:
parent
88095b636e
commit
634d3bedd3
@ -156,17 +156,13 @@ void ThreadStatus::finalizePerformanceCounters()
|
||||
void ThreadStatus::initQueryProfiler()
|
||||
{
|
||||
/// query profilers are useless without trace collector
|
||||
if (!global_context)
|
||||
if (!global_context || !ext::Singleton<TraceCollector>::isInitialized())
|
||||
return;
|
||||
|
||||
const auto & settings = query_context->getSettingsRef();
|
||||
|
||||
try
|
||||
{
|
||||
/// Force initialization of TraceCollector instance before setting signal handlers,
|
||||
/// because the constructor is not async-signal-safe.
|
||||
ext::Singleton<TraceCollector> initialize __attribute__((unused));
|
||||
|
||||
if (settings.query_profiler_real_time_period_ns > 0)
|
||||
query_profiler_real = std::make_unique<QueryProfilerReal>(thread_id,
|
||||
/* period */ static_cast<UInt32>(settings.query_profiler_real_time_period_ns));
|
||||
|
@ -1,33 +1,18 @@
|
||||
#pragma once
|
||||
|
||||
#include <memory>
|
||||
#include <type_traits>
|
||||
|
||||
namespace ext {
|
||||
|
||||
template <class T, typename DefaultConstructable = void>
|
||||
class Singleton;
|
||||
|
||||
/// For default-constructable type we don't need to implement |create()|
|
||||
/// and may use "arrow" operator immediately.
|
||||
template <class T>
|
||||
class Singleton<T, std::enable_if_t<std::is_default_constructible_v<T>>>
|
||||
class Singleton
|
||||
{
|
||||
public:
|
||||
T * operator->()
|
||||
Singleton()
|
||||
{
|
||||
static T instance;
|
||||
return &instance;
|
||||
if (!instance)
|
||||
instance.reset(new T);
|
||||
}
|
||||
};
|
||||
|
||||
/// For custom-constructed type we have to construct |Singleton| object with non-default constructor once
|
||||
/// before any use of "arrow" operator.
|
||||
template <class T>
|
||||
class Singleton<T, std::enable_if_t<!std::is_default_constructible_v<T>>>
|
||||
{
|
||||
public:
|
||||
Singleton() = default;
|
||||
|
||||
template <typename ... Args>
|
||||
Singleton(const Args & ... args)
|
||||
@ -41,6 +26,10 @@ public:
|
||||
return instance.get();
|
||||
}
|
||||
|
||||
static bool isInitialized() {
|
||||
return !!instance;
|
||||
}
|
||||
|
||||
private:
|
||||
inline static std::unique_ptr<T> instance{};
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user