forked from qt-creator/qt-creator
QmlProfiler: Make creation of local RunControls more flexible
In order for plugins to create a RunControl for locally running applications that do not use LocalApplicationRunConfiguration it is required to export an API that takes care of the internal setup. Also this removes the hard dependency on LocalApplicationRunConfiguration. We don't want to expose Internal classes in public API, so we have to make QmlProfiler::Internal::QmlProfilerRunControl and QmlProfiler::Internal::QmlProfilerStateManager public. Also, AbstractQmlProfilerRunner doesn't do anything useful and can be removed. Change-Id: I0403e5b17e14ac894addd818ad7b249c51a8ed8d Reviewed-by: hjk <hjk@theqtcompany.com> Reviewed-by: Benjamin Zeller <benjamin.zeller@canonical.com> Reviewed-by: Daniel Teske <daniel.teske@theqtcompany.com>
This commit is contained in:
@@ -32,31 +32,44 @@
|
||||
#include "qmlprofilerplugin.h"
|
||||
#include "qmlprofilerengine.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>
|
||||
#include <projectexplorer/devicesupport/idevice.h>
|
||||
#include <projectexplorer/kitinformation.h>
|
||||
#include <projectexplorer/target.h>
|
||||
|
||||
#include <QTcpServer>
|
||||
|
||||
using namespace QmlProfiler;
|
||||
using namespace QmlProfiler::Internal;
|
||||
using namespace ProjectExplorer;
|
||||
|
||||
LocalQmlProfilerRunner *LocalQmlProfilerRunner::createLocalRunner(
|
||||
Analyzer::AnalyzerRunControl *LocalQmlProfilerRunner::createLocalRunControl(
|
||||
RunConfiguration *runConfiguration,
|
||||
const Analyzer::AnalyzerStartParameters &sp,
|
||||
QString *errorMessage,
|
||||
QmlProfilerRunControl *engine)
|
||||
QString *errorMessage)
|
||||
{
|
||||
LocalApplicationRunConfiguration *larc =
|
||||
qobject_cast<LocalApplicationRunConfiguration *>(runConfiguration);
|
||||
QTC_ASSERT(larc, return 0);
|
||||
EnvironmentAspect *environment = runConfiguration->extraAspect<EnvironmentAspect>();
|
||||
QTC_ASSERT(environment, return 0);
|
||||
// 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);
|
||||
QmlProfilerRunControl *engine = qobject_cast<QmlProfilerRunControl *>(rc);
|
||||
if (!engine) {
|
||||
delete rc;
|
||||
return 0;
|
||||
}
|
||||
|
||||
Configuration conf;
|
||||
conf.executable = larc->executable();
|
||||
conf.executableArguments = larc->commandLineArguments();
|
||||
conf.workingDirectory = larc->workingDirectory();
|
||||
conf.environment = environment->environment();
|
||||
conf.executable = sp.debuggee;
|
||||
conf.executableArguments = sp.debuggeeArgs;
|
||||
conf.workingDirectory = sp.workingDirectory;
|
||||
conf.environment = sp.environment;
|
||||
|
||||
conf.port = sp.analyzerPort;
|
||||
|
||||
@@ -65,12 +78,33 @@ LocalQmlProfilerRunner *LocalQmlProfilerRunner::createLocalRunner(
|
||||
*errorMessage = tr("No executable file to launch.");
|
||||
return 0;
|
||||
}
|
||||
return new LocalQmlProfilerRunner(conf, engine);
|
||||
|
||||
LocalQmlProfilerRunner *runner = new LocalQmlProfilerRunner(conf, engine);
|
||||
|
||||
QObject::connect(runner, SIGNAL(stopped()), engine, SLOT(notifyRemoteFinished()));
|
||||
QObject::connect(runner, SIGNAL(appendMessage(QString,Utils::OutputFormat)),
|
||||
engine, SLOT(logApplicationMessage(QString,Utils::OutputFormat)));
|
||||
QObject::connect(engine, SIGNAL(starting(const Analyzer::AnalyzerRunControl*)), runner,
|
||||
SLOT(start()));
|
||||
QObject::connect(rc, SIGNAL(finished()), runner, SLOT(stop()));
|
||||
return rc;
|
||||
}
|
||||
|
||||
quint16 LocalQmlProfilerRunner::findFreePort(QString &host)
|
||||
{
|
||||
QTcpServer server;
|
||||
if (!server.listen(QHostAddress::LocalHost)
|
||||
&& !server.listen(QHostAddress::LocalHostIPv6)) {
|
||||
qWarning() << "Cannot open port on host for QML profiling.";
|
||||
return 0;
|
||||
}
|
||||
host = server.serverAddress().toString();
|
||||
return server.serverPort();
|
||||
}
|
||||
|
||||
LocalQmlProfilerRunner::LocalQmlProfilerRunner(const Configuration &configuration,
|
||||
QmlProfilerRunControl *engine) :
|
||||
AbstractQmlProfilerRunner(engine),
|
||||
QObject(engine),
|
||||
m_configuration(configuration),
|
||||
m_engine(engine)
|
||||
{
|
||||
@@ -132,8 +166,3 @@ void LocalQmlProfilerRunner::stop()
|
||||
if (m_launcher.isRunning())
|
||||
m_launcher.stop();
|
||||
}
|
||||
|
||||
quint16 LocalQmlProfilerRunner::debugPort() const
|
||||
{
|
||||
return m_configuration.port;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user