From cb4bfaf905a6db608bc3a4aeeef2c34979b60c81 Mon Sep 17 00:00:00 2001 From: Aurindam Jana Date: Wed, 17 Apr 2013 11:10:45 +0200 Subject: [PATCH] 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 --- src/plugins/qmlprofiler/qmlprofilerengine.cpp | 57 ++++++++++++------- src/plugins/qmlprofiler/qmlprofilertool.cpp | 17 +++++- 2 files changed, 49 insertions(+), 25 deletions(-) diff --git a/src/plugins/qmlprofiler/qmlprofilerengine.cpp b/src/plugins/qmlprofiler/qmlprofilerengine.cpp index b93e1e79160..7d06a40ed3a 100644 --- a/src/plugins/qmlprofiler/qmlprofilerengine.cpp +++ b/src/plugins/qmlprofiler/qmlprofilerengine.cpp @@ -37,6 +37,9 @@ #include #include #include +#include +#include +#include #include #include #include @@ -44,6 +47,7 @@ #include #include #include +#include #include #include @@ -91,31 +95,40 @@ QmlProfilerEngine::QmlProfilerEnginePrivate::createRunner(ProjectExplorer::RunCo ProjectExplorer::EnvironmentAspect *environment = runConfiguration->extraAspect(); QTC_ASSERT(environment, return 0); - if (QmlProjectManager::QmlProjectRunConfiguration *rc1 = - qobject_cast(runConfiguration)) { - // This is a "plain" .qmlproject. - LocalQmlProfilerRunner::Configuration conf; - conf.executable = rc1->observerPath(); - conf.executableArguments = rc1->viewerArguments(); - conf.workingDirectory = rc1->workingDirectory(); - conf.environment = environment->environment(); - conf.port = debugger->qmlDebugServerPort(); - runner = new LocalQmlProfilerRunner(conf, parent); - } else if (LocalApplicationRunConfiguration *rc2 = - qobject_cast(runConfiguration)) { - // FIXME: Check. - LocalQmlProfilerRunner::Configuration conf; - conf.executable = rc2->executable(); - conf.executableArguments = rc2->commandLineArguments(); - conf.workingDirectory = rc2->workingDirectory(); - conf.environment = environment->environment(); - conf.port = debugger->qmlDebugServerPort(); - runner = new LocalQmlProfilerRunner(conf, parent); - } else if (RemoteLinux::RemoteLinuxRunConfiguration *rmConfig = + + if (RemoteLinux::RemoteLinuxRunConfiguration *rmConfig = qobject_cast(runConfiguration)) { runner = new RemoteLinuxQmlProfilerRunner(rmConfig, parent); } else { - QTC_CHECK(false); + LocalQmlProfilerRunner::Configuration conf; + if (QmlProjectManager::QmlProjectRunConfiguration *rc1 = + qobject_cast(runConfiguration)) { + // This is a "plain" .qmlproject. + conf.executable = rc1->observerPath(); + conf.executableArguments = rc1->viewerArguments(); + conf.workingDirectory = rc1->workingDirectory(); + conf.environment = environment->environment(); + } else if (LocalApplicationRunConfiguration *rc2 = + qobject_cast(runConfiguration)) { + // FIXME: Check. + conf.executable = rc2->executable(); + conf.executableArguments = rc2->commandLineArguments(); + conf.workingDirectory = rc2->workingDirectory(); + conf.environment = environment->environment(); + } else { + 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; } diff --git a/src/plugins/qmlprofiler/qmlprofilertool.cpp b/src/plugins/qmlprofiler/qmlprofilertool.cpp index 5eda4328344..b50fb1f857a 100644 --- a/src/plugins/qmlprofiler/qmlprofilertool.cpp +++ b/src/plugins/qmlprofiler/qmlprofilertool.cpp @@ -48,11 +48,13 @@ #include #include #include +#include #include #include #include #include #include +#include #include #include @@ -305,7 +307,6 @@ AnalyzerStartParameters QmlProfilerTool::createStartParameters(RunConfiguration Debugger::DebuggerRunConfigurationAspect *debugger = runConfiguration->extraAspect(); 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. if (QmlProjectRunConfiguration *rc1 = @@ -318,7 +319,6 @@ AnalyzerStartParameters QmlProfilerTool::createStartParameters(RunConfiguration sp.debuggeeArgs = rc1->viewerArguments(); sp.displayName = rc1->displayName(); sp.connParams.host = QLatin1String("localhost"); - sp.connParams.port = debugger->qmlDebugServerPort(); } else if (LocalApplicationRunConfiguration *rc2 = qobject_cast(runConfiguration)) { if (environment) @@ -328,7 +328,6 @@ AnalyzerStartParameters QmlProfilerTool::createStartParameters(RunConfiguration sp.debuggeeArgs = rc2->commandLineArguments(); sp.displayName = rc2->displayName(); sp.connParams.host = QLatin1String("localhost"); - sp.connParams.port = debugger->qmlDebugServerPort(); } else if (RemoteLinux::RemoteLinuxRunConfiguration *rc3 = qobject_cast(runConfiguration)) { sp.debuggee = rc3->remoteExecutableFilePath(); @@ -341,6 +340,18 @@ AnalyzerStartParameters QmlProfilerTool::createStartParameters(RunConfiguration // What could that be? 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; }