Commit 5dad96e3 authored by hjk's avatar hjk

QmlProfiler: Adapt QmlProfilerRunControlFactory to Analyzer changes

Change-Id: I8047cdb3fc65df2139c1a5770218c48e83ef5f5a
Reviewed-by: default avatarUlf Hermann <ulf.hermann@theqtcompany.com>
parent e214eda8
......@@ -27,9 +27,6 @@
#include "qmlprofilerplugin.h"
#include "qmlprofilerruncontrol.h"
#include <analyzerbase/analyzermanager.h>
#include <analyzerbase/analyzerruncontrol.h>
#include <analyzerbase/analyzerstartparameters.h>
#include <projectexplorer/runconfiguration.h>
#include <projectexplorer/localapplicationrunconfiguration.h>
#include <projectexplorer/environmentaspect.h>
......@@ -44,51 +41,6 @@
using namespace QmlProfiler;
using namespace ProjectExplorer;
Analyzer::AnalyzerRunControl *LocalQmlProfilerRunner::createLocalRunControl(
RunConfiguration *runConfiguration,
const Analyzer::AnalyzerStartParameters &sp,
QString *errorMessage)
{
// only desktop device is supported
const IDevice::ConstPtr device = DeviceKitInformation::device(
runConfiguration->target()->kit());
QTC_ASSERT(device->type() == ProjectExplorer::Constants::DESKTOP_DEVICE_TYPE, return 0);
Analyzer::AnalyzerRunControl *rc = Analyzer::AnalyzerManager::createRunControl(
sp, runConfiguration, ProjectExplorer::Constants::QML_PROFILER_RUN_MODE);
QmlProfilerRunControl *engine = qobject_cast<QmlProfilerRunControl *>(rc);
if (!engine) {
delete rc;
return 0;
}
Configuration conf;
conf.executable = sp.debuggee;
conf.executableArguments = sp.debuggeeArgs;
conf.workingDirectory = rc->workingDirectory();
conf.socket = sp.analyzerSocket;
if (EnvironmentAspect *environment = runConfiguration->extraAspect<EnvironmentAspect>())
conf.environment = environment->environment();
conf.port = sp.analyzerPort;
if (conf.executable.isEmpty()) {
if (errorMessage)
*errorMessage = tr("No executable file to launch.");
return 0;
}
LocalQmlProfilerRunner *runner = new LocalQmlProfilerRunner(conf, engine);
QObject::connect(runner, &LocalQmlProfilerRunner::stopped,
engine, &QmlProfilerRunControl::notifyRemoteFinished);
QObject::connect(runner, &LocalQmlProfilerRunner::appendMessage,
engine, &QmlProfilerRunControl::logApplicationMessage);
QObject::connect(engine, &Analyzer::AnalyzerRunControl::starting,
runner, &LocalQmlProfilerRunner::start);
QObject::connect(rc, &RunControl::finished, runner, &LocalQmlProfilerRunner::stop);
return rc;
}
QString LocalQmlProfilerRunner::findFreeSocket()
{
QTemporaryFile file;
......@@ -120,6 +72,14 @@ LocalQmlProfilerRunner::LocalQmlProfilerRunner(const Configuration &configuratio
{
connect(&m_launcher, &ApplicationLauncher::appendMessage,
this, &LocalQmlProfilerRunner::appendMessage);
connect(this, &LocalQmlProfilerRunner::stopped,
engine, &QmlProfilerRunControl::notifyRemoteFinished);
connect(this, &LocalQmlProfilerRunner::appendMessage,
engine, &QmlProfilerRunControl::logApplicationMessage);
connect(engine, &Analyzer::AnalyzerRunControl::starting,
this, &LocalQmlProfilerRunner::start);
connect(engine, &RunControl::finished,
this, &LocalQmlProfilerRunner::stop);
}
LocalQmlProfilerRunner::~LocalQmlProfilerRunner()
......
......@@ -30,12 +30,6 @@
#include <utils/environment.h>
#include <projectexplorer/applicationlauncher.h>
namespace ProjectExplorer { class RunConfiguration; }
namespace Analyzer {
class AnalyzerStartParameters;
class AnalyzerRunControl;
}
namespace QmlProfiler {
class QmlProfilerRunControl;
......@@ -53,29 +47,22 @@ public:
Utils::Environment environment;
};
static Analyzer::AnalyzerRunControl *createLocalRunControl(
ProjectExplorer::RunConfiguration *runConfiguration,
const Analyzer::AnalyzerStartParameters &sp,
QString *errorMessage);
LocalQmlProfilerRunner(const Configuration &configuration, QmlProfilerRunControl *engine);
~LocalQmlProfilerRunner();
static quint16 findFreePort(QString &host);
static QString findFreeSocket();
~LocalQmlProfilerRunner();
signals:
void started();
void stopped();
void appendMessage(const QString &message, Utils::OutputFormat format);
private slots:
private:
void spontaneousStop(int exitCode, QProcess::ExitStatus status);
void start();
void stop();
private:
LocalQmlProfilerRunner(const Configuration &configuration, QmlProfilerRunControl *engine);
Configuration m_configuration;
ProjectExplorer::ApplicationLauncher m_launcher;
QmlProfilerRunControl *m_engine;
......
......@@ -54,9 +54,9 @@ bool QmlProfilerPlugin::initialize(const QStringList &arguments, QString *errorS
auto tool = new QmlProfilerTool(this);
auto widgetCreator = [tool] { return tool->createWidgets(); };
auto runControlCreator = [tool](const AnalyzerStartParameters &sp,
auto runControlCreator = [tool](const AnalyzerStartParameters &,
ProjectExplorer::RunConfiguration *runConfiguration, Core::Id) {
return tool->createRunControl(sp, runConfiguration);
return tool->createRunControl(runConfiguration);
};
AnalyzerAction *action = 0;
......
......@@ -26,6 +26,7 @@
#include "qmlprofilerruncontrol.h"
#include "localqmlprofilerrunner.h"
#include "qmlprofilertool.h"
#include <analyzerbase/analyzermanager.h>
#include <coreplugin/icore.h>
......@@ -61,6 +62,7 @@ namespace QmlProfiler {
class QmlProfilerRunControl::QmlProfilerRunControlPrivate
{
public:
Internal::QmlProfilerTool *m_tool = 0;
QmlProfilerStateManager *m_profilerState = 0;
QTimer m_noDebugOutputTimer;
QmlDebug::QmlOutputParser m_outputParser;
......@@ -71,10 +73,12 @@ public:
// QmlProfilerRunControl
//
QmlProfilerRunControl::QmlProfilerRunControl(RunConfiguration *runConfiguration)
QmlProfilerRunControl::QmlProfilerRunControl(RunConfiguration *runConfiguration,
Internal::QmlProfilerTool *tool)
: AnalyzerRunControl(runConfiguration, ProjectExplorer::Constants::QML_PROFILER_RUN_MODE)
, d(new QmlProfilerRunControlPrivate)
{
d->m_tool = tool;
// Only wait 4 seconds for the 'Waiting for connection' on application output, then just try to connect
// (application output might be redirected / blocked)
d->m_noDebugOutputTimer.setSingleShot(true);
......@@ -248,6 +252,11 @@ void QmlProfilerRunControl::registerProfilerStateManager( QmlProfilerStateManage
this, &QmlProfilerRunControl::profilerStateChanged);
}
void QmlProfilerRunControl::finalizeSetup()
{
d->m_tool->finalizeRunControl(this);
}
void QmlProfilerRunControl::profilerStateChanged()
{
switch (d->m_profilerState->currentState()) {
......
......@@ -33,15 +33,19 @@
namespace QmlProfiler {
namespace Internal { class QmlProfilerTool; }
class QmlProfilerRunControl : public Analyzer::AnalyzerRunControl
{
Q_OBJECT
public:
QmlProfilerRunControl(ProjectExplorer::RunConfiguration *runConfiguration);
QmlProfilerRunControl(ProjectExplorer::RunConfiguration *runConfiguration,
Internal::QmlProfilerTool *tool);
~QmlProfilerRunControl();
void registerProfilerStateManager( QmlProfilerStateManager *profilerState );
void finalizeSetup();
void notifyRemoteSetupDone(quint16 port);
StopResult stop();
......
......@@ -29,6 +29,8 @@
#include "qmlprofilerrunconfigurationaspect.h"
#include <analyzerbase/ianalyzertool.h>
#include <analyzerbase/analyzerruncontrol.h>
#include <analyzerbase/analyzermanager.h>
#include <debugger/debuggerrunconfigurationaspect.h>
......@@ -61,38 +63,60 @@ bool QmlProfilerRunControlFactory::canRun(RunConfiguration *runConfiguration, Co
&& (qobject_cast<LocalApplicationRunConfiguration *>(runConfiguration));
}
static AnalyzerStartParameters createQmlProfilerStartParameters(RunConfiguration *runConfiguration)
RunControl *QmlProfilerRunControlFactory::create(RunConfiguration *runConfiguration, Core::Id mode, QString *errorMessage)
{
AnalyzerStartParameters sp;
QTC_ASSERT(canRun(runConfiguration, mode), return 0);
Kit *kit = runConfiguration->target()->kit();
// FIXME: This is only used to communicate the connParams settings.
auto rc = qobject_cast<LocalApplicationRunConfiguration *>(runConfiguration);
QTC_ASSERT(rc, return sp);
sp.debuggee = rc->executable();
sp.debuggeeArgs = rc->commandLineArguments();
const QtSupport::BaseQtVersion *version =
QtSupport::QtKitInformation::qtVersion(runConfiguration->target()->kit());
auto localRunConfiguration = qobject_cast<LocalApplicationRunConfiguration *>(runConfiguration);
QTC_ASSERT(localRunConfiguration, return 0);
AnalyzerRunnable runnable;
runnable.debuggee = localRunConfiguration->executable();
runnable.debuggeeArgs = localRunConfiguration->commandLineArguments();
AnalyzerConnection connection;
const QtSupport::BaseQtVersion *version = QtSupport::QtKitInformation::qtVersion(kit);
if (version) {
QtSupport::QtVersionNumber versionNumber = version->qtVersion();
if (versionNumber.majorVersion >= 5 && versionNumber.minorVersion >= 6)
sp.analyzerSocket = LocalQmlProfilerRunner::findFreeSocket();
connection.analyzerSocket = LocalQmlProfilerRunner::findFreeSocket();
else
sp.analyzerPort = LocalQmlProfilerRunner::findFreePort(sp.analyzerHost);
connection.analyzerPort = LocalQmlProfilerRunner::findFreePort(connection.analyzerHost);
} else {
qWarning() << "Running QML profiler on Kit without Qt version??";
sp.analyzerPort = LocalQmlProfilerRunner::findFreePort(sp.analyzerHost);
connection.analyzerPort = LocalQmlProfilerRunner::findFreePort(connection.analyzerHost);
}
return sp;
}
RunControl *QmlProfilerRunControlFactory::create(RunConfiguration *runConfiguration, Core::Id mode, QString *errorMessage)
{
QTC_ASSERT(canRun(runConfiguration, mode), return 0);
// only desktop device is supported
const IDevice::ConstPtr device = DeviceKitInformation::device(kit);
QTC_ASSERT(device->type() == ProjectExplorer::Constants::DESKTOP_DEVICE_TYPE, return 0);
auto runControl = qobject_cast<QmlProfilerRunControl *>
(AnalyzerManager::createRunControl(runConfiguration, mode));
QTC_ASSERT(runControl, return 0);
runControl->setRunnable(runnable);
runControl->setConnection(connection);
runControl->finalizeSetup();
LocalQmlProfilerRunner::Configuration conf;
conf.executable = runnable.debuggee;
conf.executableArguments = runnable.debuggeeArgs;
conf.workingDirectory = runControl->workingDirectory();
conf.socket = connection.analyzerSocket;
if (EnvironmentAspect *environment = runConfiguration->extraAspect<EnvironmentAspect>())
conf.environment = environment->environment();
conf.port = connection.analyzerPort;
if (conf.executable.isEmpty()) {
if (errorMessage)
*errorMessage = tr("No executable file to launch.");
return 0;
}
AnalyzerStartParameters sp = createQmlProfilerStartParameters(runConfiguration);
return LocalQmlProfilerRunner::createLocalRunControl(runConfiguration, sp, errorMessage);
(void) new LocalQmlProfilerRunner(conf, runControl);
return runControl;
}
ProjectExplorer::IRunConfigurationAspect *
......
......@@ -201,8 +201,7 @@ static QString sysroot(RunConfiguration *runConfig)
return QString();
}
AnalyzerRunControl *QmlProfilerTool::createRunControl(const AnalyzerStartParameters &sp,
RunConfiguration *runConfiguration)
AnalyzerRunControl *QmlProfilerTool::createRunControl(RunConfiguration *runConfiguration)
{
QmlProfilerRunConfigurationAspect *aspect = static_cast<QmlProfilerRunConfigurationAspect *>(
runConfiguration->extraAspect(Constants::SETTINGS));
......@@ -215,22 +214,25 @@ AnalyzerRunControl *QmlProfilerTool::createRunControl(const AnalyzerStartParamet
settings->flushInterval() : 0);
d->m_profilerConnections->setAggregateTraces(settings->aggregateTraces());
QmlProfilerRunControl *engine = new QmlProfilerRunControl(runConfiguration);
engine->setRunnable(AnalyzerRunnable(sp));
engine->setConnection(AnalyzerConnection(sp));
return new QmlProfilerRunControl(runConfiguration, this);
}
engine->registerProfilerStateManager(d->m_profilerState);
void QmlProfilerTool::finalizeRunControl(QmlProfilerRunControl *runControl)
{
runControl->registerProfilerStateManager(d->m_profilerState);
// FIXME: Check that there's something sensible in sp.connParams
if (!sp.analyzerSocket.isEmpty())
d->m_profilerConnections->setLocalSocket(sp.analyzerSocket);
auto &connection = runControl->connection();
if (!connection.analyzerSocket.isEmpty())
d->m_profilerConnections->setLocalSocket(connection.analyzerSocket);
else
d->m_profilerConnections->setTcpConnection(sp.analyzerHost, sp.analyzerPort);
d->m_profilerConnections->setTcpConnection(connection.analyzerHost, connection.analyzerPort);
//
// Initialize m_projectFinder
//
RunConfiguration *runConfiguration = runControl->runConfiguration();
QString projectDirectory;
if (runConfiguration) {
Project *project = runConfiguration->target()->project();
......@@ -239,13 +241,11 @@ AnalyzerRunControl *QmlProfilerTool::createRunControl(const AnalyzerStartParamet
populateFileFinder(projectDirectory, sysroot(runConfiguration));
if (sp.analyzerSocket.isEmpty())
connect(engine, &QmlProfilerRunControl::processRunning,
if (connection.analyzerSocket.isEmpty())
connect(runControl, &QmlProfilerRunControl::processRunning,
d->m_profilerConnections, &QmlProfilerClientManager::connectTcpClient);
connect(d->m_profilerConnections, &QmlProfilerClientManager::connectionFailed,
engine, &QmlProfilerRunControl::cancelProcess);
return engine;
runControl, &QmlProfilerRunControl::cancelProcess);
}
QWidget *QmlProfilerTool::createWidgets()
......@@ -516,17 +516,20 @@ void QmlProfilerTool::startRemoteTool()
settings->setValue(QLatin1String("AnalyzerQmlAttachDialog/port"), port);
}
AnalyzerStartParameters sp;
AnalyzerConnection connection;
IDevice::ConstPtr device = DeviceKitInformation::device(kit);
if (device) {
sp.connParams = device->sshParameters();
sp.analyzerHost = device->qmlProfilerHost();
connection.connParams = device->sshParameters();
connection.analyzerHost = device->qmlProfilerHost();
}
sp.analyzerPort = port;
connection.analyzerPort = port;
auto runControl = qobject_cast<QmlProfilerRunControl *>(createRunControl(0));
runControl->setConnection(connection);
runControl->finalizeSetup();
AnalyzerRunControl *rc = createRunControl(sp, 0);
ProjectExplorerPlugin::startRunControl(rc, ProjectExplorer::Constants::QML_PROFILER_RUN_MODE);
ProjectExplorerPlugin::startRunControl(runControl, ProjectExplorer::Constants::QML_PROFILER_RUN_MODE);
}
void QmlProfilerTool::logState(const QString &msg)
......
......@@ -38,6 +38,9 @@ class QMessageBox;
QT_END_NAMESPACE
namespace QmlProfiler {
class QmlProfilerRunControl;
namespace Internal {
class QMLPROFILER_EXPORT QmlProfilerTool : public QObject
......@@ -48,8 +51,8 @@ public:
explicit QmlProfilerTool(QObject *parent);
~QmlProfilerTool();
Analyzer::AnalyzerRunControl *createRunControl(const Analyzer::AnalyzerStartParameters &sp,
ProjectExplorer::RunConfiguration *runConfiguration = 0);
Analyzer::AnalyzerRunControl *createRunControl(ProjectExplorer::RunConfiguration *runConfiguration = 0);
void finalizeRunControl(QmlProfilerRunControl *runControl);
QWidget *createWidgets();
bool prepareTool();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment