diff options
author | Ulf Hermann <ulf.hermann@theqtcompany.com> | 2015-11-30 20:05:43 +0100 |
---|---|---|
committer | Ulf Hermann <ulf.hermann@theqtcompany.com> | 2015-12-15 17:53:25 +0000 |
commit | 57f7fe3e1c92d11bb9e3bf2c87a11e4bc740e255 (patch) | |
tree | 1ea2225a00b8d591c58e59a5f530af3bcb55c8d7 /src | |
parent | 63dede74a386012f9bd5a6896c3fd6ef6ffa01cd (diff) |
Support debugging and profiling for pure QJSEngines
The engines will register themselves with the debug server whenever
they are created without a private object. The assumption is that we
get the latest possible registration like this. They try to deregister
in all dtors, but they check if a different engine has done the same
first.
Change-Id: Ife7d7532d1de2e4a6ee21d9f7e673fcdfff2387b
Reviewed-by: Simon Hausmann <simon.hausmann@theqtcompany.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/qml/jsapi/qjsengine.cpp | 24 | ||||
-rw-r--r-- | src/qml/jsapi/qjsengine_p.h | 3 | ||||
-rw-r--r-- | src/qml/qml/qqmlapplicationengine.cpp | 4 | ||||
-rw-r--r-- | src/qml/qml/qqmlengine.cpp | 10 |
4 files changed, 33 insertions, 8 deletions
diff --git a/src/qml/jsapi/qjsengine.cpp b/src/qml/jsapi/qjsengine.cpp index 5ccbccebad..80dce129c7 100644 --- a/src/qml/jsapi/qjsengine.cpp +++ b/src/qml/jsapi/qjsengine.cpp @@ -43,6 +43,7 @@ #include "private/qv4script_p.h" #include "private/qv4runtime_p.h" #include <private/qqmlbuiltinfunctions_p.h> +#include <private/qqmldebugconnector_p.h> #include <QtCore/qdatetime.h> #include <QtCore/qmetaobject.h> @@ -251,6 +252,7 @@ QJSEngine::QJSEngine() : QObject(*new QJSEnginePrivate, 0) , d(new QV8Engine(this)) { + QJSEnginePrivate::addToDebugServer(this); } /*! @@ -264,6 +266,7 @@ QJSEngine::QJSEngine(QObject *parent) : QObject(*new QJSEnginePrivate, parent) , d(new QV8Engine(this)) { + QJSEnginePrivate::addToDebugServer(this); } /*! @@ -284,6 +287,7 @@ QJSEngine::QJSEngine(QJSEnginePrivate &dd, QObject *parent) */ QJSEngine::~QJSEngine() { + QJSEnginePrivate::removeFromDebugServer(this); delete d; } @@ -671,6 +675,26 @@ QJSEnginePrivate::~QJSEnginePrivate() (*iter)->release(); } +void QJSEnginePrivate::addToDebugServer(QJSEngine *q) +{ + if (QCoreApplication::instance()->thread() != q->thread()) + return; + + QQmlDebugConnector *server = QQmlDebugConnector::instance(); + if (!server || server->hasEngine(q)) + return; + + server->open(); + server->addEngine(q); +} + +void QJSEnginePrivate::removeFromDebugServer(QJSEngine *q) +{ + QQmlDebugConnector *server = QQmlDebugConnector::instance(); + if (server && server->hasEngine(q)) + server->removeEngine(q); +} + QQmlPropertyCache *QJSEnginePrivate::createCache(const QMetaObject *mo) { if (!mo->superClass()) { diff --git a/src/qml/jsapi/qjsengine_p.h b/src/qml/jsapi/qjsengine_p.h index 8fdec08085..1fb8dc6fb2 100644 --- a/src/qml/jsapi/qjsengine_p.h +++ b/src/qml/jsapi/qjsengine_p.h @@ -70,6 +70,9 @@ public: QJSEnginePrivate() : mutex(QMutex::Recursive) {} ~QJSEnginePrivate(); + static void addToDebugServer(QJSEngine *q); + static void removeFromDebugServer(QJSEngine *q); + // Locker locks the QQmlEnginePrivate data structures for read and write, if necessary. // Currently, locking is only necessary if the threaded loader is running concurrently. If it is // either idle, or is running with the main thread blocked, no locking is necessary. This way diff --git a/src/qml/qml/qqmlapplicationengine.cpp b/src/qml/qml/qqmlapplicationengine.cpp index b2bf1939b0..4ab35e69e3 100644 --- a/src/qml/qml/qqmlapplicationengine.cpp +++ b/src/qml/qml/qqmlapplicationengine.cpp @@ -197,6 +197,7 @@ QQmlApplicationEngine::QQmlApplicationEngine(QObject *parent) { Q_D(QQmlApplicationEngine); d->init(); + QJSEnginePrivate::addToDebugServer(this); } /*! @@ -208,6 +209,7 @@ QQmlApplicationEngine::QQmlApplicationEngine(const QUrl &url, QObject *parent) { Q_D(QQmlApplicationEngine); d->init(); + QJSEnginePrivate::addToDebugServer(this); load(url); } @@ -224,6 +226,7 @@ QQmlApplicationEngine::QQmlApplicationEngine(const QString &filePath, QObject *p { Q_D(QQmlApplicationEngine); d->init(); + QJSEnginePrivate::addToDebugServer(this); load(QUrl::fromLocalFile(filePath)); } @@ -233,6 +236,7 @@ QQmlApplicationEngine::QQmlApplicationEngine(const QString &filePath, QObject *p QQmlApplicationEngine::~QQmlApplicationEngine() { Q_D(QQmlApplicationEngine); + QJSEnginePrivate::removeFromDebugServer(this); d->cleanUp();//Instantiated root objects must be deleted before the engine } diff --git a/src/qml/qml/qqmlengine.cpp b/src/qml/qml/qqmlengine.cpp index 2d3d8aa03c..b3636d1fa6 100644 --- a/src/qml/qml/qqmlengine.cpp +++ b/src/qml/qml/qqmlengine.cpp @@ -868,11 +868,6 @@ void QQmlEnginePrivate::init() v8engine()->setEngine(q); rootContext = new QQmlContext(q,true); - - if (QCoreApplication::instance()->thread() == q->thread() && QQmlDebugConnector::instance()) { - QQmlDebugConnector::instance()->open(); - QQmlDebugConnector::instance()->addEngine(q); - } } QQuickWorkerScriptEngine *QQmlEnginePrivate::getWorkerScriptEngine() @@ -924,6 +919,7 @@ QQmlEngine::QQmlEngine(QObject *parent) { Q_D(QQmlEngine); d->init(); + QJSEnginePrivate::addToDebugServer(this); } /*! @@ -948,9 +944,7 @@ QQmlEngine::QQmlEngine(QQmlEnginePrivate &dd, QObject *parent) QQmlEngine::~QQmlEngine() { Q_D(QQmlEngine); - QQmlDebugConnector *server = QQmlDebugConnector::instance(); - if (server) - server->removeEngine(this); + QJSEnginePrivate::removeFromDebugServer(this); d->typeLoader.invalidate(); |