diff --git a/src/libs/nanotrace/nanotracehr.cpp b/src/libs/nanotrace/nanotracehr.cpp index e6bb03196da..f50f5ef44f5 100644 --- a/src/libs/nanotrace/nanotracehr.cpp +++ b/src/libs/nanotrace/nanotracehr.cpp @@ -45,8 +45,7 @@ unsigned int getUnsignedIntegerHash(std::thread::id id) return static_cast(std::hash{}(id) & 0xFFFFFFFF); } -template -constexpr bool isArgumentValid(const StaticString &string) +constexpr bool isArgumentValid(const ArgumentsString &string) { return string.isValid() && string.size(); } @@ -171,7 +170,7 @@ void flushEvents(const Utils::span events, } } -template NANOTRACE_EXPORT void flushEvents(const Utils::span events, +template NANOTRACE_EXPORT void flushEvents(const Utils::span events, std::thread::id threadId, std::shared_ptr file); @@ -226,8 +225,7 @@ void flushInThread(EnabledEventQueue &eventQueue) eventQueue.eventsIndex = 0; } -template NANOTRACE_EXPORT void flushInThread( - EnabledEventQueue &eventQueue); +template NANOTRACE_EXPORT void flushInThread(EnabledEventQueue &eventQueue); template NANOTRACE_EXPORT void flushInThread(EnabledEventQueue &eventQueue); template @@ -273,8 +271,7 @@ void EventQueue::flush() file.reset(); } -template class NANOTRACE_EXPORT_TEMPLATE - EventQueue; +template class NANOTRACE_EXPORT_TEMPLATE EventQueue; template class NANOTRACE_EXPORT_TEMPLATE EventQueue; } // namespace NanotraceHR diff --git a/src/libs/nanotrace/nanotracehr.h b/src/libs/nanotrace/nanotracehr.h index 92041f2af8b..49ed2563577 100644 --- a/src/libs/nanotrace/nanotracehr.h +++ b/src/libs/nanotrace/nanotracehr.h @@ -49,7 +49,7 @@ enum class Tracing { IsDisabled, IsEnabled }; # define NO_UNIQUE_ADDRESS #endif -using ArgumentsString = StaticString<3700>; +using ArgumentsString = StaticString; namespace Literals { struct TracerLiteral @@ -98,9 +98,7 @@ template concept HasTupleSize = requires { std::tuple_size_v == size; }; template -concept CanConvert = requires(Entry entry, StaticString<1000> string) { - convertToString(string, entry); -}; +concept CanConvert = requires(Entry entry, StaticString string) { convertToString(string, entry); }; namespace Internal { template @@ -413,15 +411,11 @@ struct TraceEventWithoutArguments char type = ' '; }; -template -struct alignas(4096) TraceEvent : public TraceEventWithoutArguments +struct alignas(4096) TraceEventWithArguments : public TraceEventWithoutArguments { - using ArgumentsStringType = ArgumentsString; - ArgumentsString arguments; }; -using StringViewWithStringArgumentsTraceEvent = TraceEvent; enum class IsEnabled { No, Yes }; @@ -431,12 +425,13 @@ class EventQueue; template using EnabledEventQueue = EventQueue; -using EnabledEventQueueWithoutArguments = EventQueue; +using EnabledEventQueueWithArguments = EnabledEventQueue; + +using EnabledEventQueueWithoutArguments = EnabledEventQueue; template void flushInThread(EnabledEventQueue &eventQueue); -extern template NANOTRACE_EXPORT void flushInThread( - EnabledEventQueue &eventQueue); +extern template NANOTRACE_EXPORT void flushInThread(EnabledEventQueue &eventQueue); extern template NANOTRACE_EXPORT void flushInThread( EnabledEventQueue &eventQueue); @@ -598,13 +593,12 @@ public: }; template -using StringViewWithStringArgumentsEventQueue = EventQueue; - +using EventQueueWithArguments = EventQueue; template using EventQueueWithoutArguments = EventQueue; +using EnabledEventQueueWithoutArguments = EventQueueWithoutArguments; -extern template class NANOTRACE_EXPORT_EXTERN_TEMPLATE - EventQueue; +extern template class NANOTRACE_EXPORT_EXTERN_TEMPLATE EventQueue; extern template class NANOTRACE_EXPORT_EXTERN_TEMPLATE EventQueue; @@ -656,7 +650,171 @@ public: }; template -class Tracer; +class Tracer +{ +public: + Tracer() = default; + using TokenType = typename Category::TokenType; + using FlowTokenType = typename Category::FlowTokenType; + + friend TokenType; + friend FlowTokenType; + friend Category; + + [[nodiscard]] Tracer(TracerLiteral, const Category &, KeyValue auto &&...) {} + + Tracer(const Tracer &) = delete; + Tracer &operator=(const Tracer &) = delete; + Tracer(Tracer &&other) noexcept = default; + Tracer &operator=(Tracer &&other) noexcept = delete; + + TokenType createToken() { return {}; } + + Tracer beginDuration(TracerLiteral, KeyValue auto &&...) { return {}; } + + void tick(TracerLiteral, KeyValue auto &&...) {} + + void end(KeyValue auto &&...) {} + + ~Tracer() {} +}; + +template +class Tracer +{ + using TokenType = typename Category::TokenType; + using FlowTokenType = typename Category::FlowTokenType; + using PrivateTag = typename Category::PrivateTag; + using CategoryFunctionPointer = typename Category::CategoryFunctionPointer; + + friend FlowTokenType; + friend TokenType; + friend Category; + + template + [[nodiscard]] Tracer(std::size_t bindId, + IsFlow flow, + TracerLiteral name, + CategoryFunctionPointer category, + Arguments &&...arguments) + : m_name{name} + , m_bindId{bindId} + , flow{flow} + , m_category{category} + { + if (category().isEnabled == IsEnabled::Yes) + sendBeginTrace(std::forward(arguments)...); + } + +public: + template + [[nodiscard]] Tracer(PrivateTag, + std::size_t bindId, + IsFlow flow, + TracerLiteral name, + CategoryFunctionPointer category, + Arguments &&...arguments) + : Tracer{bindId, flow, std::move(name), category, std::forward(arguments)...} + {} + + template + [[nodiscard]] Tracer(TracerLiteral name, CategoryFunctionPointer category, Arguments &&...arguments) + : m_name{name} + , m_category{category} + { + if (category().isEnabled == IsEnabled::Yes) + sendBeginTrace(std::forward(arguments)...); + } + + template + [[nodiscard]] Tracer(TracerLiteral name, Category &category, Arguments &&...arguments) + : Tracer(std::move(name), category.self(), std::forward(arguments)...) + {} + + Tracer(const Tracer &) = delete; + Tracer &operator=(const Tracer &) = delete; + Tracer(Tracer &&other) noexcept = delete; + Tracer &operator=(Tracer &&other) noexcept = delete; + + TokenType createToken() { return {0, m_category}; } + + ~Tracer() { sendEndTrace(); } + + template + Tracer beginDuration(TracerLiteral name, Arguments &&...arguments) + { + return {std::move(name), m_category, std::forward(arguments)...}; + } + + template + void tick(TracerLiteral name, Arguments &&...arguments) + { + m_category().begin('i', 0, name, 0, IsFlow::No, std::forward(arguments)...); + } + + template + void end(Arguments &&...arguments) + { + sendEndTrace(std::forward(arguments)...); + m_name = {}; + } + +private: + template + void sendBeginTrace(Arguments &&...arguments) + { + auto &category = m_category(); + if (category.isEnabled == IsEnabled::Yes) { + auto &traceEvent = getTraceEvent(category.eventQueue(arguments...)); + traceEvent.name = m_name; + traceEvent.category = category.name(); + traceEvent.bindId = m_bindId; + traceEvent.flow = flow; + traceEvent.type = 'B'; + if constexpr (sizeof...(arguments)) { + Internal::setArguments(traceEvent.arguments, + std::forward(arguments)...); + } + traceEvent.time = Clock::now(); + } + } + + template + void sendEndTrace(Arguments &&...arguments) + { + if (m_name.size()) { + auto &category = m_category(); + if (category.isEnabled == IsEnabled::Yes) { + auto end = Clock::now(); + auto &traceEvent = getTraceEvent(category.eventQueue(arguments...)); + traceEvent.name = std::move(m_name); + traceEvent.category = category.name(); + traceEvent.time = end; + traceEvent.bindId = m_bindId; + traceEvent.flow = flow; + traceEvent.type = 'E'; + if constexpr (sizeof...(arguments)) { + Internal::setArguments(traceEvent.arguments, + std::forward(arguments)...); + } + } + } + } + +private: + std::string_view m_name; + std::size_t m_bindId = 0; + IsFlow flow = IsFlow::No; + CategoryFunctionPointer m_category; +}; + +template +Tracer(TracerLiteral name, Category &category, Arguments &&...) + -> Tracer; + +template +Tracer(TracerLiteral name, const Category &category, Arguments &&...) + -> Tracer; template class Token : public BasicDisabledToken @@ -1130,8 +1288,7 @@ private: CategoryFunctionPointer m_category = nullptr; }; -template -class Category +class DisabledCategory { public: class SourceLocation @@ -1143,23 +1300,24 @@ public: }; using IsActive = std::false_type; - using ArgumentsStringType = typename TraceEvent::ArgumentsStringType; - using AsynchronousTokenType = AsynchronousToken; - using FlowTokenType = FlowToken; - using TracerType = Tracer; - using TokenType = Token; - using CategoryFunctionPointer = Category &(*) (); + using AsynchronousTokenType = AsynchronousToken; + using FlowTokenType = FlowToken; + using TracerType = Tracer; + using TokenType = Token; + using CategoryFunctionPointer = DisabledCategory &(*) (); - Category(TracerLiteral, - EventQueue &, - EventQueueWithoutArguments &, - CategoryFunctionPointer) + DisabledCategory() = default; + + DisabledCategory(TracerLiteral, + EventQueueWithArguments &, + EventQueueWithoutArguments &, + CategoryFunctionPointer) {} - Category(TracerLiteral, - EventQueue &, - EventQueueWithoutArguments &, - CategoryFunctionPointer) + DisabledCategory(TracerLiteral, + EventQueueWithArguments &, + EventQueueWithoutArguments &, + CategoryFunctionPointer) {} template @@ -1171,7 +1329,9 @@ public: template [[nodiscard]] std::pair beginAsynchronousWithFlow( TracerLiteral, Arguments &&...) - {} + { + return {}; + } template [[nodiscard]] TracerType beginDuration(TracerLiteral, Arguments &&...) @@ -1193,8 +1353,7 @@ public: static constexpr bool isActive() { return false; } }; -template -class Category +class EnabledCategory { class PrivateTag {}; @@ -1233,12 +1392,11 @@ public: }; using IsActive = std::true_type; - using ArgumentsStringType = typename TraceEvent::ArgumentsStringType; - using AsynchronousTokenType = AsynchronousToken; - using FlowTokenType = FlowToken; - using TracerType = Tracer; - using TokenType = Token; - using CategoryFunctionPointer = Category &(*) (); + using AsynchronousTokenType = AsynchronousToken; + using FlowTokenType = FlowToken; + using TracerType = Tracer; + using TokenType = Token; + using CategoryFunctionPointer = EnabledCategory &(*) (); friend AsynchronousTokenType; friend TokenType; @@ -1246,10 +1404,10 @@ public: friend TracerType; template - Category(TracerLiteral name, - EventQueue &queue, - EnabledEventQueueWithoutArguments &eventQueueWithoutArguments, - CategoryFunctionPointer self) + EnabledCategory(TracerLiteral name, + EventQueue &queue, + EnabledEventQueueWithoutArguments &eventQueueWithoutArguments, + CategoryFunctionPointer self) : m_name{std::move(name)} , m_eventQueue{queue} , m_eventQueueWithoutArguments{eventQueueWithoutArguments} @@ -1261,8 +1419,8 @@ public: m_bindIdCounter = m_globalBindIdCounter += 1ULL << 32; } - Category(const Category &) = delete; - Category &operator=(const Category &) = delete; + EnabledCategory(const EnabledCategory &) = delete; + EnabledCategory &operator=(const EnabledCategory &) = delete; template [[nodiscard]] AsynchronousTokenType beginAsynchronous(TracerLiteral traceName, @@ -1292,7 +1450,7 @@ public: template [[nodiscard]] TracerType beginDuration(TracerLiteral traceName, Arguments &&...arguments) { - return {traceName, m_self, std::forward(arguments)...}; + return TracerType{traceName, m_self, std::forward(arguments)...}; } template @@ -1333,7 +1491,7 @@ public: EnabledEventQueueWithoutArguments &eventQueue() const { return m_eventQueueWithoutArguments; } template - EnabledEventQueue &eventQueue(const Arguments &...) const + EnabledEventQueueWithArguments &eventQueue(const Arguments &...) const { return m_eventQueue; } @@ -1425,7 +1583,7 @@ private: private: std::string_view m_name; - EnabledEventQueue &m_eventQueue; + EnabledEventQueueWithArguments &m_eventQueue; EnabledEventQueueWithoutArguments &m_eventQueueWithoutArguments; inline static std::atomic m_globalIdCounter; std::size_t m_idCounter; @@ -1434,171 +1592,4 @@ private: CategoryFunctionPointer m_self; }; -template -using StringViewWithStringArgumentsCategory = Category; - -template -class Tracer -{ -public: - Tracer() = default; - using TokenType = typename Category::TokenType; - using FlowTokenType = typename Category::FlowTokenType; - - friend TokenType; - friend FlowTokenType; - friend Category; - - [[nodiscard]] Tracer(TracerLiteral, Category &, KeyValue auto &&...) {} - - Tracer(const Tracer &) = delete; - Tracer &operator=(const Tracer &) = delete; - Tracer(Tracer &&other) noexcept = default; - Tracer &operator=(Tracer &&other) noexcept = delete; - - TokenType createToken() { return {}; } - - Tracer beginDuration(TracerLiteral, KeyValue auto &&...) { return {}; } - - void tick(TracerLiteral, KeyValue auto &&...) {} - - void end(KeyValue auto &&...) {} - - ~Tracer() {} -}; - -template -class Tracer -{ - using ArgumentsStringType = typename Category::ArgumentsStringType; - using TokenType = typename Category::TokenType; - using FlowTokenType = typename Category::FlowTokenType; - using PrivateTag = typename Category::PrivateTag; - using CategoryFunctionPointer = typename Category::CategoryFunctionPointer; - - friend FlowTokenType; - friend TokenType; - friend Category; - - template - [[nodiscard]] Tracer(std::size_t bindId, - IsFlow flow, - TracerLiteral name, - CategoryFunctionPointer category, - Arguments &&...arguments) - : m_name{name} - , m_bindId{bindId} - , flow{flow} - , m_category{category} - { - if (category().isEnabled == IsEnabled::Yes) - sendBeginTrace(std::forward(arguments)...); - } - -public: - template - [[nodiscard]] Tracer(PrivateTag, - std::size_t bindId, - IsFlow flow, - TracerLiteral name, - CategoryFunctionPointer category, - Arguments &&...arguments) - : Tracer{bindId, flow, std::move(name), category, std::forward(arguments)...} - {} - - template - [[nodiscard]] Tracer(TracerLiteral name, CategoryFunctionPointer category, Arguments &&...arguments) - : m_name{name} - , m_category{category} - { - if (category().isEnabled == IsEnabled::Yes) - sendBeginTrace(std::forward(arguments)...); - } - - template - [[nodiscard]] Tracer(TracerLiteral name, Category &category, Arguments &&...arguments) - : Tracer(std::move(name), category.self(), std::forward(arguments)...) - {} - - Tracer(const Tracer &) = delete; - Tracer &operator=(const Tracer &) = delete; - Tracer(Tracer &&other) noexcept = delete; - Tracer &operator=(Tracer &&other) noexcept = delete; - - TokenType createToken() { return {0, m_category}; } - - ~Tracer() { sendEndTrace(); } - - template - Tracer beginDuration(TracerLiteral name, Arguments &&...arguments) - { - return {std::move(name), m_category, std::forward(arguments)...}; - } - - template - void tick(TracerLiteral name, Arguments &&...arguments) - { - m_category().begin('i', 0, name, 0, IsFlow::No, std::forward(arguments)...); - } - - template - void end(Arguments &&...arguments) - { - sendEndTrace(std::forward(arguments)...); - m_name = {}; - } - -private: - template - void sendBeginTrace(Arguments &&...arguments) - { - auto &category = m_category(); - if (category.isEnabled == IsEnabled::Yes) { - auto &traceEvent = getTraceEvent(category.eventQueue(arguments...)); - traceEvent.name = m_name; - traceEvent.category = category.name(); - traceEvent.bindId = m_bindId; - traceEvent.flow = flow; - traceEvent.type = 'B'; - if constexpr (sizeof...(arguments)) { - Internal::setArguments(traceEvent.arguments, - std::forward(arguments)...); - } - traceEvent.time = Clock::now(); - } - } - - template - void sendEndTrace(Arguments &&...arguments) - { - if (m_name.size()) { - auto &category = m_category(); - if (category.isEnabled == IsEnabled::Yes) { - auto end = Clock::now(); - auto &traceEvent = getTraceEvent(category.eventQueue(arguments...)); - traceEvent.name = std::move(m_name); - traceEvent.category = category.name(); - traceEvent.time = end; - traceEvent.bindId = m_bindId; - traceEvent.flow = flow; - traceEvent.type = 'E'; - if constexpr (sizeof...(arguments)) { - Internal::setArguments(traceEvent.arguments, - std::forward(arguments)...); - } - } - } - } - -private: - std::string_view m_name; - std::size_t m_bindId = 0; - IsFlow flow = IsFlow::No; - CategoryFunctionPointer m_category; -}; - -template -Tracer(TracerLiteral name, Category &category, Arguments &&...) - -> Tracer; - } // namespace NanotraceHR diff --git a/src/libs/nanotrace/staticstring.h b/src/libs/nanotrace/staticstring.h index 64f737c175a..9889fe0d2a2 100644 --- a/src/libs/nanotrace/staticstring.h +++ b/src/libs/nanotrace/staticstring.h @@ -11,7 +11,6 @@ namespace NanotraceHR { -template class StaticString { public: @@ -27,13 +26,13 @@ public: { auto newSize = m_size + string.size(); - if (newSize <= Capacity) { + if (newSize <= capacity) { std::char_traits::copy(std::next(data(), static_cast(m_size)), string.data(), string.size()); m_size = newSize; } else { - m_size = Capacity + 1; + m_size = capacity + 1; } } @@ -41,13 +40,13 @@ public: { auto newSize = m_size + 1; - if (newSize <= Capacity) { + if (newSize <= capacity) { auto current = std::next(data(), static_cast(m_size)); *current = character; m_size = newSize; } else { - m_size = Capacity + 1; + m_size = capacity + 1; } } @@ -103,7 +102,7 @@ public: return *this; } - bool isValid() const { return m_size <= Capacity; } + constexpr bool isValid() const { return m_size <= capacity; } std::size_t size() const { return m_size; } @@ -115,7 +114,8 @@ public: void clear() { m_size = 0; } private: - std::array m_data; + inline static constexpr std::size_t capacity = 3700; + std::array m_data; std::size_t m_size = 0; }; diff --git a/src/libs/sqlite/sqlitetracing.cpp b/src/libs/sqlite/sqlitetracing.cpp index 2a8c994e971..8dad57110a8 100644 --- a/src/libs/sqlite/sqlitetracing.cpp +++ b/src/libs/sqlite/sqlitetracing.cpp @@ -5,6 +5,8 @@ namespace Sqlite { +#ifdef ENABLE_SQLITE_TRACING + std::shared_ptr traceFile() { static auto traceFile = std::make_shared("tracing.json"); @@ -14,32 +16,30 @@ std::shared_ptr traceFile() namespace { -thread_local NanotraceHR::StringViewWithStringArgumentsEventQueue eventQueue( - traceFile()); -thread_local NanotraceHR::EventQueueWithoutArguments eventQueueWithoutArguments( - traceFile()); +thread_local NanotraceHR::EnabledEventQueueWithoutArguments eventQueue(traceFile()); +thread_local NanotraceHR::EnabledEventQueueWithoutArguments eventQueueWithoutArguments(traceFile()); } // namespace -NanotraceHR::StringViewWithStringArgumentsCategory &sqliteLowLevelCategory() +NanotraceHR::EnabledCategory &sqliteLowLevelCategory() { - thread_local NanotraceHR::StringViewWithStringArgumentsCategory - sqliteLowLevelCategory_{"sqlite low level", - eventQueue, - eventQueueWithoutArguments, - sqliteLowLevelCategory}; + thread_local NanotraceHR::EnabledCategory sqliteLowLevelCategory_{"sqlite low level", + eventQueue, + eventQueueWithoutArguments, + sqliteLowLevelCategory}; return sqliteLowLevelCategory_; } -NanotraceHR::StringViewWithStringArgumentsCategory &sqliteHighLevelCategory() +NanotraceHR::EnabledCategory &sqliteHighLevelCategory() { - thread_local NanotraceHR::StringViewWithStringArgumentsCategory - sqliteHighLevelCategory_{"sqlite high level", - eventQueue, - eventQueueWithoutArguments, - sqliteHighLevelCategory}; + thread_local NanotraceHR::EnabledCategory sqliteHighLevelCategory_{"sqlite high level", + eventQueue, + eventQueueWithoutArguments, + sqliteHighLevelCategory}; return sqliteHighLevelCategory_; } +#endif + } // namespace Sqlite diff --git a/src/libs/sqlite/sqlitetracing.h b/src/libs/sqlite/sqlitetracing.h index e55d76764e6..62863be3001 100644 --- a/src/libs/sqlite/sqlitetracing.h +++ b/src/libs/sqlite/sqlitetracing.h @@ -10,22 +10,25 @@ namespace Sqlite { using namespace NanotraceHR::Literals; -constexpr NanotraceHR::Tracing sqliteTracingStatus() -{ #ifdef ENABLE_SQLITE_TRACING - return NanotraceHR::Tracing::IsEnabled; + +using TraceFile = NanotraceHR::EnabledTraceFile; + +SQLITE_EXPORT std::shared_ptr traceFile(); + +NanotraceHR::EnabledCategory &sqliteLowLevelCategory(); + +SQLITE_EXPORT NanotraceHR::EnabledCategory &sqliteHighLevelCategory(); #else - return NanotraceHR::Tracing::IsDisabled; -#endif +inline NanotraceHR::DisabledCategory sqliteLowLevelCategory() +{ + return {}; } -using TraceFile = NanotraceHR::TraceFile; - -SQLITE_EXPORT std::shared_ptr traceFile(); - -NanotraceHR::StringViewWithStringArgumentsCategory &sqliteLowLevelCategory(); - -SQLITE_EXPORT NanotraceHR::StringViewWithStringArgumentsCategory & -sqliteHighLevelCategory(); +inline NanotraceHR::DisabledCategory sqliteHighLevelCategory() +{ + return {}; +} +#endif } // namespace Sqlite diff --git a/src/plugins/qmldesigner/components/formeditor/formeditortracing.cpp b/src/plugins/qmldesigner/components/formeditor/formeditortracing.cpp index b9a3d150d67..f635b020d55 100644 --- a/src/plugins/qmldesigner/components/formeditor/formeditortracing.cpp +++ b/src/plugins/qmldesigner/components/formeditor/formeditortracing.cpp @@ -9,9 +9,12 @@ namespace QmlDesigner::FormEditorTracing { using namespace NanotraceHR::Literals; + +#ifdef ENABLE_FORM_EDITOR_TRACING + namespace { -thread_local Category category_{"model", +thread_local Category category_{"form editor", Tracing::eventQueueWithStringArguments(), Tracing::eventQueueWithoutArguments(), category}; @@ -23,4 +26,6 @@ Category &category() return category_; } +#endif + } // namespace QmlDesigner::FormEditorTracing diff --git a/src/plugins/qmldesigner/components/formeditor/formeditortracing.h b/src/plugins/qmldesigner/components/formeditor/formeditortracing.h index c54205a1a68..b4794d1f2b2 100644 --- a/src/plugins/qmldesigner/components/formeditor/formeditortracing.h +++ b/src/plugins/qmldesigner/components/formeditor/formeditortracing.h @@ -9,18 +9,22 @@ namespace QmlDesigner::FormEditorTracing { -constexpr NanotraceHR::Tracing tracingStatus() -{ #ifdef ENABLE_FORM_EDITOR_TRACING - return NanotraceHR::Tracing::IsEnabled; -#else - return NanotraceHR::Tracing::IsDisabled; -#endif -} -using Category = NanotraceHR::StringViewWithStringArgumentsCategory; +using Category = NanotraceHR::EnabledCategory; using SourceLocation = Category::SourceLocation; [[gnu::pure]] QMLDESIGNERCOMPONENTS_EXPORT Category &category(); +#else + +using Category = NanotraceHR::DisabledCategory; +using SourceLocation = Category::SourceLocation; + +inline Category category() +{ + return {}; +} + +#endif } // namespace QmlDesigner::FormEditorTracing diff --git a/src/plugins/qmldesigner/components/itemlibrary/itemlibrarytracing.cpp b/src/plugins/qmldesigner/components/itemlibrary/itemlibrarytracing.cpp index 355781718ff..a935c9459d8 100644 --- a/src/plugins/qmldesigner/components/itemlibrary/itemlibrarytracing.cpp +++ b/src/plugins/qmldesigner/components/itemlibrary/itemlibrarytracing.cpp @@ -9,9 +9,12 @@ namespace QmlDesigner::ItemLibraryTracing { using namespace NanotraceHR::Literals; + +#ifdef ENABLE_ITEM_LIBRARY_TRACING + namespace { -thread_local Category category_{"model", +thread_local Category category_{"item library", Tracing::eventQueueWithStringArguments(), Tracing::eventQueueWithoutArguments(), category}; @@ -23,4 +26,6 @@ Category &category() return category_; } +#endif + } // namespace QmlDesigner::ItemLibraryTracing diff --git a/src/plugins/qmldesigner/components/itemlibrary/itemlibrarytracing.h b/src/plugins/qmldesigner/components/itemlibrary/itemlibrarytracing.h index 5d782eb3035..989ecdb7336 100644 --- a/src/plugins/qmldesigner/components/itemlibrary/itemlibrarytracing.h +++ b/src/plugins/qmldesigner/components/itemlibrary/itemlibrarytracing.h @@ -9,18 +9,23 @@ namespace QmlDesigner::ItemLibraryTracing { -constexpr NanotraceHR::Tracing tracingStatus() -{ #ifdef ENABLE_ITEM_LIBRARY_TRACING - return NanotraceHR::Tracing::IsEnabled; -#else - return NanotraceHR::Tracing::IsDisabled; -#endif -} -using Category = NanotraceHR::StringViewWithStringArgumentsCategory; +using Category = NanotraceHR::EnabledCategory; using SourceLocation = Category::SourceLocation; [[gnu::pure]] QMLDESIGNERCOMPONENTS_EXPORT Category &category(); +#else + +using Category = NanotraceHR::DisabledCategory; +using SourceLocation = Category::SourceLocation; + +inline Category category() +{ + return {}; +} + +#endif + } // namespace QmlDesigner::ItemLibraryTracing diff --git a/src/plugins/qmldesigner/components/navigator/navigatortracing.cpp b/src/plugins/qmldesigner/components/navigator/navigatortracing.cpp index be0341812b5..4ec47d9edc6 100644 --- a/src/plugins/qmldesigner/components/navigator/navigatortracing.cpp +++ b/src/plugins/qmldesigner/components/navigator/navigatortracing.cpp @@ -9,9 +9,12 @@ namespace QmlDesigner::NavigatorTracing { using namespace NanotraceHR::Literals; + +#ifdef ENABLE_NAVIGATOR_TRACING + namespace { -thread_local Category category_{"model", +thread_local Category category_{"navigator", Tracing::eventQueueWithStringArguments(), Tracing::eventQueueWithoutArguments(), category}; @@ -23,4 +26,6 @@ Category &category() return category_; } +#endif + } // namespace QmlDesigner::NavigatorTracing diff --git a/src/plugins/qmldesigner/components/navigator/navigatortracing.h b/src/plugins/qmldesigner/components/navigator/navigatortracing.h index 45ab5def0e9..724321665a5 100644 --- a/src/plugins/qmldesigner/components/navigator/navigatortracing.h +++ b/src/plugins/qmldesigner/components/navigator/navigatortracing.h @@ -9,18 +9,23 @@ namespace QmlDesigner::NavigatorTracing { -constexpr NanotraceHR::Tracing tracingStatus() -{ #ifdef ENABLE_NAVIGATOR_TRACING - return NanotraceHR::Tracing::IsEnabled; -#else - return NanotraceHR::Tracing::IsDisabled; -#endif -} -using Category = NanotraceHR::StringViewWithStringArgumentsCategory; +using Category = NanotraceHR::EnabledCategory; using SourceLocation = Category::SourceLocation; [[gnu::pure]] QMLDESIGNERCOMPONENTS_EXPORT Category &category(); +#else + +using Category = NanotraceHR::DisabledCategory; +using SourceLocation = Category::SourceLocation; + +inline Category category() +{ + return {}; +} + +#endif + } // namespace QmlDesigner::NavigatorTracing diff --git a/src/plugins/qmldesigner/components/propertyeditor/propertyeditortracing.cpp b/src/plugins/qmldesigner/components/propertyeditor/propertyeditortracing.cpp index d641aca07df..c0e1a0785db 100644 --- a/src/plugins/qmldesigner/components/propertyeditor/propertyeditortracing.cpp +++ b/src/plugins/qmldesigner/components/propertyeditor/propertyeditortracing.cpp @@ -9,9 +9,12 @@ namespace QmlDesigner::PropertyEditorTracing { using namespace NanotraceHR::Literals; + +#ifdef ENABLE_PROPERTY_EDITOR_TRACING + namespace { -thread_local Category category_{"model", +thread_local Category category_{"property editor", Tracing::eventQueueWithStringArguments(), Tracing::eventQueueWithoutArguments(), category}; @@ -23,4 +26,6 @@ Category &category() return category_; } +#endif + } // namespace QmlDesigner::PropertyEditorTracing diff --git a/src/plugins/qmldesigner/components/propertyeditor/propertyeditortracing.h b/src/plugins/qmldesigner/components/propertyeditor/propertyeditortracing.h index db6aed68f05..e117c649fe7 100644 --- a/src/plugins/qmldesigner/components/propertyeditor/propertyeditortracing.h +++ b/src/plugins/qmldesigner/components/propertyeditor/propertyeditortracing.h @@ -9,18 +9,23 @@ namespace QmlDesigner::PropertyEditorTracing { -constexpr NanotraceHR::Tracing tracingStatus() -{ #ifdef ENABLE_PROPERTY_EDITOR_TRACING - return NanotraceHR::Tracing::IsEnabled; -#else - return NanotraceHR::Tracing::IsDisabled; -#endif -} -using Category = NanotraceHR::StringViewWithStringArgumentsCategory; +using Category = NanotraceHR::EnabledCategory; using SourceLocation = Category::SourceLocation; [[gnu::pure]] QMLDESIGNERCOMPONENTS_EXPORT Category &category(); +#else + +using Category = NanotraceHR::DisabledCategory; +using SourceLocation = Category::SourceLocation; + +inline Category category() +{ + return {}; +}; + +#endif + } // namespace QmlDesigner::PropertyEditorTracing diff --git a/src/plugins/qmldesigner/libs/designercore/imagecache/asynchronousimagecache.cpp b/src/plugins/qmldesigner/libs/designercore/imagecache/asynchronousimagecache.cpp index bf499390aba..d39eeb396af 100644 --- a/src/plugins/qmldesigner/libs/designercore/imagecache/asynchronousimagecache.cpp +++ b/src/plugins/qmldesigner/libs/designercore/imagecache/asynchronousimagecache.cpp @@ -18,6 +18,9 @@ namespace QmlDesigner { using namespace NanotraceHR::Literals; namespace ImageCache { + +#ifdef ENABLE_IMAGE_CACHE_TRACING + namespace { thread_local Category category_{"image cache", @@ -30,6 +33,9 @@ Category &category() { return category_; } + +#endif + } // namespace ImageCache AsynchronousImageCache::AsynchronousImageCache(ImageCacheStorageInterface &storage, diff --git a/src/plugins/qmldesigner/libs/designercore/include/imagecacheauxiliarydata.h b/src/plugins/qmldesigner/libs/designercore/include/imagecacheauxiliarydata.h index f9461907674..3c7a328594a 100644 --- a/src/plugins/qmldesigner/libs/designercore/include/imagecacheauxiliarydata.h +++ b/src/plugins/qmldesigner/libs/designercore/include/imagecacheauxiliarydata.h @@ -17,20 +17,27 @@ namespace QmlDesigner { namespace ImageCache { -constexpr NanotraceHR::Tracing tracingStatus() -{ #ifdef ENABLE_IMAGE_CACHE_TRACING - return NanotraceHR::Tracing::IsEnabled; -#else - return NanotraceHR::Tracing::IsDisabled; -#endif -} -using Category = NanotraceHR::StringViewWithStringArgumentsCategory; +using Category = NanotraceHR::EnabledCategory; using TraceToken = Category::FlowTokenType; using FlowToken = Category::FlowTokenType; using Token = Category::TokenType; -extern Category &category(); +[[gnu::pure]] QMLDESIGNERCORE_EXPORT Category &category(); + +#else + +using Category = NanotraceHR::DisabledCategory; +using TraceToken = Category::FlowTokenType; +using FlowToken = Category::FlowTokenType; +using Token = Category::TokenType; + +inline Category category() +{ + return {}; +} + +#endif class FontCollectorSizeAuxiliaryData { diff --git a/src/plugins/qmldesigner/libs/designercore/projectstorage/projectstorageexceptions.cpp b/src/plugins/qmldesigner/libs/designercore/projectstorage/projectstorageexceptions.cpp index 7198e581602..e4f5943e0fc 100644 --- a/src/plugins/qmldesigner/libs/designercore/projectstorage/projectstorageexceptions.cpp +++ b/src/plugins/qmldesigner/libs/designercore/projectstorage/projectstorageexceptions.cpp @@ -11,10 +11,9 @@ using namespace NanotraceHR::Literals; using NanotraceHR::keyValue; namespace { -auto &category() -{ - return ProjectStorageTracing::projectStorageCategory(); -} + +auto category = ProjectStorageTracing::projectStorageCategory; + } // namespace TypeHasInvalidSourceId::TypeHasInvalidSourceId(const Sqlite::source_location &location) diff --git a/src/plugins/qmldesigner/libs/designercore/tracing/qmldesignertracing.cpp b/src/plugins/qmldesigner/libs/designercore/tracing/qmldesignertracing.cpp index c66456a6151..7ea2a0223b8 100644 --- a/src/plugins/qmldesigner/libs/designercore/tracing/qmldesignertracing.cpp +++ b/src/plugins/qmldesigner/libs/designercore/tracing/qmldesignertracing.cpp @@ -9,34 +9,35 @@ namespace QmlDesigner { using namespace NanotraceHR::Literals; +#ifdef ENABLE_QMLDESIGNER_TRACING + namespace Tracing { namespace { -using TraceFile = NanotraceHR::TraceFile; +using TraceFile = NanotraceHR::EnabledTraceFile; auto traceFile() { - if constexpr (std::is_same_v) { - return Sqlite::traceFile(); - } else { - static auto traceFile = std::make_shared("tracing.json"); - return traceFile; - } +# ifdef ENABLE_SQLITE_TRACING + return Sqlite::traceFile(); +# else + static auto traceFile = std::make_shared("tracing.json"); + return traceFile; +# endif } } // namespace EventQueueWithStringArguments &eventQueueWithStringArguments() { - thread_local NanotraceHR::StringViewWithStringArgumentsEventQueue eventQueue( - traceFile()); + thread_local NanotraceHR::EnabledEventQueueWithArguments eventQueue(traceFile()); return eventQueue; } EventQueueWithoutArguments &eventQueueWithoutArguments() { - thread_local NanotraceHR::EventQueueWithoutArguments eventQueue(traceFile()); + thread_local NanotraceHR::EnabledEventQueueWithoutArguments eventQueue(traceFile()); return eventQueue; } @@ -44,6 +45,9 @@ EventQueueWithoutArguments &eventQueueWithoutArguments() } // namespace Tracing namespace ModelTracing { + +# ifdef ENABLE_MODEL_TRACING + namespace { thread_local Category category_{"model", @@ -58,10 +62,14 @@ Category &category() return category_; } +# endif + } // namespace ModelTracing namespace ProjectStorageTracing { +# ifdef ENABLE_PROJECT_STORAGE_TRACING + Category &projectStorageCategory() { thread_local Category category{"project storage", @@ -82,17 +90,28 @@ Category &projectStorageUpdaterCategory() return category; } +# endif + } // namespace ProjectStorageTracing namespace SourcePathStorageTracing { + +# ifdef ENABLE_SOURCE_PATH_STORAGE_TRACING + Category &category() { - thread_local Category category_{"project storage updater", + thread_local Category category_{"source path storage", Tracing::eventQueueWithStringArguments(), Tracing::eventQueueWithoutArguments(), category}; return category_; } + +# endif + } // namespace SourcePathStorageTracing + +#endif + } // namespace QmlDesigner diff --git a/src/plugins/qmldesigner/libs/designercore/tracing/qmldesignertracing.h b/src/plugins/qmldesigner/libs/designercore/tracing/qmldesignertracing.h index 6ea691563f8..a01883b988b 100644 --- a/src/plugins/qmldesigner/libs/designercore/tracing/qmldesignertracing.h +++ b/src/plugins/qmldesigner/libs/designercore/tracing/qmldesignertracing.h @@ -10,70 +10,87 @@ namespace QmlDesigner { namespace Tracing { -constexpr NanotraceHR::Tracing tracingStatus() -{ #ifdef ENABLE_QMLDESIGNER_TRACING - return NanotraceHR::Tracing::IsEnabled; -#else - return NanotraceHR::Tracing::IsDisabled; -#endif -} -using EventQueueWithStringArguments = NanotraceHR::StringViewWithStringArgumentsEventQueue; -using EventQueueWithoutArguments = NanotraceHR::EventQueueWithoutArguments; +using EventQueueWithStringArguments = NanotraceHR::EnabledEventQueueWithArguments; +using EventQueueWithoutArguments = NanotraceHR::EnabledEventQueueWithoutArguments; [[gnu::pure]] QMLDESIGNERCORE_EXPORT EventQueueWithStringArguments &eventQueueWithStringArguments(); [[gnu::pure]] QMLDESIGNERCORE_EXPORT EventQueueWithoutArguments &eventQueueWithoutArguments(); +#endif + } // namespace Tracing namespace ModelTracing { -constexpr NanotraceHR::Tracing tracingStatus() -{ -#ifdef ENABLE_MODEL_TRACING - return NanotraceHR::Tracing::IsEnabled; -#else - return NanotraceHR::Tracing::IsDisabled; -#endif -} -using Category = NanotraceHR::StringViewWithStringArgumentsCategory; +#ifdef ENABLE_MODEL_TRACING + +using Category = NanotraceHR::EnabledCategory; using SourceLocation = Category::SourceLocation; using AsynchronousToken = Category::AsynchronousTokenType; [[gnu::pure]] QMLDESIGNERCORE_EXPORT Category &category(); + +#else + +using Category = NanotraceHR::DisabledCategory; +using SourceLocation = Category::SourceLocation; +using AsynchronousToken = Category::AsynchronousTokenType; + +inline Category category() +{ + return {}; +}; + +#endif + } // namespace ModelTracing namespace ProjectStorageTracing { -constexpr NanotraceHR::Tracing projectStorageTracingStatus() -{ -#ifdef ENABLE_PROJECT_STORAGE_TRACING - return NanotraceHR::Tracing::IsEnabled; -#else - return NanotraceHR::Tracing::IsDisabled; -#endif -} -using Category = NanotraceHR::StringViewWithStringArgumentsCategory; +#ifdef ENABLE_PROJECT_STORAGE_TRACING + +using Category = NanotraceHR::EnabledCategory; [[gnu::pure]] Category &projectStorageCategory(); [[gnu::pure]] Category &projectStorageUpdaterCategory(); +#else + +using Category = NanotraceHR::DisabledCategory; + +inline Category projectStorageCategory() +{ + return {}; +} + +inline Category projectStorageUpdaterCategory() +{ + return {}; +} + +#endif + } // namespace ProjectStorageTracing namespace SourcePathStorageTracing { -constexpr NanotraceHR::Tracing tracingStatus() -{ -#ifdef ENABLE_SOURCE_PATH_STORAGE_TRACING - return NanotraceHR::Tracing::IsEnabled; -#else - return NanotraceHR::Tracing::IsDisabled; -#endif -} -using Category = NanotraceHR::StringViewWithStringArgumentsCategory; +#ifdef ENABLE_SOURCE_PATH_STORAGE_TRACING + +using Category = NanotraceHR::EnabledCategory; [[gnu::pure]] Category &category(); +#else + +using Category = NanotraceHR::DisabledCategory; + +inline Category category() +{ + return {}; +} + +#endif } // namespace SourcePathStorageTracing } // namespace QmlDesigner diff --git a/tests/unit/tests/unittests/imagecache/taskqueue-test.cpp b/tests/unit/tests/unittests/imagecache/taskqueue-test.cpp index 94f974dd752..0762b0d8921 100644 --- a/tests/unit/tests/unittests/imagecache/taskqueue-test.cpp +++ b/tests/unit/tests/unittests/imagecache/taskqueue-test.cpp @@ -26,7 +26,7 @@ auto IsTask(Matcher matcher) class TaskQueue : public testing::Test { - using Category = NanotraceHR::StringViewWithStringArgumentsCategory; + using Category = NanotraceHR::DisabledCategory; protected: Notification notification;