diff options
author | Benjamin Zeller <benjamin.zeller@canonical.com> | 2015-06-12 18:14:00 +0200 |
---|---|---|
committer | Benjamin Zeller <benjamin.zeller@canonical.com> | 2015-06-15 16:55:54 +0000 |
commit | 9321967d8423497a71d616e1eaacc2b5d027fa34 (patch) | |
tree | 3562bacee3c9cd57c0c545a5bd6216f0407999ab /src/plugins/qmlprofiler/localqmlprofilerrunner.cpp | |
parent | 5c054dd24a7813746ca8e8a8e486ab8d0e8f4979 (diff) |
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>
Diffstat (limited to 'src/plugins/qmlprofiler/localqmlprofilerrunner.cpp')
-rw-r--r-- | src/plugins/qmlprofiler/localqmlprofilerrunner.cpp | 69 |
1 files changed, 49 insertions, 20 deletions
diff --git a/src/plugins/qmlprofiler/localqmlprofilerrunner.cpp b/src/plugins/qmlprofiler/localqmlprofilerrunner.cpp index 02e2458c9a..4f9aab14df 100644 --- a/src/plugins/qmlprofiler/localqmlprofilerrunner.cpp +++ b/src/plugins/qmlprofiler/localqmlprofilerrunner.cpp @@ -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; -} |