QmlProfiler: Use a port from the device port range

Check for free ports from the range of device ports instead of
using a fixed port.

Change-Id: I30b2e141ae6bce1ddd90294d4b802e2c9943424b
Reviewed-by: Christiaan Janssen <christiaan.janssen@digia.com>
This commit is contained in:
Aurindam Jana
2013-04-17 11:10:45 +02:00
parent 53ce5340d6
commit cb4bfaf905
2 changed files with 49 additions and 25 deletions

View File

@@ -37,6 +37,9 @@
#include <debugger/debuggerrunconfigurationaspect.h> #include <debugger/debuggerrunconfigurationaspect.h>
#include <utils/qtcassert.h> #include <utils/qtcassert.h>
#include <coreplugin/helpmanager.h> #include <coreplugin/helpmanager.h>
#include <projectexplorer/projectexplorerconstants.h>
#include <projectexplorer/kitinformation.h>
#include <projectexplorer/target.h>
#include <qmlprojectmanager/qmlprojectrunconfiguration.h> #include <qmlprojectmanager/qmlprojectrunconfiguration.h>
#include <qmlprojectmanager/qmlprojectplugin.h> #include <qmlprojectmanager/qmlprojectplugin.h>
#include <projectexplorer/environmentaspect.h> #include <projectexplorer/environmentaspect.h>
@@ -44,6 +47,7 @@
#include <projectexplorer/localapplicationrunconfiguration.h> #include <projectexplorer/localapplicationrunconfiguration.h>
#include <qmldebug/qmloutputparser.h> #include <qmldebug/qmloutputparser.h>
#include <remotelinux/remotelinuxrunconfiguration.h> #include <remotelinux/remotelinuxrunconfiguration.h>
#include <utils/tcpportsgatherer.h>
#include <QMainWindow> #include <QMainWindow>
#include <QMessageBox> #include <QMessageBox>
@@ -91,32 +95,41 @@ QmlProfilerEngine::QmlProfilerEnginePrivate::createRunner(ProjectExplorer::RunCo
ProjectExplorer::EnvironmentAspect *environment ProjectExplorer::EnvironmentAspect *environment
= runConfiguration->extraAspect<ProjectExplorer::EnvironmentAspect>(); = runConfiguration->extraAspect<ProjectExplorer::EnvironmentAspect>();
QTC_ASSERT(environment, return 0); QTC_ASSERT(environment, return 0);
if (RemoteLinux::RemoteLinuxRunConfiguration *rmConfig =
qobject_cast<RemoteLinux::RemoteLinuxRunConfiguration *>(runConfiguration)) {
runner = new RemoteLinuxQmlProfilerRunner(rmConfig, parent);
} else {
LocalQmlProfilerRunner::Configuration conf;
if (QmlProjectManager::QmlProjectRunConfiguration *rc1 = if (QmlProjectManager::QmlProjectRunConfiguration *rc1 =
qobject_cast<QmlProjectManager::QmlProjectRunConfiguration *>(runConfiguration)) { qobject_cast<QmlProjectManager::QmlProjectRunConfiguration *>(runConfiguration)) {
// This is a "plain" .qmlproject. // This is a "plain" .qmlproject.
LocalQmlProfilerRunner::Configuration conf;
conf.executable = rc1->observerPath(); conf.executable = rc1->observerPath();
conf.executableArguments = rc1->viewerArguments(); conf.executableArguments = rc1->viewerArguments();
conf.workingDirectory = rc1->workingDirectory(); conf.workingDirectory = rc1->workingDirectory();
conf.environment = environment->environment(); conf.environment = environment->environment();
conf.port = debugger->qmlDebugServerPort();
runner = new LocalQmlProfilerRunner(conf, parent);
} else if (LocalApplicationRunConfiguration *rc2 = } else if (LocalApplicationRunConfiguration *rc2 =
qobject_cast<LocalApplicationRunConfiguration *>(runConfiguration)) { qobject_cast<LocalApplicationRunConfiguration *>(runConfiguration)) {
// FIXME: Check. // FIXME: Check.
LocalQmlProfilerRunner::Configuration conf;
conf.executable = rc2->executable(); conf.executable = rc2->executable();
conf.executableArguments = rc2->commandLineArguments(); conf.executableArguments = rc2->commandLineArguments();
conf.workingDirectory = rc2->workingDirectory(); conf.workingDirectory = rc2->workingDirectory();
conf.environment = environment->environment(); conf.environment = environment->environment();
conf.port = debugger->qmlDebugServerPort();
runner = new LocalQmlProfilerRunner(conf, parent);
} else if (RemoteLinux::RemoteLinuxRunConfiguration *rmConfig =
qobject_cast<RemoteLinux::RemoteLinuxRunConfiguration *>(runConfiguration)) {
runner = new RemoteLinuxQmlProfilerRunner(rmConfig, parent);
} else { } else {
QTC_CHECK(false); QTC_CHECK(false);
} }
const ProjectExplorer::IDevice::ConstPtr device =
ProjectExplorer::DeviceKitInformation::device(runConfiguration->target()->kit());
QTC_ASSERT(device->type() == ProjectExplorer::Constants::DESKTOP_DEVICE_TYPE, return 0);
Utils::TcpPortsGatherer portsGatherer;
portsGatherer.update(QAbstractSocket::UnknownNetworkLayerProtocol);
Utils::PortList portList = device->freePorts();
int freePort = portsGatherer.getNextFreePort(&portList);
if (freePort == -1)
return 0;
conf.port = freePort;
runner = new LocalQmlProfilerRunner(conf, parent);
}
return runner; return runner;
} }

