From b8b516ff1273ebabf64391aa12de45c47326d98b Mon Sep 17 00:00:00 2001 From: Mike Krus Date: Thu, 5 Dec 2019 17:23:18 +0000 Subject: Move AspectCommandDebugger to system service, activate command executer - Always compile in AspectCommandDebugger and CommandExecuter - AspectCommandDebugger start when QT3D_COMMAND_SERVER_ENABLED is set - System information service becomes entry point for commands from the debugger - Added commands to enable and disable tracing Change-Id: Ic0d7fe72fa8a118a43ca348ca4284595a71827a4 Reviewed-by: Paul Lemire --- src/core/aspects/aspectcommanddebugger.cpp | 20 +++----------- src/core/aspects/aspectcommanddebugger_p.h | 18 ++++++------- src/core/aspects/aspects.pri | 10 +++---- src/core/aspects/qaspectengine.cpp | 12 --------- src/core/aspects/qaspectengine_p.h | 10 ------- src/core/configure.json | 3 +-- src/core/services/qsysteminformationservice.cpp | 33 ++++++++++++++++++++++- src/core/services/qsysteminformationservice_p.h | 5 ++++ src/core/services/qsysteminformationservice_p_p.h | 6 +++++ 9 files changed, 60 insertions(+), 57 deletions(-) (limited to 'src/core') diff --git a/src/core/aspects/aspectcommanddebugger.cpp b/src/core/aspects/aspectcommanddebugger.cpp index eceec1bbd..7635f44c0 100644 --- a/src/core/aspects/aspectcommanddebugger.cpp +++ b/src/core/aspects/aspectcommanddebugger.cpp @@ -39,12 +39,12 @@ #include "aspectcommanddebugger_p.h" -#include #include #include #include #include +#include QT_BEGIN_NAMESPACE @@ -64,13 +64,6 @@ struct CommandHeader } // anonymous -AspectCommandDebugger::ReadBuffer::ReadBuffer() - : buffer() - , startIdx(0) - , endIdx(0) -{ -} - void AspectCommandDebugger::ReadBuffer::insert(const QByteArray &array) { buffer.insert(endIdx, array); @@ -88,9 +81,9 @@ void AspectCommandDebugger::ReadBuffer::trim() } } -AspectCommandDebugger::AspectCommandDebugger(QObject *parent) +AspectCommandDebugger::AspectCommandDebugger(QSystemInformationService *parent) : QTcpServer(parent) - , m_aspectEngine(nullptr) + , m_service(parent) { } @@ -115,11 +108,6 @@ void AspectCommandDebugger::initialize() qWarning() << Q_FUNC_INFO << "failed to listen on port 8883"; } -void AspectCommandDebugger::setAspectEngine(QAspectEngine *engine) -{ - m_aspectEngine = engine; -} - void AspectCommandDebugger::asynchronousReplyFinished(AsynchronousCommandReply *reply) { Q_ASSERT(reply->isFinished()); @@ -189,7 +177,7 @@ void AspectCommandDebugger::executeCommand(const QString &command, QTcpSocket *socket) { // Only a single aspect is going to reply - const QVariant response = m_aspectEngine->executeCommand(command); + const QVariant response = m_service->executeCommand(command); if (response.userType() == qMetaTypeId()) { // AsynchronousCommand // Store the command | socket in a table AsynchronousCommandReply *reply = response.value(); diff --git a/src/core/aspects/aspectcommanddebugger_p.h b/src/core/aspects/aspectcommanddebugger_p.h index bb6100df5..b39708ab1 100644 --- a/src/core/aspects/aspectcommanddebugger_p.h +++ b/src/core/aspects/aspectcommanddebugger_p.h @@ -54,32 +54,30 @@ // #include +#include QT_BEGIN_NAMESPACE namespace Qt3DCore { -class QAspectEngine; +class QSystemInformationService; namespace Debug { class AsynchronousCommandReply; -class Q_AUTOTEST_EXPORT AspectCommandDebugger : public QTcpServer +class Q_3DCORE_PRIVATE_EXPORT AspectCommandDebugger : public QTcpServer { Q_OBJECT public: - explicit AspectCommandDebugger(QObject *parent = nullptr); + explicit AspectCommandDebugger(QSystemInformationService *parent = nullptr); void initialize(); - void setAspectEngine(QAspectEngine *engine); - - struct ReadBuffer { - ReadBuffer(); + struct Q_3DCORE_PRIVATE_EXPORT ReadBuffer { QByteArray buffer; - int startIdx; - int endIdx; + int startIdx = 0; + int endIdx = 0; inline int size() const { return endIdx - startIdx; } void insert(const QByteArray &array); @@ -95,7 +93,7 @@ private: void executeCommand(const QString &command, QTcpSocket *socket); QVector m_connections; - QAspectEngine *m_aspectEngine; + QSystemInformationService *m_service; ReadBuffer m_readBuffer; QHash m_asyncCommandToSocketEntries; diff --git a/src/core/aspects/aspects.pri b/src/core/aspects/aspects.pri index 5e8327192..068f74389 100644 --- a/src/core/aspects/aspects.pri +++ b/src/core/aspects/aspects.pri @@ -4,7 +4,8 @@ SOURCES += \ $$PWD/qabstractaspect.cpp \ $$PWD/qaspectengine.cpp \ $$PWD/qaspectfactory.cpp \ - $$PWD/qaspectmanager.cpp + $$PWD/qaspectmanager.cpp \ + $$PWD/aspectcommanddebugger.cpp HEADERS += \ $$PWD/qabstractaspect.h \ @@ -12,13 +13,10 @@ HEADERS += \ $$PWD/qabstractaspect_p.h \ $$PWD/qaspectengine_p.h \ $$PWD/qaspectfactory_p.h \ - $$PWD/qaspectmanager_p.h + $$PWD/qaspectmanager_p.h \ + $$PWD/aspectcommanddebugger_p.h INCLUDEPATH += $$PWD include($$QT3D_BUILD_ROOT/src/core/qt3dcore-config.pri) QT_FOR_CONFIG += 3dcore-private -qtConfig(qt3d-profile-jobs): { - HEADERS += $$PWD/aspectcommanddebugger_p.h - SOURCES += $$PWD/aspectcommanddebugger.cpp -} diff --git a/src/core/aspects/qaspectengine.cpp b/src/core/aspects/qaspectengine.cpp index e16635cb2..d28306197 100644 --- a/src/core/aspects/qaspectengine.cpp +++ b/src/core/aspects/qaspectengine.cpp @@ -58,10 +58,6 @@ #include #include -#if QT_CONFIG(qt3d_profile_jobs) -#include -#endif - QT_BEGIN_NAMESPACE namespace{ @@ -123,9 +119,6 @@ QAspectEnginePrivate::QAspectEnginePrivate() , m_scene(nullptr) , m_initialized(false) , m_runMode(QAspectEngine::Automatic) - #if QT_CONFIG(qt3d_profile_jobs) - , m_commandDebugger(new Debug::AspectCommandDebugger(q_func())) - #endif { qRegisterMetaType(); qRegisterMetaType(); @@ -277,11 +270,6 @@ void QAspectEnginePrivate::initialize() arbiter->setScene(m_scene); m_initialized = true; m_aspectManager->setPostConstructorInit(m_scene->postConstructorInit()); - Q_Q(QAspectEngine); -#if QT_CONFIG(qt3d_profile_jobs) - m_commandDebugger->setAspectEngine(q_func()); - m_commandDebugger->initialize(); -#endif } /*! diff --git a/src/core/aspects/qaspectengine_p.h b/src/core/aspects/qaspectengine_p.h index c83940435..8f3abcd38 100644 --- a/src/core/aspects/qaspectengine_p.h +++ b/src/core/aspects/qaspectengine_p.h @@ -69,12 +69,6 @@ class QAspectManager; class QPostman; class QScene; -#if QT_CONFIG(qt3d_profile_jobs) -namespace Debug { -class AspectCommandDebugger; -} // Debug -#endif - class Q_3DCORE_PRIVATE_EXPORT QAspectEnginePrivate : public QObjectPrivate { public: @@ -93,10 +87,6 @@ public: bool m_initialized; QAspectEngine::RunMode m_runMode; -#if QT_CONFIG(qt3d_profile_jobs) - Debug::AspectCommandDebugger *m_commandDebugger; -#endif - void initialize(); void shutdown(); diff --git a/src/core/configure.json b/src/core/configure.json index 2ba205530..2e13d9027 100644 --- a/src/core/configure.json +++ b/src/core/configure.json @@ -44,7 +44,7 @@ "output": [ "privateFeature" ] }, "qt3d-profile-jobs": { - "label": "Output Qt3D Job traces", + "label": "Output Qt3D Job traces (deprecated)", "autoDetect": false, "output": [ "privateFeature" ] }, @@ -112,7 +112,6 @@ "entries": [ "assimp", "system-assimp", - "qt3d-profile-jobs", "qt3d-profile-gl", "qt3d-simd-sse2", "qt3d-simd-avx2", diff --git a/src/core/services/qsysteminformationservice.cpp b/src/core/services/qsysteminformationservice.cpp index ae7b96f89..40f3594fb 100644 --- a/src/core/services/qsysteminformationservice.cpp +++ b/src/core/services/qsysteminformationservice.cpp @@ -51,8 +51,9 @@ #include #include -#include #include +#include +#include QT_BEGIN_NAMESPACE @@ -86,10 +87,17 @@ QSystemInformationServicePrivate::QSystemInformationServicePrivate(QAspectEngine , m_aspectEngine(aspectEngine) , m_submissionStorage(nullptr) , m_frameId(0) + , m_commandDebugger(nullptr) { m_traceEnabled = qEnvironmentVariableIsSet("QT3D_TRACE_ENABLED"); if (m_traceEnabled) m_jobsStatTimer.start(); + + const bool commandServerEnabled = qEnvironmentVariableIsSet("QT3D_COMMAND_SERVER_ENABLED"); + if (commandServerEnabled) { + m_commandDebugger = new Debug::AspectCommandDebugger(q_func()); + m_commandDebugger->initialize(); + } } QSystemInformationServicePrivate::~QSystemInformationServicePrivate() = default; @@ -285,6 +293,12 @@ bool QSystemInformationService::isTraceEnabled() const return d->m_traceEnabled; } +bool QSystemInformationService::isCommandServerEnabled() const +{ + Q_D(const QSystemInformationService); + return d->m_commandDebugger != nullptr; +} + void QSystemInformationService::setTraceEnabled(bool traceEnabled) { Q_D(QSystemInformationService); @@ -344,6 +358,23 @@ void QSystemInformationService::writePreviousFrameTraces() d->writeFrameJobLogStats(); } +QVariant QSystemInformationService::executeCommand(const QString &command) +{ + Q_D(QSystemInformationService); + + if (command == QLatin1String("tracing on")) { + setTraceEnabled(true); + return {isTraceEnabled()}; + } + + if (command == QLatin1String("tracing off")) { + setTraceEnabled(false); + return {isTraceEnabled()}; + } + + return d->m_aspectEngine->executeCommand(command); +} + } QT_END_NAMESPACE diff --git a/src/core/services/qsysteminformationservice_p.h b/src/core/services/qsysteminformationservice_p.h index a524fbfd0..64e6c779e 100644 --- a/src/core/services/qsysteminformationservice_p.h +++ b/src/core/services/qsysteminformationservice_p.h @@ -67,10 +67,13 @@ class Q_3DCORESHARED_EXPORT QSystemInformationService : public QAbstractServiceP { Q_OBJECT Q_PROPERTY(bool traceEnabled READ isTraceEnabled WRITE setTraceEnabled NOTIFY traceEnabledChanged) + Q_PROPERTY(bool commandServerEnabled READ isCommandServerEnabled CONSTANT) public: QSystemInformationService(QAspectEngine *aspectEngine); bool isTraceEnabled() const; + bool isCommandServerEnabled() const; + void setTraceEnabled(bool traceEnabled); QStringList aspectNames() const; @@ -78,6 +81,8 @@ public: void writePreviousFrameTraces(); + QVariant executeCommand(const QString &command); + signals: void traceEnabledChanged(bool traceEnabled); diff --git a/src/core/services/qsysteminformationservice_p_p.h b/src/core/services/qsysteminformationservice_p_p.h index 00282c28a..222f4e1af 100644 --- a/src/core/services/qsysteminformationservice_p_p.h +++ b/src/core/services/qsysteminformationservice_p_p.h @@ -66,6 +66,10 @@ QT_BEGIN_NAMESPACE namespace Qt3DCore { +namespace Debug { +class AspectCommandDebugger; +} // Debug + union Q_3DCORE_PRIVATE_EXPORT JobId { JobId() : id(0L) { } @@ -115,6 +119,8 @@ public: QScopedPointer m_traceFile; quint32 m_frameId; + Debug::AspectCommandDebugger *m_commandDebugger; + Q_DECLARE_PUBLIC(QSystemInformationService) }; -- cgit v1.2.3