forked from qt-creator/qt-creator
QmlProfilerTool: Move parts of finalizeRunControl into QmlProfilerRunner
Hide QmlProfilerRunner::cancelProcess(). Pass RunControl into finalizeRunControl, instead of QmlProfilerRunner. Change-Id: I3f57a8d80a6261bb5692715c0251a600d35b54ae Reviewed-by: hjk <hjk@qt.io>
This commit is contained in:
@@ -3,8 +3,10 @@
|
|||||||
|
|
||||||
#include "qmlprofilerruncontrol.h"
|
#include "qmlprofilerruncontrol.h"
|
||||||
|
|
||||||
|
#include "qmlprofilerclientmanager.h"
|
||||||
#include "qmlprofilerstatemanager.h"
|
#include "qmlprofilerstatemanager.h"
|
||||||
#include "qmlprofilertool.h"
|
#include "qmlprofilertool.h"
|
||||||
|
#include "qmlprofilertr.h"
|
||||||
|
|
||||||
#include <coreplugin/icore.h>
|
#include <coreplugin/icore.h>
|
||||||
#include <coreplugin/helpmanager.h>
|
#include <coreplugin/helpmanager.h>
|
||||||
@@ -24,6 +26,8 @@
|
|||||||
#include <utils/qtcassert.h>
|
#include <utils/qtcassert.h>
|
||||||
#include <utils/url.h>
|
#include <utils/url.h>
|
||||||
|
|
||||||
|
#include <QMessageBox>
|
||||||
|
|
||||||
using namespace Core;
|
using namespace Core;
|
||||||
using namespace ProjectExplorer;
|
using namespace ProjectExplorer;
|
||||||
|
|
||||||
@@ -63,7 +67,7 @@ void QmlProfilerRunner::start()
|
|||||||
if (d->m_profilerState)
|
if (d->m_profilerState)
|
||||||
disconnect(d->m_profilerState, &QmlProfilerStateManager::stateChanged, this, nullptr);
|
disconnect(d->m_profilerState, &QmlProfilerStateManager::stateChanged, this, nullptr);
|
||||||
|
|
||||||
QmlProfilerTool::instance()->finalizeRunControl(this);
|
QmlProfilerTool::instance()->finalizeRunControl(runControl());
|
||||||
connect(this, &QmlProfilerRunner::stopped,
|
connect(this, &QmlProfilerRunner::stopped,
|
||||||
QmlProfilerTool::instance(), &QmlProfilerTool::handleStop);
|
QmlProfilerTool::instance(), &QmlProfilerTool::handleStop);
|
||||||
d->m_profilerState = QmlProfilerTool::instance()->stateManager();
|
d->m_profilerState = QmlProfilerTool::instance()->stateManager();
|
||||||
@@ -73,6 +77,66 @@ void QmlProfilerRunner::start()
|
|||||||
if (d->m_profilerState->currentState() == QmlProfilerStateManager::Idle)
|
if (d->m_profilerState->currentState() == QmlProfilerStateManager::Idle)
|
||||||
reportStopped();
|
reportStopped();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
QmlProfilerClientManager *clientManager = QmlProfilerTool::instance()->clientManager();
|
||||||
|
connect(clientManager, &QmlProfilerClientManager::connectionFailed, this, [this, clientManager] {
|
||||||
|
auto infoBox = new QMessageBox(ICore::dialogParent());
|
||||||
|
infoBox->setIcon(QMessageBox::Critical);
|
||||||
|
infoBox->setWindowTitle(QGuiApplication::applicationDisplayName());
|
||||||
|
|
||||||
|
const int interval = clientManager->retryInterval();
|
||||||
|
const int retries = clientManager->maximumRetries();
|
||||||
|
|
||||||
|
infoBox->setText(Tr::tr("Could not connect to the in-process QML profiler "
|
||||||
|
"within %1 s.\n"
|
||||||
|
"Do you want to retry and wait %2 s?")
|
||||||
|
.arg(interval * retries / 1000.0)
|
||||||
|
.arg(interval * 2 * retries / 1000.0));
|
||||||
|
infoBox->setStandardButtons(QMessageBox::Retry | QMessageBox::Cancel | QMessageBox::Help);
|
||||||
|
infoBox->setDefaultButton(QMessageBox::Retry);
|
||||||
|
infoBox->setModal(true);
|
||||||
|
|
||||||
|
connect(infoBox, &QDialog::finished, this, [this, clientManager, interval](int result) {
|
||||||
|
const auto cancelProcess = [this] {
|
||||||
|
QTC_ASSERT(d->m_profilerState, return);
|
||||||
|
|
||||||
|
switch (d->m_profilerState->currentState()) {
|
||||||
|
case QmlProfilerStateManager::Idle:
|
||||||
|
break;
|
||||||
|
case QmlProfilerStateManager::AppRunning:
|
||||||
|
d->m_profilerState->setCurrentState(QmlProfilerStateManager::AppDying);
|
||||||
|
break;
|
||||||
|
default: {
|
||||||
|
const QString message = QString::fromLatin1("Unexpected process termination requested with state %1 in %2:%3")
|
||||||
|
.arg(d->m_profilerState->currentStateAsString(), QString::fromLatin1(__FILE__), QString::number(__LINE__));
|
||||||
|
qWarning("%s", qPrintable(message));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
runControl()->initiateStop();
|
||||||
|
};
|
||||||
|
|
||||||
|
switch (result) {
|
||||||
|
case QMessageBox::Retry:
|
||||||
|
clientManager->setRetryInterval(interval * 2);
|
||||||
|
clientManager->retryConnect();
|
||||||
|
break;
|
||||||
|
case QMessageBox::Help:
|
||||||
|
HelpManager::showHelpUrl(
|
||||||
|
"qthelp://org.qt-project.qtcreator/doc/creator-debugging-qml.html");
|
||||||
|
Q_FALLTHROUGH();
|
||||||
|
case QMessageBox::Cancel:
|
||||||
|
// The actual error message has already been logged.
|
||||||
|
QmlProfilerTool::logState(Tr::tr("Failed to connect."));
|
||||||
|
cancelProcess();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
infoBox->show();
|
||||||
|
}, Qt::QueuedConnection); // Queue any connection failures after reportStarted()
|
||||||
|
clientManager->connectToServer(runControl()->qmlChannel());
|
||||||
|
|
||||||
reportStarted();
|
reportStarted();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -105,26 +169,6 @@ void QmlProfilerRunner::stop()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void QmlProfilerRunner::cancelProcess()
|
|
||||||
{
|
|
||||||
QTC_ASSERT(d->m_profilerState, return);
|
|
||||||
|
|
||||||
switch (d->m_profilerState->currentState()) {
|
|
||||||
case QmlProfilerStateManager::Idle:
|
|
||||||
break;
|
|
||||||
case QmlProfilerStateManager::AppRunning:
|
|
||||||
d->m_profilerState->setCurrentState(QmlProfilerStateManager::AppDying);
|
|
||||||
break;
|
|
||||||
default: {
|
|
||||||
const QString message = QString::fromLatin1("Unexpected process termination requested with state %1 in %2:%3")
|
|
||||||
.arg(d->m_profilerState->currentStateAsString(), QString::fromLatin1(__FILE__), QString::number(__LINE__));
|
|
||||||
qWarning("%s", qPrintable(message));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
runControl()->initiateStop();
|
|
||||||
}
|
|
||||||
|
|
||||||
RunWorker *createLocalQmlProfilerWorker(RunControl *runControl)
|
RunWorker *createLocalQmlProfilerWorker(RunControl *runControl)
|
||||||
{
|
{
|
||||||
auto worker = new ProcessRunner(runControl);
|
auto worker = new ProcessRunner(runControl);
|
||||||
|
@@ -20,8 +20,6 @@ public:
|
|||||||
QmlProfilerRunner(ProjectExplorer::RunControl *runControl);
|
QmlProfilerRunner(ProjectExplorer::RunControl *runControl);
|
||||||
~QmlProfilerRunner() override;
|
~QmlProfilerRunner() override;
|
||||||
|
|
||||||
void cancelProcess();
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void start() override;
|
void start() override;
|
||||||
void stop() override;
|
void stop() override;
|
||||||
|
@@ -350,10 +350,9 @@ void QmlProfilerTool::updateRunActions()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void QmlProfilerTool::finalizeRunControl(QmlProfilerRunner *runWorker)
|
void QmlProfilerTool::finalizeRunControl(RunControl *runControl)
|
||||||
{
|
{
|
||||||
d->m_toolBusy = true;
|
d->m_toolBusy = true;
|
||||||
auto runControl = runWorker->runControl();
|
|
||||||
if (auto aspect = runControl->aspectData<QmlProfilerRunConfigurationAspect>()) {
|
if (auto aspect = runControl->aspectData<QmlProfilerRunConfigurationAspect>()) {
|
||||||
if (auto settings = static_cast<const QmlProfilerSettings *>(aspect->currentSettings)) {
|
if (auto settings = static_cast<const QmlProfilerSettings *>(aspect->currentSettings)) {
|
||||||
d->m_profilerConnections->setFlushInterval(settings->flushEnabled() ?
|
d->m_profilerConnections->setFlushInterval(settings->flushEnabled() ?
|
||||||
@@ -366,52 +365,7 @@ void QmlProfilerTool::finalizeRunControl(QmlProfilerRunner *runWorker)
|
|||||||
|
|
||||||
updateRunActions();
|
updateRunActions();
|
||||||
|
|
||||||
//
|
|
||||||
// Initialize m_projectFinder
|
|
||||||
//
|
|
||||||
|
|
||||||
d->m_profilerModelManager->populateFileFinder(runControl->target());
|
d->m_profilerModelManager->populateFileFinder(runControl->target());
|
||||||
|
|
||||||
connect(d->m_profilerConnections, &QmlProfilerClientManager::connectionFailed,
|
|
||||||
runWorker, [this, runWorker] {
|
|
||||||
auto infoBox = new QMessageBox(ICore::dialogParent());
|
|
||||||
infoBox->setIcon(QMessageBox::Critical);
|
|
||||||
infoBox->setWindowTitle(QGuiApplication::applicationDisplayName());
|
|
||||||
|
|
||||||
const int interval = d->m_profilerConnections->retryInterval();
|
|
||||||
const int retries = d->m_profilerConnections->maximumRetries();
|
|
||||||
|
|
||||||
infoBox->setText(Tr::tr("Could not connect to the in-process QML profiler "
|
|
||||||
"within %1 s.\n"
|
|
||||||
"Do you want to retry and wait %2 s?")
|
|
||||||
.arg(interval * retries / 1000.0)
|
|
||||||
.arg(interval * 2 * retries / 1000.0));
|
|
||||||
infoBox->setStandardButtons(QMessageBox::Retry | QMessageBox::Cancel | QMessageBox::Help);
|
|
||||||
infoBox->setDefaultButton(QMessageBox::Retry);
|
|
||||||
infoBox->setModal(true);
|
|
||||||
|
|
||||||
connect(infoBox, &QDialog::finished, runWorker, [this, runWorker, interval](int result) {
|
|
||||||
switch (result) {
|
|
||||||
case QMessageBox::Retry:
|
|
||||||
d->m_profilerConnections->setRetryInterval(interval * 2);
|
|
||||||
d->m_profilerConnections->retryConnect();
|
|
||||||
break;
|
|
||||||
case QMessageBox::Help:
|
|
||||||
HelpManager::showHelpUrl(
|
|
||||||
"qthelp://org.qt-project.qtcreator/doc/creator-debugging-qml.html");
|
|
||||||
Q_FALLTHROUGH();
|
|
||||||
case QMessageBox::Cancel:
|
|
||||||
// The actual error message has already been logged.
|
|
||||||
QmlProfilerTool::logState(Tr::tr("Failed to connect."));
|
|
||||||
runWorker->cancelProcess();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
infoBox->show();
|
|
||||||
}, Qt::QueuedConnection); // Queue any connection failures after reportStarted()
|
|
||||||
|
|
||||||
d->m_profilerConnections->connectToServer(runControl->qmlChannel());
|
|
||||||
d->m_profilerState->setCurrentState(QmlProfilerStateManager::AppRunning);
|
d->m_profilerState->setCurrentState(QmlProfilerStateManager::AppRunning);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -17,7 +17,6 @@ class QmlProfilerStateManager;
|
|||||||
|
|
||||||
namespace Internal {
|
namespace Internal {
|
||||||
|
|
||||||
class QmlProfilerRunner;
|
|
||||||
class QmlProfilerClientManager;
|
class QmlProfilerClientManager;
|
||||||
|
|
||||||
class QMLPROFILER_EXPORT QmlProfilerTool : public QObject
|
class QMLPROFILER_EXPORT QmlProfilerTool : public QObject
|
||||||
@@ -30,7 +29,7 @@ public:
|
|||||||
|
|
||||||
static QmlProfilerTool *instance();
|
static QmlProfilerTool *instance();
|
||||||
|
|
||||||
void finalizeRunControl(QmlProfilerRunner *runWorker);
|
void finalizeRunControl(ProjectExplorer::RunControl *runControl);
|
||||||
void handleStop();
|
void handleStop();
|
||||||
|
|
||||||
bool prepareTool();
|
bool prepareTool();
|
||||||
|
Reference in New Issue
Block a user