From ecba81097cc39b386ec53348659f5dba4c3fbd18 Mon Sep 17 00:00:00 2001 From: Marco Bubke Date: Tue, 17 Oct 2023 19:10:32 +0200 Subject: [PATCH] Nanotrace: Add flows Change-Id: If9c6642449a495f2fcc94f843b7fcd7bf2ab4548 Reviewed-by: Reviewed-by: Qt CI Patch Build Bot Reviewed-by: Thomas Hartmann --- src/libs/nanotrace/nanotracehr.cpp | 33 +- src/libs/nanotrace/nanotracehr.h | 653 ++++++++++++++++-- src/libs/sqlite/sqlitebasestatement.cpp | 57 +- .../imagecache/asynchronousimagecache.cpp | 8 +- .../imagecache/asynchronousimagefactory.cpp | 3 +- .../imagecache/imagecachecollectorinterface.h | 2 +- .../imagecache/imagecachegenerator.cpp | 64 +- .../imagecache/imagecachegenerator.h | 1 + .../imagecache/imagecachegeneratorinterface.h | 2 +- .../imagecache/meshimagecachecollector.h | 2 +- .../designercore/imagecache/taskqueue.h | 11 +- .../projectstorage/projectstorage.cpp | 12 +- .../projectstorage/projectstorage.h | 155 +++-- .../tracing/qmldesignertracing.cpp | 2 +- 14 files changed, 806 insertions(+), 199 deletions(-) diff --git a/src/libs/nanotrace/nanotracehr.cpp b/src/libs/nanotrace/nanotracehr.cpp index 5e04295920c..9e679e350c0 100644 --- a/src/libs/nanotrace/nanotracehr.cpp +++ b/src/libs/nanotrace/nanotracehr.cpp @@ -31,19 +31,38 @@ bool hasId(char phase) return false; } +template +unsigned int getUnsignedIntegerHash(Id id) +{ + return static_cast(id & 0xFFFFFFFF); +} + +unsigned int getUnsignedIntegerHash(std::thread::id id) +{ + return static_cast(std::hash{}(id) & 0xFFFFFFFF); +} + template void printEvent(std::ostream &out, const TraceEvent &event, qint64 processId, std::thread::id threadId) { out << R"({"ph":")" << event.type << R"(","name":")" << event.name << R"(","cat":")" << event.category << R"(","ts":)" << static_cast(event.time.time_since_epoch().count()) / 1000 << R"(,"pid":)" - << processId << R"(,"tid":)" << threadId; + << getUnsignedIntegerHash(processId) << R"(,"tid":)" << getUnsignedIntegerHash(threadId); if (event.type == 'X') out << R"(,"dur":)" << static_cast(event.duration.count()) / 1000; if (hasId(event.type)) - out << R"(,"id":")" << event.id << R"(")"; + out << R"(,"id":)" << event.id; + + if (event.bindId) { + out << R"(,"bind_id":)" << event.bindId; + if (event.flow & IsFlow::Out) + out << R"(,"flow_out":true)"; + if (event.flow & IsFlow::In) + out << R"(,"flow_in":true)"; + } if (event.arguments.size()) out << R"(,"args":)" << event.arguments; @@ -58,8 +77,9 @@ void writeMetaEvent(TraceFile *file, std::string_view key, s if (out.is_open()) { file->out << R"({"name":")" << key << R"(","ph":"M", "pid":)" - << QCoreApplication::applicationPid() << R"(,"tid":)" - << std::this_thread::get_id() << R"(,"args":{"name":")" << value << R"("}})" + << getUnsignedIntegerHash(QCoreApplication::applicationPid()) << R"(,"tid":)" + << getUnsignedIntegerHash(std::this_thread::get_id()) << R"(,"args":{"name":")" + << value << R"("}})" << ",\n"; } } @@ -150,7 +170,7 @@ void flushInThread(EnabledEventQueue &eventQueue) eventQueue.file->processing = std::async(std::launch::async, flush, eventQueue.currentEvents.subspan(0, eventQueue.eventsIndex), - std::this_thread::get_id()); + eventQueue.threadId); eventQueue.currentEvents = eventQueue.currentEvents.data() == eventQueue.eventsOne.data() ? eventQueue.eventsTwo : eventQueue.eventsOne; @@ -182,6 +202,7 @@ EventQueue::EventQueue(EnabledTraceFile *file, , eventsOne{eventsOne} , eventsTwo{eventsTwo} , currentEvents{eventsOne} + , threadId{std::this_thread::get_id()} { if (auto thread = QThread::currentThread()) { connection = QObject::connect(QCoreApplication::instance(), @@ -208,7 +229,7 @@ void EventQueue::flush() { std::lock_guard lock{mutex}; if (isEnabled == IsEnabled::Yes && eventsIndex > 0) { - flushEvents(currentEvents.subspan(0, eventsIndex), std::this_thread::get_id(), *this); + flushEvents(currentEvents.subspan(0, eventsIndex), threadId, *this); eventsIndex = 0; } } diff --git a/src/libs/nanotrace/nanotracehr.h b/src/libs/nanotrace/nanotracehr.h index 2f3552148c4..48aa61d37a1 100644 --- a/src/libs/nanotrace/nanotracehr.h +++ b/src/libs/nanotrace/nanotracehr.h @@ -259,6 +259,14 @@ template } // namespace Internal +enum class IsFlow : std::size_t { No = 0, Out = 1 << 0, In = 1 << 1, InOut = In | Out }; + +inline bool operator&(IsFlow first, IsFlow second) +{ + return static_cast>(first) + & static_cast>(second); +} + template struct TraceEvent { @@ -279,6 +287,8 @@ struct TraceEvent TimePoint time; Duration duration; std::size_t id = 0; + std::size_t bindId : 62; + IsFlow flow : 2; char type = ' '; }; @@ -391,6 +401,7 @@ public: IsEnabled isEnabled = IsEnabled::Yes; QMetaObject::Connection connection; std::mutex mutex; + std::thread::id threadId; }; extern template class NANOTRACE_EXPORT EventQueue; @@ -478,6 +489,151 @@ public: static constexpr bool isActive() { return false; } }; +template +class Tracer; + +template +class Token : public BasicDisabledToken +{ +public: + using ArgumentType = typename Category::ArgumentType; + using FlowTokenType = typename Category::FlowTokenType; + using AsynchronousTokenType = typename Category::AsynchronousTokenType; + using TracerType = typename Category::TracerType; + + Token() {} + + ~Token() {} + + template + [[nodiscard]] AsynchronousTokenType beginAsynchronous(ArgumentType, Arguments &&...) + { + return {}; + } + + template + [[nodiscard]] std::pair beginAsynchronousWithFlow( + ArgumentType, Arguments &&...) + { + return {}; + } + + template + [[nodiscard]] TracerType beginDuration(ArgumentType, Arguments &&...) + { + return {}; + } + + template + [[nodiscard]] std::pair beginDurationWithFlow(ArgumentType, + Arguments &&...) + { + return {}; + } + + template + void tick(ArgumentType, Arguments &&...) + {} +}; + +template +class Token : public BasicEnabledToken + +{ + using CategoryFunctionPointer = typename Category::CategoryFunctionPointer; + + Token(std::size_t id, CategoryFunctionPointer category) + : m_id{id} + , m_category{category} + {} + + using PrivateTag = typename Category::PrivateTag; + +public: + using ArgumentType = typename Category::ArgumentType; + using FlowTokenType = typename Category::FlowTokenType; + using AsynchronousTokenType = typename Category::AsynchronousTokenType; + using TracerType = typename Category::TracerType; + + Token(PrivateTag, std::size_t id, CategoryFunctionPointer category) + : Token{id, category} + {} + + friend TracerType; + friend AsynchronousTokenType; + + ~Token() {} + + template + [[nodiscard]] AsynchronousTokenType beginAsynchronous(ArgumentType name, Arguments &&...arguments) + { + if (m_id) + m_category().begin('b', m_id, name, 0, IsFlow::No, std::forward(arguments)...); + + return {std::move(name), m_id, m_category}; + } + + template + [[nodiscard]] std::pair beginAsynchronousWithFlow( + ArgumentType name, Arguments &&...arguments) + { + std::size_t bindId = 0; + + if (m_id) { + auto category = m_category(); + bindId = category.createBindId(); + category.begin('b', m_id, name, bindId, IsFlow::Out, std::forward(arguments)...); + } + + return {std::piecewise_construct, + std::forward_as_tuple(std::move(name), m_id, m_category), + std::forward_as_tuple(std::move(name), bindId, m_category)}; + } + + template + [[nodiscard]] TracerType beginDuration(ArgumentType traceName, Arguments &&...arguments) + { + return {traceName, m_category, std::forward(arguments)...}; + } + + template + [[nodiscard]] std::pair beginDurationWithFlow(ArgumentType traceName, + Arguments &&...arguments) + { + std::size_t bindId = m_category().createBindId(); + + return {std::piecewise_construct, + std::forward_as_tuple(PrivateTag{}, + bindId, + IsFlow::Out, + traceName, + m_category, + std::forward(arguments)...), + std::forward_as_tuple(PrivateTag{}, traceName, bindId, m_category)}; + } + + template + void tick(ArgumentType name, Arguments &&...arguments) + { + m_category().begin('i', 0, name, 0, IsFlow::No, std::forward(arguments)...); + } + +private: + std::size_t m_id = 0; + CategoryFunctionPointer m_category = nullptr; +}; +template +class Category; + +template +using StringViewCategory = Category; +template +using StringCategory = Category; +template +using StringViewWithStringArgumentsCategory = Category; + +using DisabledToken = Token, Tracing::IsDisabled>; + template class ObjectToken : public BasicDisabledToken { @@ -499,10 +655,12 @@ public: template class ObjectToken : public BasicEnabledToken { - ObjectToken(std::string_view name, std::size_t id, Category &category) + using CategoryFunctionPointer = typename Category::CategoryFunctionPointer; + + ObjectToken(std::string_view name, std::size_t id, CategoryFunctionPointer category) : m_name{name} , m_id{id} - , m_category{&category} + , m_category{category} {} public: @@ -511,14 +669,12 @@ public: friend Category; - ObjectToken() = default; - ObjectToken(const ObjectToken &other) : m_name{other.m_name} , m_category{other.m_category} { if (other.m_id) - m_id = m_category->beginObject(m_name).m_id; + m_id = m_category().beginObject(m_name).m_id; } ObjectToken &operator=(const ObjectToken &other) @@ -553,7 +709,7 @@ public: ~ObjectToken() { if (m_id) - m_category->end('e', m_id, std::move(m_name)); + m_category().end('e', m_id, std::move(m_name)); m_id = 0; } @@ -561,14 +717,16 @@ public: template void change(ArgumentType name, Arguments &&...arguments) { - if (m_id) - m_category->tick('n', m_id, std::move(name), std::forward(arguments)...); + if (m_id) { + m_category().tick( + 'n', m_id, std::move(name), 0, IsFlow::No, std::forward(arguments)...); + } } private: StringType m_name; std::size_t m_id = 0; - Category *m_category = nullptr; + CategoryFunctionPointer m_category = nullptr; }; template @@ -576,6 +734,8 @@ class AsynchronousToken : public BasicDisabledToken { public: using ArgumentType = typename Category::ArgumentType; + using FlowTokenType = typename Category::FlowTokenType; + using TokenType = typename Category::TokenType; AsynchronousToken() {} @@ -586,44 +746,71 @@ public: ~AsynchronousToken() {} - [[nodiscard]] AsynchronousToken create() { return {}; } + [[nodiscard]] TokenType createToken() { return {}; } template [[nodiscard]] AsynchronousToken begin(ArgumentType, Arguments &&...) { - return AsynchronousToken{}; + return {}; } template - void tick(Arguments &&...) + [[nodiscard]] std::pair beginWithFlow(ArgumentType, + Arguments &&...) + { + return {}; + } + + template + void tick(ArgumentType, Arguments &&...) {} + template + FlowTokenType tickWithFlow(ArgumentType, Arguments &&...) + { + return {}; + } + template void end(Arguments &&...) {} }; -using DisabledAsynchronousToken = AsynchronousToken; -template -class Category; +using DisabledAsynchronousToken = AsynchronousToken, + Tracing::IsDisabled>; + +template +class FlowToken; template class AsynchronousToken : public BasicEnabledToken { - AsynchronousToken(std::string_view name, std::size_t id, Category &category) + using CategoryFunctionPointer = typename Category::CategoryFunctionPointer; + + AsynchronousToken(std::string_view name, std::size_t id, CategoryFunctionPointer category) : m_name{name} , m_id{id} - , m_category{&category} + , m_category{category} {} + using PrivateTag = typename Category::PrivateTag; + public: using StringType = typename Category::StringType; using ArgumentType = typename Category::ArgumentType; + using FlowTokenType = typename Category::FlowTokenType; + using TokenType = typename Category::TokenType; friend Category; + friend FlowTokenType; + friend TokenType; - AsynchronousToken() = default; + AsynchronousToken(PrivateTag, std::string_view name, std::size_t id, CategoryFunctionPointer category) + : AsynchronousToken{name, id, category} + {} + + AsynchronousToken() {} AsynchronousToken(const AsynchronousToken &) = delete; AsynchronousToken &operator=(const AsynchronousToken &) = delete; @@ -647,29 +834,62 @@ public: ~AsynchronousToken() { end(); } - [[nodiscard]] AsynchronousToken create() { return {{}, m_id, *m_category}; } + [[nodiscard]] TokenType createToken() { return {m_id, m_category}; } template [[nodiscard]] AsynchronousToken begin(ArgumentType name, Arguments &&...arguments) { if (m_id) - m_category->begin('b', m_id, name, std::forward(arguments)...); + m_category().begin('b', m_id, name, 0, IsFlow::No, std::forward(arguments)...); - return AsynchronousToken{std::move(name), m_id, *m_category}; + return AsynchronousToken{std::move(name), m_id, m_category}; + } + + template + [[nodiscard]] std::pair beginWithFlow(ArgumentType name, + Arguments &&...arguments) + { + std::size_t bindId = 0; + + if (m_id) { + auto category = m_category(); + bindId = category.createBindId(); + category.begin('b', m_id, name, bindId, IsFlow::Out, std::forward(arguments)...); + } + + return {std::piecewise_construct, + std::forward_as_tuple(std::move(name), m_id, m_category), + std::forward_as_tuple(PrivateTag{}, std::move(name), bindId, m_category)}; } template void tick(ArgumentType name, Arguments &&...arguments) { - if (m_id) - m_category->tick('n', m_id, std::move(name), std::forward(arguments)...); + if (m_id) { + m_category().tick( + 'n', m_id, std::move(name), 0, IsFlow::No, std::forward(arguments)...); + } + } + + template + FlowTokenType tickWithFlow(ArgumentType name, Arguments &&...arguments) + { + std::size_t bindId = 0; + + if (m_id) { + auto category = m_category(); + bindId = category.createBindId(); + category.tick('n', m_id, name, bindId, IsFlow::Out, std::forward(arguments)...); + } + + return {std::move(name), bindId, m_category}; } template void end(Arguments &&...arguments) { if (m_id && m_name.size()) - m_category->end('e', m_id, std::move(m_name), std::forward(arguments)...); + m_category().end('e', m_id, std::move(m_name), std::forward(arguments)...); m_id = 0; } @@ -677,7 +897,174 @@ public: private: StringType m_name; std::size_t m_id = 0; - Category *m_category = nullptr; + CategoryFunctionPointer m_category = nullptr; +}; + +template +class FlowToken : public BasicDisabledToken +{ +public: + FlowToken() = default; + using AsynchronousTokenType = typename Category::AsynchronousTokenType; + using ArgumentType = typename Category::ArgumentType; + using TracerType = typename Category::TracerType; + using TokenType = typename Category::TokenType; + + friend TracerType; + friend AsynchronousTokenType; + friend TokenType; + friend Category; + + FlowToken(const FlowToken &) = delete; + FlowToken &operator=(const FlowToken &) = delete; + FlowToken(FlowToken &&other) noexcept = default; + FlowToken &operator=(FlowToken &&other) noexcept = default; + + ~FlowToken() {} + + template + [[nodiscard]] AsynchronousTokenType beginAsynchronous(ArgumentType, Arguments &&...) + { + return {}; + } + + template + [[nodiscard]] std::pair beginAsynchronousWithFlow(ArgumentType, + Arguments &&...) + { + return {}; + } + + template + void connectTo(const AsynchronousTokenType &, Arguments &&...) + {} + + template + [[nodiscard]] TracerType beginDuration(ArgumentType, Arguments &&...) + { + return {}; + } + + template + [[nodiscard]] std::pair beginDurationWithFlow(ArgumentType, Arguments &&...) + { + return std::pair(); + } + + template + void tick(ArgumentType, Arguments &&...) + {} +}; + +template +class FlowToken : public BasicDisabledToken +{ + using PrivateTag = typename Category::PrivateTag; + using CategoryFunctionPointer = typename Category::CategoryFunctionPointer; + +public: + FlowToken() = default; + + FlowToken(PrivateTag, std::string_view name, std::size_t bindId, CategoryFunctionPointer category) + : m_name{name} + , m_bindId{bindId} + , m_category{category} + {} + + using StringType = typename Category::StringType; + using AsynchronousTokenType = typename Category::AsynchronousTokenType; + using ArgumentType = typename Category::ArgumentType; + using TracerType = typename Category::TracerType; + using TokenType = typename Category::TokenType; + + friend AsynchronousTokenType; + friend TokenType; + friend TracerType; + friend Category; + + FlowToken(const FlowToken &) = delete; + FlowToken &operator=(const FlowToken &) = delete; + FlowToken(FlowToken &&other) noexcept = default; + FlowToken &operator=(FlowToken &&other) noexcept = default; + + ~FlowToken() {} + + template + [[nodiscard]] AsynchronousTokenType beginAsynchronous(ArgumentType name, Arguments &&...arguments) + { + std::size_t id = 0; + + if (m_bindId) { + auto category = m_category(); + id = category.createId(); + category->begin('b', id, name, m_bindId, IsFlow::In, std::forward(arguments)...); + } + + return {std::move(name), id, m_category}; + } + + template + [[nodiscard]] std::pair beginAsynchronousWithFlow( + ArgumentType name, Arguments &&...arguments) + { + std::size_t id = 0; + std::size_t bindId = 0; + + if (m_bindId) { + auto category = m_category(); + id = category.createId(); + bindId = category.createBindId(); + category->begin('b', id, name, bindId, IsFlow::InOut, std::forward(arguments)...); + } + + return {std::piecewise_construct, + std::forward_as_tuple(PrivateTag{}, std::move(name), id, m_category), + std::forward_as_tuple(PrivateTag{}, std::move(name), bindId, m_category)}; + } + + template + void connectTo(const AsynchronousTokenType &token, Arguments &&...arguments) + { + if (m_bindId && token.m_id) { + m_category().begin('b', + token.m_id, + token.m_name, + m_bindId, + IsFlow::In, + std::forward(arguments)...); + } + } + + template + [[nodiscard]] TracerType beginDuration(ArgumentType traceName, Arguments &&...arguments) + { + return {m_bindId, IsFlow::In, traceName, m_category, std::forward(arguments)...}; + } + + template + [[nodiscard]] std::pair beginDurationWithFlow(ArgumentType traceName, + Arguments &&...arguments) + { + return {std::piecewise_construct, + std::forward_as_tuple(PrivateTag{}, + m_bindId, + IsFlow::InOut, + traceName, + m_category, + std::forward(arguments)...), + std::forward_as_tuple(PrivateTag{}, traceName, m_bindId, m_category)}; + } + + template + void tick(ArgumentType name, Arguments &&...arguments) + { + m_category().tick('i', 0, name, m_bindId, IsFlow::In, std::forward(arguments)...); + } + +private: + StringType m_name; + std::size_t m_bindId = 0; + CategoryFunctionPointer m_category = nullptr; }; template @@ -689,10 +1076,15 @@ public: using ArgumentsStringType = typename TraceEvent::ArgumentsStringType; using AsynchronousTokenType = AsynchronousToken; using ObjectTokenType = ObjectToken; + using FlowTokenType = FlowToken; + using TracerType = Tracer; + using TokenType = Token; + using CategoryFunctionPointer = Category &(*) (); - Category(ArgumentType, EventQueue &) {} + Category(ArgumentType, EventQueue &, CategoryFunctionPointer) + {} - Category(ArgumentType, EventQueue &) {} + Category(ArgumentType, EventQueue &, CategoryFunctionPointer) {} template [[nodiscard]] AsynchronousTokenType beginAsynchronous(ArgumentType, Arguments &&...) @@ -700,18 +1092,39 @@ public: return {}; } + template + [[nodiscard]] std::pair beginAsynchronousWithFlow( + ArgumentType, Arguments &&...) + {} + template [[nodiscard]] ObjectTokenType beginObject(ArgumentType, Arguments &&...) { return {}; } + template + [[nodiscard]] TracerType beginDuration(ArgumentType, Arguments &&...) + { + return {}; + } + + template + [[nodiscard]] std::pair beginDurationWithFlow(ArgumentType, + Arguments &&...) + { + return std::pair(); + } + static constexpr bool isActive() { return false; } }; template class Category { + class PrivateTag + {}; + public: using IsActive = std::true_type; using ArgumentType = typename TraceEvent::ArgumentType; @@ -719,40 +1132,84 @@ public: using StringType = typename TraceEvent::StringType; using AsynchronousTokenType = AsynchronousToken; using ObjectTokenType = ObjectToken; + using FlowTokenType = FlowToken; + using TracerType = Tracer; + using TokenType = Token; + using CategoryFunctionPointer = Category &(*) (); friend AsynchronousTokenType; friend ObjectTokenType; + friend TokenType; + friend FlowTokenType; + friend TracerType; template - Category(ArgumentType name, EventQueue &queue) + Category(ArgumentType name, EventQueue &queue, CategoryFunctionPointer self) : m_name{std::move(name)} , m_eventQueue{queue} + , m_self{self} { static_assert(std::is_same_v, "A active category is not possible with an inactive event queue!"); - idCounter = globalIdCounter += 1ULL << 32; + m_idCounter = m_globalIdCounter += 1ULL << 32; + m_bindIdCounter = m_globalBindIdCounter += 1ULL << 32; } template [[nodiscard]] AsynchronousTokenType beginAsynchronous(ArgumentType traceName, Arguments &&...arguments) { - std::size_t id = ++idCounter; + std::size_t id = createId(); - begin('b', id, std::move(traceName), std::forward(arguments)...); + begin('b', id, std::move(traceName), 0, IsFlow::No, std::forward(arguments)...); - return {traceName, id, *this}; + return {traceName, id, m_self}; + } + + template + [[nodiscard]] std::pair beginAsynchronousWithFlow( + ArgumentType traceName, Arguments &&...arguments) + { + std::size_t id = createId(); + std::size_t bindId = createBindId(); + + begin('b', id, std::move(traceName), bindId, IsFlow::Out, std::forward(arguments)...); + + return {std::piecewise_construct, + std::forward_as_tuple(PrivateTag{}, traceName, id, m_self), + std::forward_as_tuple(PrivateTag{}, traceName, bindId, m_self)}; } template [[nodiscard]] ObjectTokenType beginObject(ArgumentType traceName, Arguments &&...arguments) { - std::size_t id = ++idCounter; + std::size_t id = createId(); - if (id) - begin('b', id, std::move(traceName), std::forward(arguments)...); + begin('b', id, std::move(traceName), 0, IsFlow::No, std::forward(arguments)...); - return {traceName, id, *this}; + return {traceName, id, m_self}; + } + + template + [[nodiscard]] TracerType beginDuration(ArgumentType traceName, Arguments &&...arguments) + { + return {traceName, m_self, std::forward(arguments)...}; + } + + template + [[nodiscard]] std::pair beginDurationWithFlow(ArgumentType traceName, + Arguments &&...arguments) + { + std::size_t bindId = createBindId(); + + return {std::piecewise_construct, + std::forward_as_tuple(PrivateTag{}, + bindId, + IsFlow::Out, + traceName, + m_self, + std::forward(arguments)...), + std::forward_as_tuple(PrivateTag{}, traceName, bindId, m_self)}; } EnabledEventQueue &eventQueue() const { return m_eventQueue; } @@ -761,12 +1218,21 @@ public: static constexpr bool isActive() { return true; } + std::size_t createBindId() { return ++m_bindIdCounter; } + + std::size_t createId() { return ++m_idCounter; } + public: IsEnabled isEnabled = IsEnabled::Yes; private: template - void begin(char type, std::size_t id, StringType traceName, Arguments &&...arguments) + void begin(char type, + std::size_t id, + StringType traceName, + std::size_t bindId, + IsFlow flow, + Arguments &&...arguments) { if (isEnabled == IsEnabled::No) return; @@ -777,12 +1243,19 @@ private: traceEvent.category = m_name; traceEvent.type = type; traceEvent.id = id; + traceEvent.bindId = bindId; + traceEvent.flow = flow; Internal::appendArguments(traceEvent.arguments, std::forward(arguments)...); traceEvent.time = Clock::now(); } template - void tick(char type, std::size_t id, StringType traceName, Arguments &&...arguments) + void tick(char type, + std::size_t id, + StringType traceName, + std::size_t bindId, + IsFlow flow, + Arguments &&...arguments) { if (isEnabled == IsEnabled::No) return; @@ -796,6 +1269,8 @@ private: traceEvent.time = time; traceEvent.type = type; traceEvent.id = id; + traceEvent.bindId = bindId; + traceEvent.flow = flow; Internal::appendArguments(traceEvent.arguments, std::forward(arguments)...); } @@ -814,14 +1289,19 @@ private: traceEvent.time = time; traceEvent.type = type; traceEvent.id = id; + traceEvent.bindId = 0; + traceEvent.flow = IsFlow::No; Internal::appendArguments(traceEvent.arguments, std::forward(arguments)...); } private: StringType m_name; EnabledEventQueue &m_eventQueue; - inline static std::atomic globalIdCounter; - std::size_t idCounter; + inline static std::atomic m_globalIdCounter; + std::size_t m_idCounter; + inline static std::atomic m_globalBindIdCounter; + std::size_t m_bindIdCounter; + CategoryFunctionPointer m_self; }; template @@ -835,7 +1315,14 @@ template class Tracer { public: + Tracer() = default; using ArgumentType = typename Category::ArgumentType; + using TokenType = typename Category::TokenType; + using FlowTokenType = typename Category::FlowTokenType; + + friend TokenType; + friend FlowTokenType; + friend Category; template [[nodiscard]] Tracer(ArgumentType, Category &, Arguments &&...) @@ -845,6 +1332,17 @@ public: Tracer &operator=(const Tracer &) = delete; Tracer(Tracer &&other) noexcept = default; Tracer &operator=(Tracer &&other) noexcept = delete; + + TokenType createToken() { return {}; } + + template + Tracer beginDuration(ArgumentType, Arguments &&...) + { + return {}; + } + + void end() {} + ~Tracer() {} }; @@ -854,14 +1352,50 @@ class Tracer using ArgumentType = typename Category::ArgumentType; using StringType = typename Category::StringType; 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, + ArgumentType name, + CategoryFunctionPointer category, + Arguments &&...arguments) + : m_name{name} + , m_bindId{bindId} + , flow{flow} + , m_category{category} + { + if (category().isEnabled == IsEnabled::Yes) { + Internal::appendArguments(m_arguments, + std::forward(arguments)...); + m_start = Clock::now(); + } + } public: template - [[nodiscard]] Tracer(ArgumentType name, Category &category, Arguments &&...arguments) + [[nodiscard]] Tracer(PrivateTag, + std::size_t bindId, + IsFlow flow, + ArgumentType name, + CategoryFunctionPointer category, + Arguments &&...arguments) + : Tracer{bindId, flow, std::move(name), category, std::forward(arguments)...} + {} + + template + [[nodiscard]] Tracer(ArgumentType name, CategoryFunctionPointer category, Arguments &&...arguments) : m_name{name} , m_category{category} { - if (category.isEnabled == IsEnabled::Yes) { + if (category().isEnabled == IsEnabled::Yes) { Internal::appendArguments(m_arguments, std::forward(arguments)...); m_start = Clock::now(); @@ -872,17 +1406,38 @@ public: Tracer &operator=(const Tracer &) = delete; Tracer(Tracer &&other) noexcept = delete; Tracer &operator=(Tracer &&other) noexcept = delete; - ~Tracer() + + TokenType createToken() { return {0, m_category}; } + + ~Tracer() { sendTrace(); } + + template + Tracer beginDuration(ArgumentType name, Arguments &&...arguments) { - if constexpr (tracingStatus() == Tracing::IsEnabled) { - if (m_category.isEnabled == IsEnabled::Yes) { + return {std::move(name), m_category, std::forward(arguments)...}; + } + + void end() + { + sendTrace(); + m_name = {}; + } + +private: + void sendTrace() + { + if (m_name.size()) { + auto category = m_category(); + if (category.isEnabled == IsEnabled::Yes) { auto duration = Clock::now() - m_start; - auto &traceEvent = getTraceEvent(m_category.eventQueue()); + auto &traceEvent = getTraceEvent(category.eventQueue()); traceEvent.name = m_name; - traceEvent.category = m_category.name(); + traceEvent.category = category.name(); traceEvent.arguments = m_arguments; traceEvent.time = m_start; traceEvent.duration = duration; + traceEvent.bindId = m_bindId; + traceEvent.flow = flow; traceEvent.type = 'X'; } } @@ -892,7 +1447,9 @@ private: TimePoint m_start; StringType m_name; StringType m_arguments; - Category &m_category; + std::size_t m_bindId; + IsFlow flow; + CategoryFunctionPointer m_category; }; template diff --git a/src/libs/sqlite/sqlitebasestatement.cpp b/src/libs/sqlite/sqlitebasestatement.cpp index efddc08e38c..406d49d2489 100644 --- a/src/libs/sqlite/sqlitebasestatement.cpp +++ b/src/libs/sqlite/sqlitebasestatement.cpp @@ -35,11 +35,18 @@ thread_local NanotraceHR::EventQueueData sqliteLowLevelCategory{ - "sqlite low level"_t, eventQueue}; +NanotraceHR::StringViewCategory &sqliteLowLevelCategory(); + +thread_local NanotraceHR::StringViewCategory sqliteLowLevelCategory_{ + "sqlite low level"_t, eventQueue, sqliteLowLevelCategory}; + +NanotraceHR::StringViewCategory &sqliteLowLevelCategory() +{ + return sqliteLowLevelCategory_; +} thread_local NanotraceHR::StringViewCategory sqliteHighLevelCategory_{ - "sqlite high level"_t, eventQueue}; + "sqlite high level"_t, eventQueue, sqliteHighLevelCategory}; } // namespace NanotraceHR::StringViewCategory &sqliteHighLevelCategory() @@ -101,14 +108,14 @@ void BaseStatement::waitForUnlockNotify() const void BaseStatement::reset() const noexcept { - NanotraceHR::Tracer tracer{"reset"_t, sqliteLowLevelCategory}; + NanotraceHR::Tracer tracer{"reset"_t, sqliteLowLevelCategory()}; sqlite3_reset(m_compiledStatement.get()); } bool BaseStatement::next() const { - NanotraceHR::Tracer tracer{"next"_t, sqliteLowLevelCategory}; + NanotraceHR::Tracer tracer{"next"_t, sqliteLowLevelCategory()}; int resultCode; do { @@ -135,7 +142,7 @@ void BaseStatement::step() const void BaseStatement::bindNull(int index) { - NanotraceHR::Tracer tracer{"bind null"_t, sqliteLowLevelCategory}; + NanotraceHR::Tracer tracer{"bind null"_t, sqliteLowLevelCategory()}; int resultCode = sqlite3_bind_null(m_compiledStatement.get(), index); if (resultCode != SQLITE_OK) @@ -149,7 +156,7 @@ void BaseStatement::bind(int index, NullValue) void BaseStatement::bind(int index, int value) { - NanotraceHR::Tracer tracer{"bind int"_t, sqliteLowLevelCategory}; + NanotraceHR::Tracer tracer{"bind int"_t, sqliteLowLevelCategory()}; int resultCode = sqlite3_bind_int(m_compiledStatement.get(), index, value); if (resultCode != SQLITE_OK) @@ -158,7 +165,7 @@ void BaseStatement::bind(int index, int value) void BaseStatement::bind(int index, long long value) { - NanotraceHR::Tracer tracer{"bind long long"_t, sqliteLowLevelCategory}; + NanotraceHR::Tracer tracer{"bind long long"_t, sqliteLowLevelCategory()}; int resultCode = sqlite3_bind_int64(m_compiledStatement.get(), index, value); if (resultCode != SQLITE_OK) @@ -167,7 +174,7 @@ void BaseStatement::bind(int index, long long value) void BaseStatement::bind(int index, double value) { - NanotraceHR::Tracer tracer{"bind double"_t, sqliteLowLevelCategory}; + NanotraceHR::Tracer tracer{"bind double"_t, sqliteLowLevelCategory()}; int resultCode = sqlite3_bind_double(m_compiledStatement.get(), index, value); if (resultCode != SQLITE_OK) @@ -176,7 +183,7 @@ void BaseStatement::bind(int index, double value) void BaseStatement::bind(int index, void *pointer) { - NanotraceHR::Tracer tracer{"bind pointer"_t, sqliteLowLevelCategory}; + NanotraceHR::Tracer tracer{"bind pointer"_t, sqliteLowLevelCategory()}; int resultCode = sqlite3_bind_pointer(m_compiledStatement.get(), index, pointer, "carray", nullptr); if (resultCode != SQLITE_OK) @@ -185,7 +192,7 @@ void BaseStatement::bind(int index, void *pointer) void BaseStatement::bind(int index, Utils::span values) { - NanotraceHR::Tracer tracer{"bind int span"_t, sqliteLowLevelCategory}; + NanotraceHR::Tracer tracer{"bind int span"_t, sqliteLowLevelCategory()}; int resultCode = sqlite3_carray_bind(m_compiledStatement.get(), index, @@ -199,7 +206,7 @@ void BaseStatement::bind(int index, Utils::span values) void BaseStatement::bind(int index, Utils::span values) { - NanotraceHR::Tracer tracer{"bind long long span"_t, sqliteLowLevelCategory}; + NanotraceHR::Tracer tracer{"bind long long span"_t, sqliteLowLevelCategory()}; int resultCode = sqlite3_carray_bind(m_compiledStatement.get(), index, @@ -213,7 +220,7 @@ void BaseStatement::bind(int index, Utils::span values) void BaseStatement::bind(int index, Utils::span values) { - NanotraceHR::Tracer tracer{"bind double span"_t, sqliteLowLevelCategory}; + NanotraceHR::Tracer tracer{"bind double span"_t, sqliteLowLevelCategory()}; int resultCode = sqlite3_carray_bind(m_compiledStatement.get(), index, @@ -227,7 +234,7 @@ void BaseStatement::bind(int index, Utils::span values) void BaseStatement::bind(int index, Utils::span values) { - NanotraceHR::Tracer tracer{"bind const char* span"_t, sqliteLowLevelCategory}; + NanotraceHR::Tracer tracer{"bind const char* span"_t, sqliteLowLevelCategory()}; int resultCode = sqlite3_carray_bind(m_compiledStatement.get(), index, @@ -241,7 +248,7 @@ void BaseStatement::bind(int index, Utils::span values) void BaseStatement::bind(int index, Utils::SmallStringView text) { - NanotraceHR::Tracer tracer{"bind string"_t, sqliteLowLevelCategory}; + NanotraceHR::Tracer tracer{"bind string"_t, sqliteLowLevelCategory()}; int resultCode = sqlite3_bind_text(m_compiledStatement.get(), index, @@ -254,7 +261,7 @@ void BaseStatement::bind(int index, Utils::SmallStringView text) void BaseStatement::bind(int index, BlobView blobView) { - NanotraceHR::Tracer tracer{"bind blob"_t, sqliteLowLevelCategory}; + NanotraceHR::Tracer tracer{"bind blob"_t, sqliteLowLevelCategory()}; int resultCode = SQLITE_OK; @@ -274,7 +281,7 @@ void BaseStatement::bind(int index, BlobView blobView) void BaseStatement::bind(int index, const Value &value) { - NanotraceHR::Tracer tracer{"bind value"_t, sqliteLowLevelCategory}; + NanotraceHR::Tracer tracer{"bind value"_t, sqliteLowLevelCategory()}; switch (value.type()) { case ValueType::Integer: @@ -297,7 +304,7 @@ void BaseStatement::bind(int index, const Value &value) void BaseStatement::bind(int index, ValueView value) { - NanotraceHR::Tracer tracer{"bind value"_t, sqliteLowLevelCategory}; + NanotraceHR::Tracer tracer{"bind value"_t, sqliteLowLevelCategory()}; switch (value.type()) { case ValueType::Integer: @@ -320,7 +327,7 @@ void BaseStatement::bind(int index, ValueView value) void BaseStatement::prepare(Utils::SmallStringView sqlStatement) { - NanotraceHR::Tracer tracer{"prepare"_t, sqliteLowLevelCategory}; + NanotraceHR::Tracer tracer{"prepare"_t, sqliteLowLevelCategory()}; if (!m_database.isLocked()) throw DatabaseIsNotLocked{}; @@ -421,7 +428,7 @@ StringType convertToTextForColumn(sqlite3_stmt *sqlStatment, int column) Type BaseStatement::fetchType(int column) const { - NanotraceHR::Tracer tracer{"fetch type"_t, sqliteLowLevelCategory}; + NanotraceHR::Tracer tracer{"fetch type"_t, sqliteLowLevelCategory()}; auto dataType = sqlite3_column_type(m_compiledStatement.get(), column); @@ -443,7 +450,7 @@ Type BaseStatement::fetchType(int column) const int BaseStatement::fetchIntValue(int column) const { - NanotraceHR::Tracer tracer{"fetch int"_t, sqliteLowLevelCategory}; + NanotraceHR::Tracer tracer{"fetch int"_t, sqliteLowLevelCategory()}; return sqlite3_column_int(m_compiledStatement.get(), column); } @@ -467,7 +474,7 @@ long BaseStatement::fetchValue(int column) const long long BaseStatement::fetchLongLongValue(int column) const { - NanotraceHR::Tracer tracer{"fetch long long"_t, sqliteLowLevelCategory}; + NanotraceHR::Tracer tracer{"fetch long long"_t, sqliteLowLevelCategory()}; return sqlite3_column_int64(m_compiledStatement.get(), column); } @@ -480,14 +487,14 @@ long long BaseStatement::fetchValue(int column) const double BaseStatement::fetchDoubleValue(int column) const { - NanotraceHR::Tracer tracer{"fetch double"_t, sqliteLowLevelCategory}; + NanotraceHR::Tracer tracer{"fetch double"_t, sqliteLowLevelCategory()}; return sqlite3_column_double(m_compiledStatement.get(), column); } BlobView BaseStatement::fetchBlobValue(int column) const { - NanotraceHR::Tracer tracer{"fetch blob"_t, sqliteLowLevelCategory}; + NanotraceHR::Tracer tracer{"fetch blob"_t, sqliteLowLevelCategory()}; return convertToBlobForColumn(m_compiledStatement.get(), column); } @@ -537,7 +544,7 @@ ValueView BaseStatement::fetchValueView(int column) const void BaseStatement::Deleter::operator()(sqlite3_stmt *statement) { - NanotraceHR::Tracer tracer{"finalize"_t, sqliteLowLevelCategory}; + NanotraceHR::Tracer tracer{"finalize"_t, sqliteLowLevelCategory()}; sqlite3_finalize(statement); } diff --git a/src/plugins/qmldesigner/designercore/imagecache/asynchronousimagecache.cpp b/src/plugins/qmldesigner/designercore/imagecache/asynchronousimagecache.cpp index 6c009ec3cad..ad4e4aa40fb 100644 --- a/src/plugins/qmldesigner/designercore/imagecache/asynchronousimagecache.cpp +++ b/src/plugins/qmldesigner/designercore/imagecache/asynchronousimagecache.cpp @@ -20,7 +20,7 @@ using namespace NanotraceHR::Literals; namespace ImageCache { namespace { -thread_local Category category_{"image cache"_t, QmlDesigner::Tracing::eventQueue()}; +thread_local Category category_{"image cache"_t, QmlDesigner::Tracing::eventQueue(), category}; } // namespace Category &category() @@ -139,7 +139,7 @@ void AsynchronousImageCache::requestImage(Utils::SmallStringView name, { auto traceToken = ImageCache::category().beginAsynchronous( "request image in asynchornous image cache"_t); - m_taskQueue.addTask(traceToken.create(), + m_taskQueue.addTask(traceToken.createToken(), std::move(name), std::move(extraId), std::move(captureCallback), @@ -157,7 +157,7 @@ void AsynchronousImageCache::requestMidSizeImage(Utils::SmallStringView name, { auto traceToken = ImageCache::category().beginAsynchronous( "request mid size image in asynchornous image cache"_t); - m_taskQueue.addTask(traceToken.create(), + m_taskQueue.addTask(traceToken.createToken(), std::move(name), std::move(extraId), std::move(captureCallback), @@ -175,7 +175,7 @@ void AsynchronousImageCache::requestSmallImage(Utils::SmallStringView name, { auto traceToken = ImageCache::category().beginAsynchronous( "request small size image in asynchornous image cache"_t); - m_taskQueue.addTask(traceToken.create(), + m_taskQueue.addTask(traceToken.createToken(), std::move(name), std::move(extraId), std::move(captureCallback), diff --git a/src/plugins/qmldesigner/designercore/imagecache/asynchronousimagefactory.cpp b/src/plugins/qmldesigner/designercore/imagecache/asynchronousimagefactory.cpp index 9ed3a34f7d6..f7c9d59e9cf 100644 --- a/src/plugins/qmldesigner/designercore/imagecache/asynchronousimagefactory.cpp +++ b/src/plugins/qmldesigner/designercore/imagecache/asynchronousimagefactory.cpp @@ -57,7 +57,8 @@ void AsynchronousImageFactory::request(Utils::SmallStringView name, extraId, std::move(auxiliaryData), std::move(capture), - ImageCache::InternalAbortCallback{}); + ImageCache::InternalAbortCallback{}, + {}); } void AsynchronousImageFactory::clean() diff --git a/src/plugins/qmldesigner/designercore/imagecache/imagecachecollectorinterface.h b/src/plugins/qmldesigner/designercore/imagecache/imagecachecollectorinterface.h index e6c70f31939..34083f7b293 100644 --- a/src/plugins/qmldesigner/designercore/imagecache/imagecachecollectorinterface.h +++ b/src/plugins/qmldesigner/designercore/imagecache/imagecachecollectorinterface.h @@ -23,7 +23,7 @@ public: const ImageCache::AuxiliaryData &auxiliaryData, CaptureCallback captureCallback, AbortCallback abortCallback, - ImageCache::TraceToken traceToken = {}) + ImageCache::TraceToken traceToken) = 0; virtual ImageTuple createImage(Utils::SmallStringView filePath, diff --git a/src/plugins/qmldesigner/designercore/imagecache/imagecachegenerator.cpp b/src/plugins/qmldesigner/designercore/imagecache/imagecachegenerator.cpp index 93ddbd38015..bf57766e5e6 100644 --- a/src/plugins/qmldesigner/designercore/imagecache/imagecachegenerator.cpp +++ b/src/plugins/qmldesigner/designercore/imagecache/imagecachegenerator.cpp @@ -111,35 +111,43 @@ void ImageCacheGenerator::waitForFinished() m_backgroundThread->wait(); } +std::optional ImageCacheGenerator::getTask() +{ + { + auto [lock, abort] = waitForEntries(); + + if (abort) + return {}; + + std::optional task = std::move(m_tasks.front()); + + m_tasks.pop_front(); + + return task; + } +} + void ImageCacheGenerator::startGeneration() { while (true) { - Task task; + auto task = getTask(); - { - auto [lock, abort] = waitForEntries(); - - if (abort) - return; - - task = std::move(m_tasks.front()); - - m_tasks.pop_front(); - } + if (!task) + return; m_collector.start( - task.filePath, - task.extraId, - std::move(task.auxiliaryData), + task->filePath, + task->extraId, + std::move(task->auxiliaryData), [this, - abortCallbacks = task.abortCallbacks, - captureCallbacks = std::move(task.captureCallbacks), - filePath = task.filePath, - extraId = task.extraId, - timeStamp = task.timeStamp](const QImage &image, - const QImage &midSizeImage, - const QImage &smallImage, - ImageCache::TraceToken traceToken) { + abortCallbacks = task->abortCallbacks, + captureCallbacks = std::move(task->captureCallbacks), + filePath = task->filePath, + extraId = task->extraId, + timeStamp = task->timeStamp](const QImage &image, + const QImage &midSizeImage, + const QImage &smallImage, + ImageCache::TraceToken traceToken) { if (image.isNull() && midSizeImage.isNull() && smallImage.isNull()) callCallbacks(abortCallbacks, ImageCache::AbortReason::Failed, @@ -158,16 +166,16 @@ void ImageCacheGenerator::startGeneration() smallImage); }, [this, - abortCallbacks = task.abortCallbacks, - filePath = task.filePath, - extraId = task.extraId, - timeStamp = task.timeStamp](ImageCache::AbortReason abortReason, - ImageCache::TraceToken traceToken) { + abortCallbacks = task->abortCallbacks, + filePath = task->filePath, + extraId = task->extraId, + timeStamp = task->timeStamp](ImageCache::AbortReason abortReason, + ImageCache::TraceToken traceToken) { callCallbacks(abortCallbacks, abortReason, std::move(traceToken)); if (abortReason != ImageCache::AbortReason::Abort) m_storage.storeImage(createId(filePath, extraId), timeStamp, {}, {}, {}); }, - std::move(task.traceToken)); + std::move(task->traceToken)); std::lock_guard lock{m_mutex}; if (m_tasks.empty()) diff --git a/src/plugins/qmldesigner/designercore/imagecache/imagecachegenerator.h b/src/plugins/qmldesigner/designercore/imagecache/imagecachegenerator.h index 3b28c117fdb..1846eff557c 100644 --- a/src/plugins/qmldesigner/designercore/imagecache/imagecachegenerator.h +++ b/src/plugins/qmldesigner/designercore/imagecache/imagecachegenerator.h @@ -72,6 +72,7 @@ private: }; void startGeneration(); + std::optional getTask(); void ensureThreadIsRunning(); [[nodiscard]] std::tuple, bool> waitForEntries(); void stopThread(); diff --git a/src/plugins/qmldesigner/designercore/imagecache/imagecachegeneratorinterface.h b/src/plugins/qmldesigner/designercore/imagecache/imagecachegeneratorinterface.h index 3708a204d63..62d1b374914 100644 --- a/src/plugins/qmldesigner/designercore/imagecache/imagecachegeneratorinterface.h +++ b/src/plugins/qmldesigner/designercore/imagecache/imagecachegeneratorinterface.h @@ -20,7 +20,7 @@ public: ImageCache::CaptureImageWithScaledImagesCallback &&captureCallback, ImageCache::InternalAbortCallback &&abortCallback, ImageCache::AuxiliaryData &&auxiliaryData, - ImageCache::TraceToken = {}) + ImageCache::TraceToken) = 0; virtual void clean() = 0; diff --git a/src/plugins/qmldesigner/designercore/imagecache/meshimagecachecollector.h b/src/plugins/qmldesigner/designercore/imagecache/meshimagecachecollector.h index 067c9033608..98c2e84605e 100644 --- a/src/plugins/qmldesigner/designercore/imagecache/meshimagecachecollector.h +++ b/src/plugins/qmldesigner/designercore/imagecache/meshimagecachecollector.h @@ -30,7 +30,7 @@ public: const ImageCache::AuxiliaryData &auxiliaryData, CaptureCallback captureCallback, AbortCallback abortCallback, - ImageCache::TraceToken traceToken = {}) override; + ImageCache::TraceToken traceToken) override; ImageTuple createImage(Utils::SmallStringView filePath, Utils::SmallStringView state, diff --git a/src/plugins/qmldesigner/designercore/imagecache/taskqueue.h b/src/plugins/qmldesigner/designercore/imagecache/taskqueue.h index 7ae32310188..ff17fef1cd8 100644 --- a/src/plugins/qmldesigner/designercore/imagecache/taskqueue.h +++ b/src/plugins/qmldesigner/designercore/imagecache/taskqueue.h @@ -26,8 +26,7 @@ public: ~TaskQueue() { destroy(); } template - void addTask(NanotraceHR::AsynchronousToken traceToken, - Arguments &&...arguments) + void addTask(NanotraceHR::Token traceToken, Arguments &&...arguments) { { std::unique_lock lock{m_mutex}; @@ -42,7 +41,7 @@ public: template void addTask(Arguments &&...arguments) { - addTask(NanotraceHR::DisabledAsynchronousToken{}, std::forward(arguments)...); + addTask(NanotraceHR::DisabledToken{}, std::forward(arguments)...); } void clean() @@ -95,8 +94,8 @@ private: return {std::move(task)}; } - template - void ensureThreadIsRunning(TraceTokend traceToken) + template + void ensureThreadIsRunning(TraceToken traceToken) { using namespace NanotraceHR::Literals; @@ -108,7 +107,7 @@ private: m_sleeping = false; - auto threadCreateToken = traceToken.begin("thread is created in the task queue"_t); + auto threadCreateToken = traceToken.beginDuration("thread is created in the task queue"_t); m_backgroundThread = std::thread{[this](auto traceToken) { traceToken.tick("thread is ready"_t); while (true) { diff --git a/src/plugins/qmldesigner/designercore/projectstorage/projectstorage.cpp b/src/plugins/qmldesigner/designercore/projectstorage/projectstorage.cpp index 2a6bdd01cbc..700a85bc112 100644 --- a/src/plugins/qmldesigner/designercore/projectstorage/projectstorage.cpp +++ b/src/plugins/qmldesigner/designercore/projectstorage/projectstorage.cpp @@ -9,8 +9,16 @@ namespace QmlDesigner { -thread_local NanotraceHR::StringViewCategory projectStorageCategory{ - "project storage"_t, Tracing::eventQueue()}; +namespace { + +thread_local NanotraceHR::StringViewCategory projectStorageCategory_{ + "project storage"_t, Tracing::eventQueue(), projectStorageCategory}; +} + +NanotraceHR::StringViewCategory &projectStorageCategory() +{ + return projectStorageCategory_; +} } // namespace QmlDesigner diff --git a/src/plugins/qmldesigner/designercore/projectstorage/projectstorage.h b/src/plugins/qmldesigner/designercore/projectstorage/projectstorage.h index 47ca8b7c9a0..6244977ec79 100644 --- a/src/plugins/qmldesigner/designercore/projectstorage/projectstorage.h +++ b/src/plugins/qmldesigner/designercore/projectstorage/projectstorage.h @@ -37,7 +37,7 @@ constexpr NanotraceHR::Tracing projectStorageTracingStatus() #endif } -extern thread_local NanotraceHR::StringViewCategory projectStorageCategory; +NanotraceHR::StringViewCategory &projectStorageCategory(); template class ProjectStorage final : public ProjectStorageInterface @@ -57,7 +57,7 @@ public: , exclusiveTransaction{database} , initializer{database, isInitialized} { - NanotraceHR::Tracer tracer{"initialize"_t, projectStorageCategory}; + NanotraceHR::Tracer tracer{"initialize"_t, projectStorageCategory()}; exclusiveTransaction.commit(); @@ -68,7 +68,7 @@ public: void synchronize(Storage::Synchronization::SynchronizationPackage package) override { - NanotraceHR::Tracer tracer{"synchronize"_t, projectStorageCategory}; + NanotraceHR::Tracer tracer{"synchronize"_t, projectStorageCategory()}; TypeIds deletedTypeIds; Sqlite::withImmediateTransaction(database, [&] { @@ -135,7 +135,7 @@ public: void synchronizeDocumentImports(Storage::Imports imports, SourceId sourceId) override { - NanotraceHR::Tracer tracer{"synchronize document imports"_t, projectStorageCategory}; + NanotraceHR::Tracer tracer{"synchronize document imports"_t, projectStorageCategory()}; Sqlite::withImmediateTransaction(database, [&] { synchronizeDocumentImports(imports, @@ -153,14 +153,14 @@ public: ModuleId moduleId(Utils::SmallStringView moduleName) const override { - NanotraceHR::Tracer tracer{"get module id"_t, projectStorageCategory}; + NanotraceHR::Tracer tracer{"get module id"_t, projectStorageCategory()}; return moduleCache.id(moduleName); } Utils::SmallString moduleName(ModuleId moduleId) const { - NanotraceHR::Tracer tracer{"get module name"_t, projectStorageCategory}; + NanotraceHR::Tracer tracer{"get module name"_t, projectStorageCategory()}; if (!moduleId) throw ModuleDoesNotExists{}; @@ -172,7 +172,7 @@ public: Utils::SmallStringView exportedTypeName, Storage::Version version) const override { - NanotraceHR::Tracer tracer{"get type id by exported name"_t, projectStorageCategory}; + NanotraceHR::Tracer tracer{"get type id by exported name"_t, projectStorageCategory()}; if (version.minor) return selectTypeIdByModuleIdAndExportedNameAndVersionStatement @@ -191,14 +191,14 @@ public: TypeId typeId(ImportedTypeNameId typeNameId) const override { - NanotraceHR::Tracer tracer{"get type id by imported type name"_t, projectStorageCategory}; + NanotraceHR::Tracer tracer{"get type id by imported type name"_t, projectStorageCategory()}; return Sqlite::withDeferredTransaction(database, [&] { return fetchTypeId(typeNameId); }); } QVarLengthArray typeIds(ModuleId moduleId) const override { - NanotraceHR::Tracer tracer{"get type ids by module id"_t, projectStorageCategory}; + NanotraceHR::Tracer tracer{"get type ids by module id"_t, projectStorageCategory()}; return selectTypeIdsByModuleIdStatement .template valuesWithTransaction>(moduleId); @@ -206,7 +206,7 @@ public: Storage::Info::ExportedTypeNames exportedTypeNames(TypeId typeId) const override { - NanotraceHR::Tracer tracer{"get exported type names by type id"_t, projectStorageCategory}; + NanotraceHR::Tracer tracer{"get exported type names by type id"_t, projectStorageCategory()}; return selectExportedTypesByTypeIdStatement .template valuesWithTransaction(typeId); @@ -215,7 +215,7 @@ public: Storage::Info::ExportedTypeNames exportedTypeNames(TypeId typeId, SourceId sourceId) const override { - NanotraceHR::Tracer tracer{"get exported type names by source id"_t, projectStorageCategory}; + NanotraceHR::Tracer tracer{"get exported type names by source id"_t, projectStorageCategory()}; return selectExportedTypesByTypeIdAndSourceIdStatement .template valuesWithTransaction(typeId, sourceId); @@ -223,7 +223,7 @@ public: ImportId importId(const Storage::Import &import) const override { - NanotraceHR::Tracer tracer{"get import id by import"_t, projectStorageCategory}; + NanotraceHR::Tracer tracer{"get import id by import"_t, projectStorageCategory()}; return Sqlite::withDeferredTransaction(database, [&] { return fetchImportId(import.sourceId, import); @@ -233,7 +233,8 @@ public: ImportedTypeNameId importedTypeNameId(ImportId importId, Utils::SmallStringView typeName) override { - NanotraceHR::Tracer tracer{"get imported type name id by import id"_t, projectStorageCategory}; + NanotraceHR::Tracer tracer{"get imported type name id by import id"_t, + projectStorageCategory()}; return Sqlite::withDeferredTransaction(database, [&] { return fetchImportedTypeNameId(Storage::Synchronization::TypeNameKind::QualifiedExported, @@ -245,7 +246,8 @@ public: ImportedTypeNameId importedTypeNameId(SourceId sourceId, Utils::SmallStringView typeName) override { - NanotraceHR::Tracer tracer{"get imported type name id by source id"_t, projectStorageCategory}; + NanotraceHR::Tracer tracer{"get imported type name id by source id"_t, + projectStorageCategory()}; return Sqlite::withDeferredTransaction(database, [&] { return fetchImportedTypeNameId(Storage::Synchronization::TypeNameKind::Exported, @@ -256,7 +258,7 @@ public: QVarLengthArray propertyDeclarationIds(TypeId typeId) const override { - NanotraceHR::Tracer tracer{"get property declaration ids"_t, projectStorageCategory}; + NanotraceHR::Tracer tracer{"get property declaration ids"_t, projectStorageCategory()}; return selectPropertyDeclarationIdsForTypeStatement .template valuesWithTransaction>(typeId); @@ -264,7 +266,7 @@ public: QVarLengthArray localPropertyDeclarationIds(TypeId typeId) const override { - NanotraceHR::Tracer tracer{"get local property declaration ids"_t, projectStorageCategory}; + NanotraceHR::Tracer tracer{"get local property declaration ids"_t, projectStorageCategory()}; return selectLocalPropertyDeclarationIdsForTypeStatement .template valuesWithTransaction>(typeId); @@ -273,7 +275,7 @@ public: PropertyDeclarationId propertyDeclarationId(TypeId typeId, Utils::SmallStringView propertyName) const override { - NanotraceHR::Tracer tracer{"get property declaration id"_t, projectStorageCategory}; + NanotraceHR::Tracer tracer{"get property declaration id"_t, projectStorageCategory()}; return selectPropertyDeclarationIdForTypeAndPropertyNameStatement .template valueWithTransaction(typeId, propertyName); @@ -282,7 +284,7 @@ public: PropertyDeclarationId localPropertyDeclarationId(TypeId typeId, Utils::SmallStringView propertyName) const { - NanotraceHR::Tracer tracer{"get local property declaration id"_t, projectStorageCategory}; + NanotraceHR::Tracer tracer{"get local property declaration id"_t, projectStorageCategory()}; return selectLocalPropertyDeclarationIdForTypeAndPropertyNameStatement .template valueWithTransaction(typeId, propertyName); @@ -291,7 +293,7 @@ public: std::optional propertyDeclaration( PropertyDeclarationId propertyDeclarationId) const override { - NanotraceHR::Tracer tracer{"get property declaration"_t, projectStorageCategory}; + NanotraceHR::Tracer tracer{"get property declaration"_t, projectStorageCategory()}; return selectPropertyDeclarationForPropertyDeclarationIdStatement .template optionalValueWithTransaction( @@ -300,7 +302,7 @@ public: std::optional type(TypeId typeId) const override { - NanotraceHR::Tracer tracer{"get type"_t, projectStorageCategory}; + NanotraceHR::Tracer tracer{"get type"_t, projectStorageCategory()}; return selectInfoTypeByTypeIdStatement.template optionalValueWithTransaction( typeId); @@ -308,14 +310,14 @@ public: Utils::PathString typeIconPath(TypeId typeId) const override { - NanotraceHR::Tracer tracer{"get type icon path"_t, projectStorageCategory}; + NanotraceHR::Tracer tracer{"get type icon path"_t, projectStorageCategory()}; return selectTypeIconPathStatement.template valueWithTransaction(typeId); } Storage::Info::TypeHints typeHints(TypeId typeId) const override { - NanotraceHR::Tracer tracer{"get type hints"_t, projectStorageCategory}; + NanotraceHR::Tracer tracer{"get type hints"_t, projectStorageCategory()}; return selectTypeHintsStatement.template valuesWithTransaction( typeId); @@ -323,7 +325,7 @@ public: Storage::Info::ItemLibraryEntries itemLibraryEntries(TypeId typeId) const override { - NanotraceHR::Tracer tracer{"get item library entries by type id"_t, projectStorageCategory}; + NanotraceHR::Tracer tracer{"get item library entries by type id"_t, projectStorageCategory()}; using Storage::Info::ItemLibraryProperties; Storage::Info::ItemLibraryEntries entries; @@ -352,7 +354,8 @@ public: Storage::Info::ItemLibraryEntries itemLibraryEntries(SourceId sourceId) const override { - NanotraceHR::Tracer tracer{"get item library entries by source id"_t, projectStorageCategory}; + NanotraceHR::Tracer tracer{"get item library entries by source id"_t, + projectStorageCategory()}; using Storage::Info::ItemLibraryProperties; Storage::Info::ItemLibraryEntries entries; @@ -381,7 +384,7 @@ public: Storage::Info::ItemLibraryEntries allItemLibraryEntries() const override { - NanotraceHR::Tracer tracer{"get all item library entries"_t, projectStorageCategory}; + NanotraceHR::Tracer tracer{"get all item library entries"_t, projectStorageCategory()}; using Storage::Info::ItemLibraryProperties; Storage::Info::ItemLibraryEntries entries; @@ -410,7 +413,7 @@ public: std::vector signalDeclarationNames(TypeId typeId) const override { - NanotraceHR::Tracer tracer{"get signal names"_t, projectStorageCategory}; + NanotraceHR::Tracer tracer{"get signal names"_t, projectStorageCategory()}; return selectSignalDeclarationNamesForTypeStatement .template valuesWithTransaction(typeId); @@ -418,7 +421,7 @@ public: std::vector functionDeclarationNames(TypeId typeId) const override { - NanotraceHR::Tracer tracer{"get function names"_t, projectStorageCategory}; + NanotraceHR::Tracer tracer{"get function names"_t, projectStorageCategory()}; return selectFuncionDeclarationNamesForTypeStatement .template valuesWithTransaction(typeId); @@ -426,7 +429,7 @@ public: std::optional propertyName(PropertyDeclarationId propertyDeclarationId) const override { - NanotraceHR::Tracer tracer{"get property name"_t, projectStorageCategory}; + NanotraceHR::Tracer tracer{"get property name"_t, projectStorageCategory()}; return selectPropertyNameStatement.template optionalValueWithTransaction( propertyDeclarationId); @@ -440,7 +443,7 @@ public: template TypeId commonTypeId() const { - NanotraceHR::Tracer tracer{"get type id from common type cache"_t, projectStorageCategory}; + NanotraceHR::Tracer tracer{"get type id from common type cache"_t, projectStorageCategory()}; return commonTypeCache_.template typeId(); } @@ -449,7 +452,7 @@ public: TypeId builtinTypeId() const { NanotraceHR::Tracer tracer{"get builtin type id from common type cache"_t, - projectStorageCategory}; + projectStorageCategory()}; return commonTypeCache_.template builtinTypeId(); } @@ -458,14 +461,14 @@ public: TypeId builtinTypeId() const { NanotraceHR::Tracer tracer{"get builtin type id from common type cache"_t, - projectStorageCategory}; + projectStorageCategory()}; return commonTypeCache_.template builtinTypeId(); } TypeIds prototypeIds(TypeId type) const override { - NanotraceHR::Tracer tracer{"get prototypes"_t, projectStorageCategory}; + NanotraceHR::Tracer tracer{"get prototypes"_t, projectStorageCategory()}; return selectPrototypeIdsForTypeIdInOrderStatement.template valuesWithTransaction( type); @@ -473,7 +476,7 @@ public: TypeIds prototypeAndSelfIds(TypeId type) const override { - NanotraceHR::Tracer tracer{"get prototypes and self"_t, projectStorageCategory}; + NanotraceHR::Tracer tracer{"get prototypes and self"_t, projectStorageCategory()}; return selectPrototypeAndSelfIdsForTypeIdInOrderStatement .template valuesWithTransaction(type); @@ -481,7 +484,7 @@ public: TypeIds heirIds(TypeId typeId) const override { - NanotraceHR::Tracer tracer{"get heirs"_t, projectStorageCategory}; + NanotraceHR::Tracer tracer{"get heirs"_t, projectStorageCategory()}; return selectHeirTypeIdsStatement.template valuesWithTransaction(typeId); } @@ -489,7 +492,7 @@ public: template bool isBasedOn_(TypeId typeId, TypeIds... baseTypeIds) const { - NanotraceHR::Tracer tracer{"is based on"_t, projectStorageCategory}; + NanotraceHR::Tracer tracer{"is based on"_t, projectStorageCategory()}; static_assert(((std::is_same_v) &&...), "Parameter must be a TypeId!"); @@ -550,7 +553,7 @@ public: TypeId fetchTypeIdByExportedName(Utils::SmallStringView name) const { - NanotraceHR::Tracer tracer{"is based on"_t, projectStorageCategory}; + NanotraceHR::Tracer tracer{"is based on"_t, projectStorageCategory()}; return selectTypeIdByExportedNameStatement.template valueWithTransaction(name); } @@ -612,7 +615,7 @@ public: SourceContextId fetchSourceContextIdUnguarded(Utils::SmallStringView sourceContextPath) { - NanotraceHR::Tracer tracer{"fetch source context id unguarded"_t, projectStorageCategory}; + NanotraceHR::Tracer tracer{"fetch source context id unguarded"_t, projectStorageCategory()}; auto sourceContextId = readSourceContextId(sourceContextPath); @@ -621,7 +624,7 @@ public: SourceContextId fetchSourceContextId(Utils::SmallStringView sourceContextPath) { - NanotraceHR::Tracer tracer{"fetch source context id"_t, projectStorageCategory}; + NanotraceHR::Tracer tracer{"fetch source context id"_t, projectStorageCategory()}; try { return Sqlite::withDeferredTransaction(database, [&] { @@ -634,7 +637,7 @@ public: Utils::PathString fetchSourceContextPath(SourceContextId sourceContextId) const { - NanotraceHR::Tracer tracer{"fetch source context path"_t, projectStorageCategory}; + NanotraceHR::Tracer tracer{"fetch source context path"_t, projectStorageCategory()}; return Sqlite::withDeferredTransaction(database, [&] { auto optionalSourceContextPath = selectSourceContextPathFromSourceContextsBySourceContextIdStatement @@ -650,7 +653,7 @@ public: auto fetchAllSourceContexts() const { - NanotraceHR::Tracer tracer{"fetch all source contexts"_t, projectStorageCategory}; + NanotraceHR::Tracer tracer{"fetch all source contexts"_t, projectStorageCategory()}; return selectAllSourceContextsStatement .template valuesWithTransaction(); @@ -658,7 +661,7 @@ public: SourceId fetchSourceId(SourceContextId sourceContextId, Utils::SmallStringView sourceName) { - NanotraceHR::Tracer tracer{"fetch source id"_t, projectStorageCategory}; + NanotraceHR::Tracer tracer{"fetch source id"_t, projectStorageCategory()}; return Sqlite::withDeferredTransaction(database, [&] { return fetchSourceIdUnguarded(sourceContextId, sourceName); @@ -668,7 +671,7 @@ public: auto fetchSourceNameAndSourceContextId(SourceId sourceId) const { NanotraceHR::Tracer tracer{"fetch source name and source context id"_t, - projectStorageCategory}; + projectStorageCategory()}; auto value = selectSourceNameAndSourceContextIdFromSourcesBySourceIdStatement .template valueWithTransaction(sourceId); @@ -689,7 +692,7 @@ public: SourceContextId fetchSourceContextId(SourceId sourceId) const { - NanotraceHR::Tracer tracer{"fetch source context id"_t, projectStorageCategory}; + NanotraceHR::Tracer tracer{"fetch source context id"_t, projectStorageCategory()}; auto sourceContextId = selectSourceContextIdFromSourcesBySourceIdStatement .template valueWithTransaction(sourceId); @@ -702,14 +705,14 @@ public: auto fetchAllSources() const { - NanotraceHR::Tracer tracer{"fetch all sources"_t, projectStorageCategory}; + NanotraceHR::Tracer tracer{"fetch all sources"_t, projectStorageCategory()}; return selectAllSourcesStatement.template valuesWithTransaction(); } SourceId fetchSourceIdUnguarded(SourceContextId sourceContextId, Utils::SmallStringView sourceName) { - NanotraceHR::Tracer tracer{"fetch source id unguarded"_t, projectStorageCategory}; + NanotraceHR::Tracer tracer{"fetch source id unguarded"_t, projectStorageCategory()}; auto sourceId = readSourceId(sourceContextId, sourceName); @@ -721,14 +724,14 @@ public: auto fetchAllFileStatuses() const { - NanotraceHR::Tracer tracer{"fetch all file statuses"_t, projectStorageCategory}; + NanotraceHR::Tracer tracer{"fetch all file statuses"_t, projectStorageCategory()}; return selectAllFileStatusesStatement.template rangeWithTransaction(); } FileStatus fetchFileStatus(SourceId sourceId) const override { - NanotraceHR::Tracer tracer{"fetch file status"_t, projectStorageCategory}; + NanotraceHR::Tracer tracer{"fetch file status"_t, projectStorageCategory()}; return selectFileStatusesForSourceIdStatement.template valueWithTransaction( sourceId); @@ -736,7 +739,7 @@ public: std::optional fetchProjectData(SourceId sourceId) const override { - NanotraceHR::Tracer tracer{"fetch project data"_t, projectStorageCategory}; + NanotraceHR::Tracer tracer{"fetch project data"_t, projectStorageCategory()}; return selectProjectDataForSourceIdStatement .template optionalValueWithTransaction(sourceId); @@ -744,7 +747,7 @@ public: Storage::Synchronization::ProjectDatas fetchProjectDatas(SourceId projectSourceId) const override { - NanotraceHR::Tracer tracer{"fetch project datas by source id"_t, projectStorageCategory}; + NanotraceHR::Tracer tracer{"fetch project datas by source id"_t, projectStorageCategory()}; return selectProjectDatasForSourceIdStatement .template valuesWithTransaction( @@ -753,7 +756,7 @@ public: Storage::Synchronization::ProjectDatas fetchProjectDatas(const SourceIds &projectSourceIds) const { - NanotraceHR::Tracer tracer{"fetch project datas by source ids"_t, projectStorageCategory}; + NanotraceHR::Tracer tracer{"fetch project datas by source ids"_t, projectStorageCategory()}; return selectProjectDatasForSourceIdsStatement .template valuesWithTransaction( @@ -776,7 +779,7 @@ public: Storage::Imports fetchDocumentImports() const { - NanotraceHR::Tracer tracer{"fetch document imports"_t, projectStorageCategory}; + NanotraceHR::Tracer tracer{"fetch document imports"_t, projectStorageCategory()}; return selectAllDocumentImportForSourceIdStatement .template valuesWithTransaction(); @@ -1030,7 +1033,7 @@ private: void synchronizeTypeAnnotations(Storage::Synchronization::TypeAnnotations &typeAnnotations, const SourceIds &updatedTypeAnnotationSourceIds) { - NanotraceHR::Tracer tracer{"synchronize type annotations"_t, projectStorageCategory}; + NanotraceHR::Tracer tracer{"synchronize type annotations"_t, projectStorageCategory()}; using Storage::Synchronization::TypeAnnotation; @@ -1099,7 +1102,7 @@ private: Prototypes &relinkableExtensions, const SourceIds &updatedSourceIds) { - NanotraceHR::Tracer tracer{"synchronize types"_t, projectStorageCategory}; + NanotraceHR::Tracer tracer{"synchronize types"_t, projectStorageCategory()}; Storage::Synchronization::ExportedTypes exportedTypes; exportedTypes.reserve(types.size() * 3); @@ -1156,7 +1159,7 @@ private: void synchronizeProjectDatas(Storage::Synchronization::ProjectDatas &projectDatas, const SourceIds &updatedProjectSourceIds) { - NanotraceHR::Tracer tracer{"synchronize project datas"_t, projectStorageCategory}; + NanotraceHR::Tracer tracer{"synchronize project datas"_t, projectStorageCategory()}; auto compareKey = [](auto &&first, auto &&second) { auto projectSourceIdDifference = first.projectSourceId - second.projectSourceId; @@ -1210,7 +1213,7 @@ private: void synchronizeFileStatuses(FileStatuses &fileStatuses, const SourceIds &updatedSourceIds) { - NanotraceHR::Tracer tracer{"synchronize file statuses"_t, projectStorageCategory}; + NanotraceHR::Tracer tracer{"synchronize file statuses"_t, projectStorageCategory()}; auto compareKey = [](auto &&first, auto &&second) { return first.sourceId - second.sourceId; @@ -1257,7 +1260,7 @@ private: Storage::Synchronization::ModuleExportedImports &moduleExportedImports, const ModuleIds &updatedModuleIds) { - NanotraceHR::Tracer tracer{"synchronize imports"_t, projectStorageCategory}; + NanotraceHR::Tracer tracer{"synchronize imports"_t, projectStorageCategory()}; synchromizeModuleExportedImports(moduleExportedImports, updatedModuleIds); synchronizeDocumentImports(imports, @@ -1418,7 +1421,7 @@ private: void relinkAliasPropertyDeclarations(AliasPropertyDeclarations &aliasPropertyDeclarations, const TypeIds &deletedTypeIds) { - NanotraceHR::Tracer tracer{"relink alias properties"_t, projectStorageCategory}; + NanotraceHR::Tracer tracer{"relink alias properties"_t, projectStorageCategory()}; std::sort(aliasPropertyDeclarations.begin(), aliasPropertyDeclarations.end()); @@ -1448,7 +1451,7 @@ private: void relinkPropertyDeclarations(PropertyDeclarations &relinkablePropertyDeclaration, const TypeIds &deletedTypeIds) { - NanotraceHR::Tracer tracer{"relink properties"_t, projectStorageCategory}; + NanotraceHR::Tracer tracer{"relink properties"_t, projectStorageCategory()}; std::sort(relinkablePropertyDeclaration.begin(), relinkablePropertyDeclaration.end()); @@ -1474,7 +1477,7 @@ private: const TypeIds &deletedTypeIds, Callable updateStatement) { - NanotraceHR::Tracer tracer{"relink prototypes"_t, projectStorageCategory}; + NanotraceHR::Tracer tracer{"relink prototypes"_t, projectStorageCategory()}; std::sort(relinkablePrototypes.begin(), relinkablePrototypes.end()); @@ -1504,7 +1507,7 @@ private: Prototypes &relinkableExtensions, TypeIds &deletedTypeIds) { - NanotraceHR::Tracer tracer{"delete not updated types"_t, projectStorageCategory}; + NanotraceHR::Tracer tracer{"delete not updated types"_t, projectStorageCategory()}; auto callback = [&](TypeId typeId) { deletedTypeIds.push_back(typeId); @@ -1528,7 +1531,7 @@ private: Prototypes &relinkableExtensions, TypeIds &deletedTypeIds) { - NanotraceHR::Tracer tracer{"relink"_t, projectStorageCategory}; + NanotraceHR::Tracer tracer{"relink"_t, projectStorageCategory()}; std::sort(deletedTypeIds.begin(), deletedTypeIds.end()); @@ -1596,7 +1599,7 @@ private: void linkAliases(const AliasPropertyDeclarations &insertedAliasPropertyDeclarations, const AliasPropertyDeclarations &updatedAliasPropertyDeclarations) { - NanotraceHR::Tracer tracer{"link aliases"_t, projectStorageCategory}; + NanotraceHR::Tracer tracer{"link aliases"_t, projectStorageCategory()}; linkAliasPropertyDeclarationAliasIds(insertedAliasPropertyDeclarations); linkAliasPropertyDeclarationAliasIds(updatedAliasPropertyDeclarations); @@ -1615,7 +1618,7 @@ private: Prototypes &relinkablePrototypes, Prototypes &relinkableExtensions) { - NanotraceHR::Tracer tracer{"synchronize exported types"_t, projectStorageCategory}; + NanotraceHR::Tracer tracer{"synchronize exported types"_t, projectStorageCategory()}; std::sort(exportedTypes.begin(), exportedTypes.end(), [](auto &&first, auto &&second) { if (first.moduleId < second.moduleId) @@ -1800,7 +1803,7 @@ private: AliasPropertyDeclarations &updatedAliasPropertyDeclarations, PropertyDeclarationIds &propertyDeclarationIds) { - NanotraceHR::Tracer tracer{"synchronize property declaration"_t, projectStorageCategory}; + NanotraceHR::Tracer tracer{"synchronize property declaration"_t, projectStorageCategory()}; std::sort(propertyDeclarations.begin(), propertyDeclarations.end(), @@ -1918,7 +1921,8 @@ private: Storage::Synchronization::Types &types, AliasPropertyDeclarations &relinkableAliasPropertyDeclarations) { - NanotraceHR::Tracer tracer{"reset removed alias properties to null"_t, projectStorageCategory}; + NanotraceHR::Tracer tracer{"reset removed alias properties to null"_t, + projectStorageCategory()}; PropertyDeclarationIds propertyDeclarationIds; propertyDeclarationIds.reserve(types.size()); @@ -2117,7 +2121,8 @@ private: void synchronizePropertyEditorQmlPaths(Storage::Synchronization::PropertyEditorQmlPaths &paths, SourceIds updatedPropertyEditorQmlPathsSourceIds) { - NanotraceHR::Tracer tracer{"synchronize property editor qml paths"_t, projectStorageCategory}; + NanotraceHR::Tracer tracer{"synchronize property editor qml paths"_t, + projectStorageCategory()}; addTypeIdToPropertyEditorQmlPaths(paths); synchronizePropertyEditorPaths(paths, updatedPropertyEditorQmlPathsSourceIds); @@ -2126,7 +2131,7 @@ private: void synchronizeFunctionDeclarations( TypeId typeId, Storage::Synchronization::FunctionDeclarations &functionsDeclarations) { - NanotraceHR::Tracer tracer{"synchronize function declaration"_t, projectStorageCategory}; + NanotraceHR::Tracer tracer{"synchronize function declaration"_t, projectStorageCategory()}; std::sort(functionsDeclarations.begin(), functionsDeclarations.end(), @@ -2185,7 +2190,7 @@ private: void synchronizeSignalDeclarations(TypeId typeId, Storage::Synchronization::SignalDeclarations &signalDeclarations) { - NanotraceHR::Tracer tracer{"synchronize signal declaration"_t, projectStorageCategory}; + NanotraceHR::Tracer tracer{"synchronize signal declaration"_t, projectStorageCategory()}; std::sort(signalDeclarations.begin(), signalDeclarations.end(), [](auto &&first, auto &&second) { auto compare = Sqlite::compare(first.name, second.name); @@ -2261,7 +2266,7 @@ private: void synchronizeEnumerationDeclarations( TypeId typeId, Storage::Synchronization::EnumerationDeclarations &enumerationDeclarations) { - NanotraceHR::Tracer tracer{"synchronize enumeation declaration"_t, projectStorageCategory}; + NanotraceHR::Tracer tracer{"synchronize enumeation declaration"_t, projectStorageCategory()}; std::sort(enumerationDeclarations.begin(), enumerationDeclarations.end(), @@ -2335,7 +2340,7 @@ private: AliasPropertyDeclarations &updatedAliasPropertyDeclarations, PropertyDeclarationIds &propertyDeclarationIds) { - NanotraceHR::Tracer tracer{"synchronize declaration per type"_t, projectStorageCategory}; + NanotraceHR::Tracer tracer{"synchronize declaration per type"_t, projectStorageCategory()}; if (type.changeLevel == Storage::Synchronization::ChangeLevel::Minimal) return; @@ -2354,7 +2359,7 @@ private: template void removeRelinkableEntries(std::vector &relinkables, Ids &ids, Compare compare) { - NanotraceHR::Tracer tracer{"remove relinkable entries"_t, projectStorageCategory}; + NanotraceHR::Tracer tracer{"remove relinkable entries"_t, projectStorageCategory()}; std::vector newRelinkables; newRelinkables.reserve(relinkables.size()); @@ -2378,7 +2383,7 @@ private: AliasPropertyDeclarations &updatedAliasPropertyDeclarations, PropertyDeclarations &relinkablePropertyDeclarations) { - NanotraceHR::Tracer tracer{"synchronize declaration"_t, projectStorageCategory}; + NanotraceHR::Tracer tracer{"synchronize declaration"_t, projectStorageCategory()}; PropertyDeclarationIds propertyDeclarationIds; propertyDeclarationIds.reserve(types.size() * 10); @@ -2408,7 +2413,7 @@ private: void syncDefaultProperties(Storage::Synchronization::Types &types) { - NanotraceHR::Tracer tracer{"synchronize default properties"_t, projectStorageCategory}; + NanotraceHR::Tracer tracer{"synchronize default properties"_t, projectStorageCategory()}; auto range = selectTypesWithDefaultPropertyStatement.template range(); @@ -2444,7 +2449,7 @@ private: void resetDefaultPropertiesIfChanged(Storage::Synchronization::Types &types) { - NanotraceHR::Tracer tracer{"reset changed default properties"_t, projectStorageCategory}; + NanotraceHR::Tracer tracer{"reset changed default properties"_t, projectStorageCategory()}; auto range = selectTypesWithDefaultPropertyStatement.template range(); @@ -2544,7 +2549,7 @@ private: Prototypes &relinkablePrototypes, Prototypes &relinkableExtensions) { - NanotraceHR::Tracer tracer{"synchronize prototypes"_t, projectStorageCategory}; + NanotraceHR::Tracer tracer{"synchronize prototypes"_t, projectStorageCategory()}; TypeIds typeIds; typeIds.reserve(types.size()); diff --git a/src/plugins/qmldesigner/designercore/tracing/qmldesignertracing.cpp b/src/plugins/qmldesigner/designercore/tracing/qmldesignertracing.cpp index f780e813ddd..ea0fe73c0f4 100644 --- a/src/plugins/qmldesigner/designercore/tracing/qmldesignertracing.cpp +++ b/src/plugins/qmldesigner/designercore/tracing/qmldesignertracing.cpp @@ -32,7 +32,7 @@ namespace ModelTracing { namespace { using namespace NanotraceHR::Literals; -thread_local Category category_{"model"_t, Tracing::stringViewEventWithStringArgumentsQueue_}; +thread_local Category category_{"model"_t, Tracing::stringViewEventWithStringArgumentsQueue_, category}; } // namespace