diff options
author | Kai Koehne <kai.koehne@nokia.com> | 2011-05-04 16:50:24 +0200 |
---|---|---|
committer | Kai Koehne <kai.koehne@nokia.com> | 2011-05-04 17:17:32 +0200 |
commit | 6d174080e91f100f49d647e9388ef0d9a7188391 (patch) | |
tree | bd5fe62f3ee9a096ae5528cdf5f5c1ccae2c9dc5 /src | |
parent | 7b41c76d92f50373c77cbb5fa64284100a3a4431 (diff) | |
download | qt-creator-6d174080e91f100f49d647e9388ef0d9a7188391.tar.gz |
QmlProfiler: Factor out logic to run apps from the engine into a separate runner
Reviewed-by: Christiaan Janssen
Diffstat (limited to 'src')
-rw-r--r-- | src/plugins/qmlprofiler/abstractqmlprofilerrunner.h | 63 | ||||
-rw-r--r-- | src/plugins/qmlprofiler/localqmlprofilerrunner.cpp | 87 | ||||
-rw-r--r-- | src/plugins/qmlprofiler/localqmlprofilerrunner.h | 76 | ||||
-rw-r--r-- | src/plugins/qmlprofiler/qmlprofiler.pro | 7 | ||||
-rw-r--r-- | src/plugins/qmlprofiler/qmlprofilerengine.cpp | 84 | ||||
-rw-r--r-- | src/plugins/qmlprofiler/qmlprofilerengine.h | 3 | ||||
-rw-r--r-- | src/plugins/qmlprofiler/qmlprofilertool.cpp | 6 |
7 files changed, 286 insertions, 40 deletions
diff --git a/src/plugins/qmlprofiler/abstractqmlprofilerrunner.h b/src/plugins/qmlprofiler/abstractqmlprofilerrunner.h new file mode 100644 index 0000000000..056bb211bc --- /dev/null +++ b/src/plugins/qmlprofiler/abstractqmlprofilerrunner.h @@ -0,0 +1,63 @@ +/************************************************************************** +** +** This file is part of Qt Creator +** +** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies). +** +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** No Commercial Usage +** +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** 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, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +**************************************************************************/ + +#ifndef ABSTRACTQMLPROFILERRUNNER_H +#define ABSTRACTQMLPROFILERRUNNER_H + +#include <QtCore/QObject> +#include <utils/outputformat.h> + +namespace QmlProfiler { +namespace Internal { + +class AbstractQmlProfilerRunner : public QObject +{ + Q_OBJECT + +public: + explicit AbstractQmlProfilerRunner(QObject *parent = 0) : QObject(parent) { } + + virtual void start() = 0; + virtual void stop() = 0; + +signals: + void started(); + void stopped(); + + void appendMessage(const QString &message, Utils::OutputFormat format); +}; + +} // namespace Internal +} // namespace QmlProfiler + +#endif // ABSTRACTQMLPROFILERRUNNER_H diff --git a/src/plugins/qmlprofiler/localqmlprofilerrunner.cpp b/src/plugins/qmlprofiler/localqmlprofilerrunner.cpp new file mode 100644 index 0000000000..898c9cd315 --- /dev/null +++ b/src/plugins/qmlprofiler/localqmlprofilerrunner.cpp @@ -0,0 +1,87 @@ +/************************************************************************** +** +** This file is part of Qt Creator +** +** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies). +** +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** No Commercial Usage +** +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** 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, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +**************************************************************************/ + +#include "localqmlprofilerrunner.h" +#include "qmlprofilerplugin.h" + +using namespace QmlProfiler; +using namespace QmlProfiler::Internal; + +LocalQmlProfilerRunner::LocalQmlProfilerRunner(const Configuration &configuration, QObject *parent) : + AbstractQmlProfilerRunner(parent), + m_configuration(configuration) +{ + connect(&m_launcher, SIGNAL(appendMessage(QString,Utils::OutputFormat)), + this, SIGNAL(appendMessage(QString,Utils::OutputFormat))); +} + +void LocalQmlProfilerRunner::start() +{ + QString arguments = QString("-qmljsdebugger=port:%1,block").arg( + QString::number(m_configuration.port)); + + if (!m_configuration.executableArguments.isEmpty()) + arguments += QChar(' ') + m_configuration.executableArguments; + + if (QmlProfilerPlugin::debugOutput) + qWarning("QmlProfiler: Launching %s:%d", qPrintable(m_configuration.executable), + m_configuration.port); + + m_launcher.setWorkingDirectory(m_configuration.workingDirectory); + m_launcher.setEnvironment(m_configuration.environment); + connect(&m_launcher, SIGNAL(processExited(int)), this, SLOT(spontaneousStop(int))); + m_launcher.start(ProjectExplorer::ApplicationLauncher::Gui, m_configuration.executable, + arguments); + + emit started(); +} + +void LocalQmlProfilerRunner::spontaneousStop(int exitCode) +{ + if (QmlProfilerPlugin::debugOutput) + qWarning() << "QmlProfiler: Application exited (exit code" << exitCode << ")."; + + disconnect(&m_launcher, SIGNAL(processExited(int)), this, SLOT(spontaneousStop(int))); + + emit stopped(); +} + +void LocalQmlProfilerRunner::stop() +{ + if (QmlProfilerPlugin::debugOutput) + qWarning() << "QmlProfiler: Stopping application ..."; + + if (m_launcher.isRunning()) { + m_launcher.stop(); + } +} diff --git a/src/plugins/qmlprofiler/localqmlprofilerrunner.h b/src/plugins/qmlprofiler/localqmlprofilerrunner.h new file mode 100644 index 0000000000..6a4958e24d --- /dev/null +++ b/src/plugins/qmlprofiler/localqmlprofilerrunner.h @@ -0,0 +1,76 @@ +/************************************************************************** +** +** This file is part of Qt Creator +** +** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies). +** +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** No Commercial Usage +** +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** 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, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +**************************************************************************/ + +#ifndef LOCALQMLPROFILERRUNNER_H +#define LOCALQMLPROFILERRUNNER_H + +#include "abstractqmlprofilerrunner.h" + +#include <utils/environment.h> +#include <projectexplorer/applicationlauncher.h> + +namespace QmlProfiler { +namespace Internal { + +class LocalQmlProfilerRunner : public AbstractQmlProfilerRunner +{ + Q_OBJECT + Q_DISABLE_COPY(LocalQmlProfilerRunner) + +public: + struct Configuration { + QString executable; + QString executableArguments; + quint16 port; + QString workingDirectory; + Utils::Environment environment; + }; + + explicit LocalQmlProfilerRunner(const Configuration &configuration, QObject *parent = 0); + + // AbstractQmlProfilerRunner + virtual void start(); + virtual void stop(); + +private slots: + void spontaneousStop(int exitCode); + +private: + Configuration m_configuration; + ProjectExplorer::ApplicationLauncher m_launcher; +}; + +} // namespace Internal +} // namespace QmlProfiler + +#endif // LOCALQMLPROFILERRUNNER_H diff --git a/src/plugins/qmlprofiler/qmlprofiler.pro b/src/plugins/qmlprofiler/qmlprofiler.pro index d03d224675..bd8fbd623a 100644 --- a/src/plugins/qmlprofiler/qmlprofiler.pro +++ b/src/plugins/qmlprofiler/qmlprofiler.pro @@ -21,7 +21,8 @@ SOURCES += \ timelineview.cpp \ qmlprofilerattachdialog.cpp \ qmlprofilersummaryview.cpp \ - qmlprojectanalyzerruncontrolfactory.cpp + qmlprojectanalyzerruncontrolfactory.cpp \ + localqmlprofilerrunner.cpp HEADERS += \ qmlprofilerconstants.h \ @@ -33,7 +34,9 @@ HEADERS += \ timelineview.h \ qmlprofilerattachdialog.h \ qmlprofilersummaryview.h \ - qmlprojectanalyzerruncontrolfactory.h + qmlprojectanalyzerruncontrolfactory.h \ + abstractqmlprofilerrunner.h \ + localqmlprofilerrunner.h RESOURCES += \ qml/qml.qrc diff --git a/src/plugins/qmlprofiler/qmlprofilerengine.cpp b/src/plugins/qmlprofiler/qmlprofilerengine.cpp index 9a7b759977..d1addf8356 100644 --- a/src/plugins/qmlprofiler/qmlprofilerengine.cpp +++ b/src/plugins/qmlprofiler/qmlprofilerengine.cpp @@ -35,6 +35,7 @@ #include "qmlprofilerplugin.h" #include "qmlprofilertool.h" +#include "localqmlprofilerrunner.h" #include <analyzerbase/analyzermanager.h> #include <analyzerbase/analyzerconstants.h> @@ -42,6 +43,8 @@ #include <qmljsdebugclient/qdeclarativedebugclient_p.h> +#include <utils/qtcassert.h> + #include "timelineview.h" #include "tracewindow.h" @@ -55,24 +58,53 @@ using namespace QmlProfiler::Internal; + +// +// QmlProfilerEnginePrivate +// + class QmlProfilerEngine::QmlProfilerEnginePrivate { public: - QmlProfilerEnginePrivate(QmlProfilerEngine *qq) : q(qq) {} + QmlProfilerEnginePrivate(QmlProfilerEngine *qq) : q(qq), m_runner(0) {} ~QmlProfilerEnginePrivate() {} - void launchperfmonitor(); bool attach(const QString &address, uint port); + static AbstractQmlProfilerRunner *createRunner(const Analyzer::AnalyzerStartParameters &m_params, QObject *parent); QmlProfilerEngine *q; Analyzer::AnalyzerStartParameters m_params; - ProjectExplorer::ApplicationLauncher m_launcher; + AbstractQmlProfilerRunner *m_runner; bool m_running; bool m_fetchingData; bool m_delayedDelete; }; +AbstractQmlProfilerRunner * +QmlProfilerEngine::QmlProfilerEnginePrivate::createRunner(const Analyzer::AnalyzerStartParameters &m_params, QObject *parent) +{ + AbstractQmlProfilerRunner *runner = 0; + if (m_params.startMode == Analyzer::StartLocal) { + LocalQmlProfilerRunner::Configuration configuration; + configuration.executable = m_params.debuggee; + configuration.executableArguments = m_params.debuggeeArgs; + configuration.workingDirectory = m_params.workingDirectory; + configuration.environment = m_params.environment; + configuration.port = m_params.connParams.port; + + runner = new LocalQmlProfilerRunner(configuration, parent); + + } else if (m_params.startMode == Analyzer::StartRemote) { + + } + return runner; +} + +// +// QmlProfilerEngine +// + QmlProfilerEngine::QmlProfilerEngine(const Analyzer::AnalyzerStartParameters &sp, ProjectExplorer::RunConfiguration *runConfiguration) : IAnalyzerEngine(sp, runConfiguration) , d(new QmlProfilerEnginePrivate(this)) @@ -82,9 +114,6 @@ QmlProfilerEngine::QmlProfilerEngine(const Analyzer::AnalyzerStartParameters &sp d->m_running = false; d->m_fetchingData = false; d->m_delayedDelete = false; - - connect(&d->m_launcher, SIGNAL(appendMessage(QString,Utils::OutputFormat)), - this, SLOT(logApplicationMessage(QString,Utils::OutputFormat))); } QmlProfilerEngine::~QmlProfilerEngine() @@ -96,11 +125,19 @@ QmlProfilerEngine::~QmlProfilerEngine() void QmlProfilerEngine::start() { - d->launchperfmonitor(); + QTC_ASSERT(!d->m_runner, return); + d->m_runner = QmlProfilerEnginePrivate::createRunner(d->m_params, this); + QTC_ASSERT(d->m_runner, return); + + connect(d->m_runner, SIGNAL(started()), this, SIGNAL(processRunning())); + connect(d->m_runner, SIGNAL(stopped()), this, SLOT(stopped())); + connect(d->m_runner, SIGNAL(appendMessage(QString,Utils::OutputFormat)), + this, SLOT(logApplicationMessage(QString,Utils::OutputFormat))); + + d->m_runner->start(); + d->m_running = true; d->m_delayedDelete = false; - - emit processRunning(); } void QmlProfilerEngine::stop() @@ -109,15 +146,13 @@ void QmlProfilerEngine::stop() if (d->m_running) d->m_delayedDelete = true; emit stopRecording(); - } - else + } else { finishProcess(); + } } -void QmlProfilerEngine::spontaneousStop(int exitCode) +void QmlProfilerEngine::stopped() { - if (QmlProfilerPlugin::debugOutput) - qWarning() << "QmlProfiler: Application exited (exit code " << exitCode << ")."; d->m_running = false; Analyzer::AnalyzerManager::instance()->stopTool(); emit finished(); @@ -139,31 +174,12 @@ void QmlProfilerEngine::finishProcess() // user stop? if (d->m_running) { d->m_running = false; - disconnect(&d->m_launcher, SIGNAL(processExited(int)), this, SLOT(spontaneousStop(int))); - if (d->m_launcher.isRunning()) { - d->m_launcher.stop(); - } + d->m_runner->stop(); emit finished(); } } -void QmlProfilerEngine::QmlProfilerEnginePrivate::launchperfmonitor() -{ - QString arguments = QLatin1String("-qmljsdebugger=port:") + QString::number(m_params.connParams.port) - + QLatin1String(",block"); - if (!m_params.debuggeeArgs.isEmpty()) - arguments += QChar(' ') + m_params.debuggeeArgs; - - if (QmlProfilerPlugin::debugOutput) - qWarning("QmlProfiler: Launching %s:%d", qPrintable(m_params.displayName), m_params.connParams.port); - - m_launcher.setWorkingDirectory(m_params.workingDirectory); - m_launcher.setEnvironment(m_params.environment); - connect(&m_launcher, SIGNAL(processExited(int)), q, SLOT(spontaneousStop(int))); - m_launcher.start(ProjectExplorer::ApplicationLauncher::Gui, m_params.debuggee, arguments); -} - void QmlProfilerEngine::logApplicationMessage(const QString &msg, Utils::OutputFormat /*format*/) { qDebug() << "app: " << msg; diff --git a/src/plugins/qmlprofiler/qmlprofilerengine.h b/src/plugins/qmlprofiler/qmlprofilerengine.h index 9f0c337d2c..af3b454dd7 100644 --- a/src/plugins/qmlprofiler/qmlprofilerengine.h +++ b/src/plugins/qmlprofiler/qmlprofilerengine.h @@ -50,7 +50,6 @@ public: signals: void processRunning(); - //void finished(); void stopRecording(); public slots: @@ -58,7 +57,7 @@ public slots: void stop(); private slots: - void spontaneousStop(int exitCode); + void stopped(); void setFetchingData(bool); void dataReceived(); diff --git a/src/plugins/qmlprofiler/qmlprofilertool.cpp b/src/plugins/qmlprofiler/qmlprofilertool.cpp index b14800bcdf..ea4ce9725c 100644 --- a/src/plugins/qmlprofiler/qmlprofilertool.cpp +++ b/src/plugins/qmlprofiler/qmlprofilertool.cpp @@ -314,8 +314,10 @@ void QmlProfilerTool::disconnectClient() { // this might be actually be called indirectly by QDDConnectionPrivate::readyRead(), therefore allow // method to complete before deleting object - d->m_client->deleteLater(); - d->m_client = 0; + if (d->m_client) { + d->m_client->deleteLater(); + d->m_client = 0; + } } void QmlProfilerTool::startRecording() |