Make sure that profiling can only be started if debugging is enabled.
authorUlf Hermann <ulf.hermann@digia.com>
Wed, 15 Jan 2014 11:30:36 +0000 (12:30 +0100)
committerThe Qt Project <gerrit-noreply@qt-project.org>
Wed, 15 Jan 2014 13:09:50 +0000 (14:09 +0100)
Enabling the profiler doesn't make much sense if there is no debug
service as the messages can't be sent anywhere then. Furthermore, the
profiler instance is only properly initialized if debugging is enabled
and thus enabling profiling without debugging being enabled can cause
problems.

Change-Id: I784a110126d45a9a2bc9d9e14d9a22e2980c3a42
Reviewed-by: Kai Koehne <kai.koehne@digia.com>
src/qml/debugger/qqmlprofilerservice.cpp
src/qml/qml/v8/qqmlbuiltinfunctions.cpp
tests/auto/qml/debugger/qqmlprofilerservice/data/controlFromJS.qml [new file with mode: 0644]
tests/auto/qml/debugger/qqmlprofilerservice/qqmlprofilerservice.pro
tests/auto/qml/debugger/qqmlprofilerservice/tst_qqmlprofilerservice.cpp
tests/auto/qml/qqmlconsole/tst_qqmlconsole.cpp

index 3c066bd..af2aea2 100644 (file)
@@ -178,7 +178,7 @@ void QQmlProfilerService::sendProfilingData()
 bool QQmlProfilerService::startProfilingImpl()
 {
     bool success = false;
-    if (!profilingEnabled()) {
+    if (QQmlDebugService::isDebuggingEnabled() && !profilingEnabled()) {
         setProfilingEnabled(true);
         sendStartedProfilingMessageImpl();
         success = true;
index 0409b92..67b7e78 100644 (file)
@@ -1432,7 +1432,9 @@ QV4::ReturnedValue ConsoleObject::method_profile(CallContext *ctx)
     const QByteArray baSource = frame.source.toUtf8();
     const QByteArray baFunction = frame.function.toUtf8();
     QMessageLogger logger(baSource.constData(), frame.line, baFunction.constData());
-    if (QQmlProfilerService::startProfiling()) {
+    if (!QQmlDebugService::isDebuggingEnabled()) {
+        logger.warning("Cannot start profiling because debug service is disabled. Start with -qmljsdebugger=port:XXXXX.");
+    } else if (QQmlProfilerService::startProfiling()) {
         QV8ProfilerService::instance()->startProfiling(title);
 
         logger.debug("Profiling started.");
diff --git a/tests/auto/qml/debugger/qqmlprofilerservice/data/controlFromJS.qml b/tests/auto/qml/debugger/qqmlprofilerservice/data/controlFromJS.qml
new file mode 100644 (file)
index 0000000..7bcabc3
--- /dev/null
@@ -0,0 +1,68 @@
+/****************************************************************************
+**
+** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the test suite of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and Digia.  For licensing terms and
+** conditions see http://qt.digia.com/licensing.  For further information
+** use the contact form at http://qt.digia.com/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file.  Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Digia gives you certain additional
+** rights.  These rights are described in the Digia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file.  Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+import QtQuick 2.0
+
+Rectangle {
+    Timer {
+        running: true
+        interval: 1
+        onTriggered: {
+            console.profile();
+            stopTimer.start();
+        }
+    }
+
+    Timer {
+        id: stopTimer
+        interval: 1000
+        onTriggered: {
+            console.profileEnd();
+            endTimer.start();
+        }
+    }
+
+    Timer {
+        id: endTimer
+        interval: 1000
+        onTriggered: Qt.quit();
+    }
+}
index b2b325d..a83927e 100644 (file)
@@ -14,4 +14,5 @@ QT += core qml testlib gui-private
 DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0
 
 OTHER_FILES += \
-    data/pixmapCacheTest.qml
+    data/pixmapCacheTest.qml \
+    data/controlFromJS.qml
index 929b079..acbc628 100644 (file)
@@ -180,6 +180,7 @@ private slots:
     void pixmapCacheData();
     void scenegraphData();
     void profileOnExit();
+    void controlFromJS();
 };
 
 void QQmlProfilerClient::messageReceived(const QByteArray &message)
@@ -494,6 +495,24 @@ void tst_QQmlProfilerService::profileOnExit()
     QCOMPARE(m_client->traceMessages.last().detailType, (int)QQmlProfilerClient::EndTrace);
 }
 
+void tst_QQmlProfilerService::controlFromJS()
+{
+    connect(true, "controlFromJS.qml");
+    QVERIFY(m_client);
+    QTRY_COMPARE(m_client->state(), QQmlDebugClient::Enabled);
+
+    m_client->setTraceState(false);
+    QVERIFY2(QQmlDebugTest::waitForSignal(m_client, SIGNAL(complete())), "No trace received in time.");
+
+    // must start with "StartTrace"
+    QCOMPARE(m_client->traceMessages.first().messageType, (int)QQmlProfilerClient::Event);
+    QCOMPARE(m_client->traceMessages.first().detailType, (int)QQmlProfilerClient::StartTrace);
+
+    // must end with "EndTrace"
+    QCOMPARE(m_client->traceMessages.last().messageType, (int)QQmlProfilerClient::Event);
+    QCOMPARE(m_client->traceMessages.last().detailType, (int)QQmlProfilerClient::EndTrace);
+}
+
 QTEST_MAIN(tst_QQmlProfilerService)
 
 #include "tst_qqmlprofilerservice.moc"
index e6f31dc..a37d705 100644 (file)
@@ -115,8 +115,8 @@ void tst_qqmlconsole::profiling()
     QUrl testUrl = testFileUrl("profiling.qml");
 
     // profiling()
-    QTest::ignoreMessage(QtDebugMsg, "Profiling started.");
-    QTest::ignoreMessage(QtDebugMsg, "Profiling ended.");
+    QTest::ignoreMessage(QtWarningMsg, "Cannot start profiling because debug service is disabled. Start with -qmljsdebugger=port:XXXXX.");
+    QTest::ignoreMessage(QtWarningMsg, "Profiling was not started.");
 
     QQmlComponent component(&engine, testUrl);
     QObject *object = component.create();