From a9dae5ea7a42f97ed55d8548f12c9f3eaa99b412 Mon Sep 17 00:00:00 2001 From: Burak Hancerli Date: Mon, 19 May 2025 15:19:38 +0200 Subject: [PATCH] QmlDesigner: Extend tracing points to the views Task-number: QDS-15148 Change-Id: I54ac7f8e63dd2fa2bc32e22a0b1bff09ca817a7e Reviewed-by: Marco Bubke --- src/libs/nanotrace/nanotracehr.h | 4 ++ .../libs/designercore/include/abstractview.h | 14 ++++- .../libs/designercore/model/model.cpp | 59 +++++++++++++------ .../libs/designercore/model/model_p.h | 9 +-- 4 files changed, 60 insertions(+), 26 deletions(-) diff --git a/src/libs/nanotrace/nanotracehr.h b/src/libs/nanotrace/nanotracehr.h index afe66867831..3b9a31029f8 100644 --- a/src/libs/nanotrace/nanotracehr.h +++ b/src/libs/nanotrace/nanotracehr.h @@ -58,6 +58,10 @@ struct TracerLiteral : text{text} {} + consteval TracerLiteral(const char *text) + : text{text} + {} + template consteval TracerLiteral(const char (&text)[size]) : text{text} diff --git a/src/plugins/qmldesigner/libs/designercore/include/abstractview.h b/src/plugins/qmldesigner/libs/designercore/include/abstractview.h index 0a684162f4d..c6e432a219c 100644 --- a/src/plugins/qmldesigner/libs/designercore/include/abstractview.h +++ b/src/plugins/qmldesigner/libs/designercore/include/abstractview.h @@ -67,9 +67,11 @@ public: }; Q_DECLARE_FLAGS(PropertyChangeFlags, PropertyChangeFlag) - AbstractView(ExternalDependenciesInterface &externalDependencies) + AbstractView(ExternalDependenciesInterface &externalDependencies, + NanotraceHR::TracerLiteral functionName = __builtin_FUNCTION()) : m_externalDependencies{externalDependencies} , m_action{Utils::makeUniqueObjectPtr(*this)} + , m_name(functionName) {} void setWidgetRegistration(WidgetRegistrationInterface *interface); @@ -287,6 +289,14 @@ public: AbstractView *m_view; }; + template + friend void convertToString(String &string, const AbstractView *view) + { + convertToString(string, view->m_name); + } + + const auto &name() const { return m_name; } + protected: void setModel(Model *model); void removeModel(); @@ -310,6 +320,8 @@ private: bool m_isBlockingNotifications = false; Kind m_kind = Kind::Other; WidgetRegistrationInterface *m_widgetRegistration = nullptr; + + NanotraceHR::TracerLiteral m_name; }; QMLDESIGNERCORE_EXPORT QList toModelNodeList( diff --git a/src/plugins/qmldesigner/libs/designercore/model/model.cpp b/src/plugins/qmldesigner/libs/designercore/model/model.cpp index 331fff52150..2a87261b1de 100644 --- a/src/plugins/qmldesigner/libs/designercore/model/model.cpp +++ b/src/plugins/qmldesigner/libs/designercore/model/model.cpp @@ -546,15 +546,16 @@ bool ModelPrivate::propertyNameIsValid(PropertyNameView propertyName) return true; } -template -void ModelPrivate::notifyNodeInstanceViewLast(Callable call) +void ModelPrivate::notifyNodeInstanceViewLast(const std::invocable auto &call) { bool resetModel = false; QString description; try { - if (m_rewriterView && !m_rewriterView->isBlockingNotifications()) + if (m_rewriterView && !m_rewriterView->isBlockingNotifications()) { + NanotraceHR::Tracer tracer{m_rewriterView->name(), ModelTracing::category()}; call(m_rewriterView); + } } catch (const RewritingException &e) { description = e.description(); resetModel = true; @@ -562,52 +563,62 @@ void ModelPrivate::notifyNodeInstanceViewLast(Callable call) for (const QPointer &view : std::as_const(m_viewList)) { try { - if (!view->isBlockingNotifications()) + if (!view->isBlockingNotifications()) { + NanotraceHR::Tracer tracer{view->name(), ModelTracing::category()}; call(view.data()); + } } catch (const Exception &e) { e.showException(tr("Exception thrown by view %1.").arg(view->widgetInfo().tabName)); } } - if (nodeInstanceView() && !nodeInstanceView()->isBlockingNotifications()) - call(nodeInstanceView()); + if (m_nodeInstanceView && !m_nodeInstanceView->isBlockingNotifications()) { + NanotraceHR::Tracer tracer{m_nodeInstanceView->name(), ModelTracing::category()}; + call(m_nodeInstanceView); + } if (resetModel) resetModelByRewriter(description); } -template -void ModelPrivate::notifyNormalViewsLast(Callable call) +void ModelPrivate::notifyNormalViewsLast(const std::invocable auto &call) { bool resetModel = false; QString description; try { - if (m_rewriterView && !m_rewriterView->isBlockingNotifications()) + if (m_rewriterView && !m_rewriterView->isBlockingNotifications()) { + NanotraceHR::Tracer tracer{m_rewriterView->name(), ModelTracing::category()}; call(m_rewriterView); + } } catch (const RewritingException &e) { description = e.description(); resetModel = true; } - if (nodeInstanceView() && !nodeInstanceView()->isBlockingNotifications()) - call(nodeInstanceView()); + if (m_nodeInstanceView && !m_nodeInstanceView->isBlockingNotifications()) { + NanotraceHR::Tracer tracer{m_nodeInstanceView->name(), ModelTracing::category()}; + call(m_nodeInstanceView); + } for (const QPointer &view : std::as_const(m_viewList)) { - if (!view->isBlockingNotifications()) + if (!view->isBlockingNotifications()) { + NanotraceHR::Tracer tracer{view->name(), ModelTracing::category()}; call(view.data()); + } } if (resetModel) resetModelByRewriter(description); } -template -void ModelPrivate::notifyInstanceChanges(Callable call) +void ModelPrivate::notifyInstanceChanges(const std::invocable auto &call) { for (const QPointer &view : std::as_const(m_viewList)) { - if (!view->isBlockingNotifications()) + if (!view->isBlockingNotifications()) { + NanotraceHR::Tracer tracer{view->name(), ModelTracing::category()}; call(view.data()); + } } } @@ -615,6 +626,7 @@ void ModelPrivate::notifyAuxiliaryDataChanged(const InternalNodePointer &node, AuxiliaryDataKeyView key, const QVariant &data) { + NanotraceHR::Tracer tracer{"notify auxiliary data changed", ModelTracing::category()}; notifyNodeInstanceViewLast([&](AbstractView *view) { ModelNode modelNode(node, m_model, view); view->auxiliaryDataChanged(modelNode, key, data); @@ -809,8 +821,10 @@ void ModelPrivate::notifyCustomNotification(const AbstractView *senderView, void ModelPrivate::notifyCustomNotificationTo(AbstractView *view, const CustomNotificationPackage &package) { - if (view) + if (view) { + NanotraceHR::Tracer tracer{view->name(), ModelTracing::category()}; view->customNotification(package); + } } void ModelPrivate::notifyPropertiesRemoved(const QList &propertyPairList) @@ -832,6 +846,8 @@ void ModelPrivate::notifyPropertiesAboutToBeRemoved(const QListname(), ModelTracing::category()}; + QList propertyList; for (InternalProperty *property : internalPropertyList) { AbstractProperty newProperty(property->name(), @@ -849,6 +865,7 @@ void ModelPrivate::notifyPropertiesAboutToBeRemoved(const QList &view : std::as_const(m_viewList)) { + NanotraceHR::Tracer tracer{view->name(), ModelTracing::category()}; QList propertyList; Q_ASSERT(view != nullptr); for (auto property : internalPropertyList) { @@ -864,14 +881,18 @@ void ModelPrivate::notifyPropertiesAboutToBeRemoved(const QListname(), ModelTracing::category()}; QList propertyList; for (auto property : internalPropertyList) { - AbstractProperty newProperty(property->name(), property->propertyOwner(), m_model, nodeInstanceView()); + AbstractProperty newProperty(property->name(), + property->propertyOwner(), + m_model, + m_nodeInstanceView); propertyList.append(newProperty); } - nodeInstanceView()->propertiesAboutToBeRemoved(propertyList); + m_nodeInstanceView->propertiesAboutToBeRemoved(propertyList); } if (resetModel) diff --git a/src/plugins/qmldesigner/libs/designercore/model/model_p.h b/src/plugins/qmldesigner/libs/designercore/model/model_p.h index 0d3b18492ee..13e8d8aaf2b 100644 --- a/src/plugins/qmldesigner/libs/designercore/model/model_p.h +++ b/src/plugins/qmldesigner/libs/designercore/model/model_p.h @@ -137,12 +137,9 @@ public: void detachView(AbstractView *view, bool notifyView); void detachAllViews(); - template - void notifyNodeInstanceViewLast(Callable call); - template - void notifyNormalViewsLast(Callable call); - template - void notifyInstanceChanges(Callable call); + void notifyNodeInstanceViewLast(const std::invocable auto &call); + void notifyNormalViewsLast(const std::invocable auto &call); + void notifyInstanceChanges(const std::invocable auto &call); void notifyNodeCreated(const InternalNodePointer &newNode); void notifyNodeAboutToBeReparent(const InternalNodePointer &node,