QmlProfiler: Use ApplicationLauncher instead of QProcess

This commit is contained in:
Kai Koehne
2011-04-14 17:14:26 +02:00
parent 20cb599b8c
commit 35493c454c
2 changed files with 32 additions and 63 deletions

View File

@@ -38,6 +38,7 @@
#include <analyzerbase/analyzermanager.h> #include <analyzerbase/analyzermanager.h>
#include <analyzerbase/analyzerconstants.h> #include <analyzerbase/analyzerconstants.h>
#include <projectexplorer/applicationlauncher.h>
#include <qmljsdebugclient/qdeclarativedebugclient_p.h> #include <qmljsdebugclient/qdeclarativedebugclient_p.h>
@@ -50,7 +51,6 @@
#include "canvas/qdeclarativecontext2d_p.h" #include "canvas/qdeclarativecontext2d_p.h"
#include "canvas/qdeclarativetiledcanvas_p.h" #include "canvas/qdeclarativetiledcanvas_p.h"
#include <QProcess>
using namespace QmlProfiler::Internal; using namespace QmlProfiler::Internal;
@@ -61,13 +61,13 @@ public:
QmlProfilerEnginePrivate(QmlProfilerEngine *qq) : q(qq) {} QmlProfilerEnginePrivate(QmlProfilerEngine *qq) : q(qq) {}
~QmlProfilerEnginePrivate() {} ~QmlProfilerEnginePrivate() {}
bool launchperfmonitor(); void launchperfmonitor();
bool attach(const QString &address, uint port); bool attach(const QString &address, uint port);
QmlProfilerEngine *q; QmlProfilerEngine *q;
Analyzer::AnalyzerStartParameters m_params; Analyzer::AnalyzerStartParameters m_params;
QProcess *m_process; ProjectExplorer::ApplicationLauncher m_launcher;
bool m_running; bool m_running;
bool m_fetchingData; bool m_fetchingData;
bool m_delayedDelete; bool m_delayedDelete;
@@ -78,10 +78,13 @@ QmlProfilerEngine::QmlProfilerEngine(const Analyzer::AnalyzerStartParameters &sp
, d(new QmlProfilerEnginePrivate(this)) , d(new QmlProfilerEnginePrivate(this))
{ {
d->m_params = sp; d->m_params = sp;
d->m_process = 0;
d->m_running = false; d->m_running = false;
d->m_fetchingData = false; d->m_fetchingData = false;
d->m_delayedDelete = false; d->m_delayedDelete = false;
connect(&d->m_launcher, SIGNAL(appendMessage(QString,ProjectExplorer::OutputFormat)),
this, SLOT(logApplicationMessage(QString,ProjectExplorer::OutputFormat)));
} }
QmlProfilerEngine::~QmlProfilerEngine() QmlProfilerEngine::~QmlProfilerEngine()
@@ -111,8 +114,10 @@ void QmlProfilerEngine::stop()
finishProcess(); finishProcess();
} }
void QmlProfilerEngine::spontaneousStop() void QmlProfilerEngine::spontaneousStop(int exitCode)
{ {
if (QmlProfilerPlugin::debugOutput)
qWarning() << "QmlProfiler: Application exited (exit code " << exitCode << ").";
d->m_running = false; d->m_running = false;
Analyzer::AnalyzerManager::instance()->stopTool(); Analyzer::AnalyzerManager::instance()->stopTool();
emit finished(); emit finished();
@@ -131,74 +136,34 @@ void QmlProfilerEngine::dataReceived() {
void QmlProfilerEngine::finishProcess() void QmlProfilerEngine::finishProcess()
{ {
// user stop?
if (d->m_running) { if (d->m_running) {
d->m_running = false; d->m_running = false;
if (d->m_process) { disconnect(&d->m_launcher, SIGNAL(processExited(int)), this, SLOT(spontaneousStop()));
disconnect(d->m_process,SIGNAL(finished(int)),this,SLOT(spontaneousStop())); if (d->m_launcher.isRunning()) {
if (d->m_process->state() == QProcess::Running) { d->m_launcher.stop();
d->m_process->terminate();
if (!d->m_process->waitForFinished(1000)) {
d->m_process->kill();
d->m_process->waitForFinished();
}
}
delete d->m_process;
d->m_process = 0;
} }
emit finished(); emit finished();
} }
} }
bool QmlProfilerEngine::QmlProfilerEnginePrivate::launchperfmonitor() void QmlProfilerEngine::QmlProfilerEnginePrivate::launchperfmonitor()
{ {
bool qtquick1 = false; QString arguments = m_params.debuggeeArgs;
arguments += QLatin1String("-qmljsdebugger=port:") + QString::number(m_params.connParams.port)
m_process = new QProcess(); + QLatin1String(",block");
QStringList arguments("-qmljsdebugger=port:" + QString::number(m_params.connParams.port) + ",block");
arguments.append(m_params.debuggeeArgs.split(" "));
if (QmlProfilerPlugin::debugOutput) if (QmlProfilerPlugin::debugOutput)
qWarning("QmlProfiler: Launching %s", qPrintable(m_params.displayName)); qWarning("QmlProfiler: Launching %s:%d", qPrintable(m_params.displayName), m_params.connParams.port);
if (qtquick1) { m_launcher.setWorkingDirectory(m_params.workingDirectory);
QProcessEnvironment env; m_launcher.setEnvironment(m_params.environment);
env.insert("QMLSCENE_IMPORT_NAME", "quick1"); connect(&m_launcher, SIGNAL(processExited(int)), q, SLOT(spontaneousStop(int)));
m_process->setProcessEnvironment(env); m_launcher.start(ProjectExplorer::ApplicationLauncher::Gui, m_params.debuggee, arguments);
}
m_process->setProcessChannelMode(QProcess::ForwardedChannels);
m_process->setWorkingDirectory(m_params.workingDirectory);
connect(m_process,SIGNAL(finished(int)),q,SLOT(spontaneousStop()));
m_process->start(m_params.debuggee, arguments);
if (!m_process->waitForStarted()) {
if (QmlProfilerPlugin::debugOutput)
qWarning("QmlProfiler: %s failed to start", qPrintable(m_params.displayName));
return false;
}
if (QmlProfilerPlugin::debugOutput)
qWarning("QmlProfiler: Connecting to %s:%d", qPrintable(m_params.connParams.host), m_params.connParams.port);
return true;
} }
void QmlProfilerEngine::logApplicationMessage(const QString &msg, ProjectExplorer::OutputFormat /*format*/)
{
qDebug() << "app: " << msg;
}

View File

@@ -35,6 +35,7 @@
#define QMLPROFILERENGINE_H #define QMLPROFILERENGINE_H
#include <analyzerbase/ianalyzerengine.h> #include <analyzerbase/ianalyzerengine.h>
#include <projectexplorer/outputformat.h>
namespace QmlProfiler { namespace QmlProfiler {
namespace Internal { namespace Internal {
@@ -55,11 +56,14 @@ signals:
public slots: public slots:
void start(); void start();
void stop(); void stop();
void spontaneousStop();
private slots:
void spontaneousStop(int exitCode);
void setFetchingData(bool); void setFetchingData(bool);
void dataReceived(); void dataReceived();
void finishProcess(); void finishProcess();
void logApplicationMessage(const QString &msg, ProjectExplorer::OutputFormat format);
private: private:
class QmlProfilerEnginePrivate; class QmlProfilerEnginePrivate;