QmlProfiler: Inline LocalQmlProfilerSupport

Task-number: QTCREATORBUG-29168
Change-Id: I991529d42bbe5b75b3a0bc13baf7c64005d9e1bb
Reviewed-by: hjk <hjk@qt.io>
This commit is contained in:
Jarek Kobus
2024-11-20 17:59:19 +01:00
parent 0316d92b47
commit 2092b7d80c
3 changed files with 19 additions and 68 deletions

View File

@@ -142,45 +142,20 @@ void QmlProfilerRunner::profilerStateChanged()
}
}
//
// LocalQmlProfilerSupport
//
static QUrl localServerUrl(RunControl *runControl)
RunWorker *createLocalQmlProfilerWorker(RunControl *runControl)
{
QUrl serverUrl;
Kit *kit = runControl->kit();
const QtSupport::QtVersion *version = QtSupport::QtKitAspect::qtVersion(kit);
if (version) {
if (version->qtVersion() >= QVersionNumber(5, 6, 0))
serverUrl = Utils::urlFromLocalSocket();
else
serverUrl = Utils::urlFromLocalHostAndFreePort();
} else {
qWarning("Running QML profiler on Kit without Qt version?");
serverUrl = Utils::urlFromLocalHostAndFreePort();
}
return serverUrl;
}
auto worker = new SimpleTargetRunner(runControl);
LocalQmlProfilerSupport::LocalQmlProfilerSupport(RunControl *runControl)
: LocalQmlProfilerSupport(runControl, localServerUrl(runControl))
{
}
LocalQmlProfilerSupport::LocalQmlProfilerSupport(RunControl *runControl, const QUrl &serverUrl)
: SimpleTargetRunner(runControl)
{
setId("LocalQmlProfilerSupport");
worker->setId("LocalQmlProfilerSupport");
auto profiler = new QmlProfilerRunner(runControl);
addStopDependency(profiler);
worker->addStopDependency(profiler);
// We need to open the local server before the application tries to connect.
// In the TCP case, it doesn't hurt either to start the profiler before.
addStartDependency(profiler);
worker->addStartDependency(profiler);
setStartModifier([this, runControl, serverUrl] {
worker->setStartModifier([worker, runControl] {
QUrl serverUrl = runControl->qmlChannel();
QString code;
@@ -192,16 +167,17 @@ LocalQmlProfilerSupport::LocalQmlProfilerSupport(RunControl *runControl, const Q
QTC_CHECK(false);
QString arguments = Utils::ProcessArgs::quoteArg(
qmlDebugCommandLineArguments(QmlProfilerServices, code, true));
qmlDebugCommandLineArguments(QmlProfilerServices, code, true));
Utils::CommandLine cmd = commandLine();
Utils::CommandLine cmd = worker->commandLine();
const QString oldArgs = cmd.arguments();
cmd.setArguments(arguments);
cmd.addArgs(oldArgs, Utils::CommandLine::Raw);
setCommandLine(cmd);
forceRunOnHost();
worker->setCommandLine(cmd);
worker->forceRunOnHost();
});
return worker;
}
// Factories
@@ -224,7 +200,7 @@ public:
LocalQmlProfilerRunWorkerFactory()
{
setId(ProjectExplorer::Constants::QML_PROFILER_RUN_FACTORY);
setProduct<LocalQmlProfilerSupport>();
setProducer(&createLocalQmlProfilerWorker);
addSupportedRunMode(ProjectExplorer::Constants::QML_PROFILER_RUN_MODE);
addSupportedDeviceType(ProjectExplorer::Constants::DESKTOP_DEVICE_TYPE);
@@ -238,5 +214,4 @@ void setupQmlProfilerRunning()
static LocalQmlProfilerRunWorkerFactory theLocalQmlProfilerRunWorkerFactory;
}
} // QmlProfiler::Internal

View File

@@ -37,16 +37,7 @@ private:
QmlProfilerRunnerPrivate *d;
};
class LocalQmlProfilerSupport : public ProjectExplorer::SimpleTargetRunner
{
Q_OBJECT
public:
LocalQmlProfilerSupport(ProjectExplorer::RunControl *runControl);
LocalQmlProfilerSupport(ProjectExplorer::RunControl *runControl,
const QUrl &serverUrl);
};
ProjectExplorer::RunWorker *createLocalQmlProfilerWorker(ProjectExplorer::RunControl *runControl);
void setupQmlProfilerRunning();
} // QmlProfiler::Internal

View File

@@ -29,8 +29,7 @@ LocalQmlProfilerRunnerTest::LocalQmlProfilerRunnerTest(QObject *parent) : QObjec
void LocalQmlProfilerRunnerTest::testRunner()
{
QPointer<RunControl> runControl;
QPointer<LocalQmlProfilerSupport> profiler;
QUrl serverUrl;
QPointer<RunWorker> profiler;
bool running = false;
bool started = false;
@@ -38,14 +37,10 @@ void LocalQmlProfilerRunnerTest::testRunner()
int runCount = 0;
int stopCount = 0;
// should not be used anywhere but cannot be empty
serverUrl.setScheme(Utils::urlSocketScheme());
serverUrl.setPath("invalid");
runControl = new RunControl(ProjectExplorer::Constants::QML_PROFILER_RUN_MODE);
runControl->setCommandLine(CommandLine{"\\-/|\\-/"});
profiler = new LocalQmlProfilerSupport(runControl, serverUrl);
profiler = createLocalQmlProfilerWorker(runControl);
auto connectRunner = [&]() {
connect(runControl, &RunControl::aboutToStart, this, [&] {
@@ -85,13 +80,12 @@ void LocalQmlProfilerRunnerTest::testRunner()
QTRY_VERIFY(runControl.isNull());
QVERIFY(profiler.isNull());
serverUrl = Utils::urlFromLocalSocket();
// comma is used to specify a test function. In this case, an invalid one.
runControl = new RunControl(ProjectExplorer::Constants::QML_PROFILER_RUN_MODE);
const FilePath app = FilePath::fromString(QCoreApplication::applicationFilePath());
runControl->setCommandLine({app, {"-test", "QmlProfiler,"}});
profiler = new LocalQmlProfilerSupport(runControl, serverUrl);
profiler = createLocalQmlProfilerWorker(runControl);
connectRunner();
runControl->initiateStart();
@@ -106,11 +100,9 @@ void LocalQmlProfilerRunnerTest::testRunner()
QTRY_VERIFY(runControl.isNull());
QVERIFY(profiler.isNull());
serverUrl.clear();
serverUrl = Utils::urlFromLocalHostAndFreePort();
runControl = new RunControl(ProjectExplorer::Constants::QML_PROFILER_RUN_MODE);
runControl->setCommandLine(CommandLine{app});
profiler = new LocalQmlProfilerSupport(runControl, serverUrl);
profiler = createLocalQmlProfilerWorker(runControl);
connectRunner();
runControl->initiateStart();
@@ -126,16 +118,9 @@ void LocalQmlProfilerRunnerTest::testRunner()
QTRY_VERIFY(runControl.isNull());
QVERIFY(profiler.isNull());
serverUrl.setScheme(Utils::urlSocketScheme());
{
Utils::TemporaryFile file("file with spaces");
if (file.open())
serverUrl.setPath(file.fileName());
}
runControl = new RunControl(ProjectExplorer::Constants::QML_PROFILER_RUN_MODE);
runControl->setCommandLine({app, {"-test", "QmlProfiler,"}});
profiler = new LocalQmlProfilerSupport(runControl, serverUrl);
profiler = createLocalQmlProfilerWorker(runControl);
connectRunner();
runControl->initiateStart();