View File

@@ -48,11 +48,13 @@
#include <utils/fancymainwindow.h> #include <utils/fancymainwindow.h>
#include <utils/fileinprojectfinder.h> #include <utils/fileinprojectfinder.h>
#include <utils/qtcassert.h> #include <utils/qtcassert.h>
#include <utils/tcpportsgatherer.h>
#include <projectexplorer/environmentaspect.h> #include <projectexplorer/environmentaspect.h>
#include <projectexplorer/projectexplorer.h> #include <projectexplorer/projectexplorer.h>
#include <projectexplorer/project.h> #include <projectexplorer/project.h>
#include <projectexplorer/target.h> #include <projectexplorer/target.h>
#include <projectexplorer/session.h> #include <projectexplorer/session.h>
#include <projectexplorer/kitinformation.h>
#include <projectexplorer/localapplicationrunconfiguration.h> #include <projectexplorer/localapplicationrunconfiguration.h>
#include <texteditor/itexteditor.h> #include <texteditor/itexteditor.h>
@@ -305,7 +307,6 @@ AnalyzerStartParameters QmlProfilerTool::createStartParameters(RunConfiguration
Debugger::DebuggerRunConfigurationAspect *debugger Debugger::DebuggerRunConfigurationAspect *debugger
= runConfiguration->extraAspect<Debugger::DebuggerRunConfigurationAspect>(); = runConfiguration->extraAspect<Debugger::DebuggerRunConfigurationAspect>();
QTC_ASSERT(debugger, return sp); QTC_ASSERT(debugger, return sp);
sp.startMode = StartQml; // FIXME: The parameter struct is not needed/not used.
// FIXME: This is only used to communicate the connParams settings. // FIXME: This is only used to communicate the connParams settings.
if (QmlProjectRunConfiguration *rc1 = if (QmlProjectRunConfiguration *rc1 =
@@ -318,7 +319,6 @@ AnalyzerStartParameters QmlProfilerTool::createStartParameters(RunConfiguration
sp.debuggeeArgs = rc1->viewerArguments(); sp.debuggeeArgs = rc1->viewerArguments();
sp.displayName = rc1->displayName(); sp.displayName = rc1->displayName();
sp.connParams.host = QLatin1String("localhost"); sp.connParams.host = QLatin1String("localhost");
sp.connParams.port = debugger->qmlDebugServerPort();
} else if (LocalApplicationRunConfiguration *rc2 = } else if (LocalApplicationRunConfiguration *rc2 =
qobject_cast<LocalApplicationRunConfiguration *>(runConfiguration)) { qobject_cast<LocalApplicationRunConfiguration *>(runConfiguration)) {
if (environment) if (environment)
@@ -328,7 +328,6 @@ AnalyzerStartParameters QmlProfilerTool::createStartParameters(RunConfiguration
sp.debuggeeArgs = rc2->commandLineArguments(); sp.debuggeeArgs = rc2->commandLineArguments();
sp.displayName = rc2->displayName(); sp.displayName = rc2->displayName();
sp.connParams.host = QLatin1String("localhost"); sp.connParams.host = QLatin1String("localhost");
sp.connParams.port = debugger->qmlDebugServerPort();
} else if (RemoteLinux::RemoteLinuxRunConfiguration *rc3 = } else if (RemoteLinux::RemoteLinuxRunConfiguration *rc3 =
qobject_cast<RemoteLinux::RemoteLinuxRunConfiguration *>(runConfiguration)) { qobject_cast<RemoteLinux::RemoteLinuxRunConfiguration *>(runConfiguration)) {
sp.debuggee = rc3->remoteExecutableFilePath(); sp.debuggee = rc3->remoteExecutableFilePath();
@@ -341,6 +340,18 @@ AnalyzerStartParameters QmlProfilerTool::createStartParameters(RunConfiguration
// What could that be? // What could that be?
QTC_ASSERT(false, return sp); QTC_ASSERT(false, return sp);
} }
const ProjectExplorer::IDevice::ConstPtr device =
ProjectExplorer::DeviceKitInformation::device(runConfiguration->target()->kit());
if (device->type() == ProjectExplorer::Constants::DESKTOP_DEVICE_TYPE) {
Utils::TcpPortsGatherer portsGatherer;
portsGatherer.update(QAbstractSocket::UnknownNetworkLayerProtocol);
Utils::PortList portList = device->freePorts();
int freePort = portsGatherer.getNextFreePort(&portList);
if (freePort == -1)
return sp;
sp.connParams.port = freePort;
}
sp.startMode = StartQml;
return sp; return sp;
} }