Remove TimelineTraceManager::State

This is redundant, now that we have registerFeatures().

Change-Id: Ia56c28b8892ab6da694570fe4b9ea5c96fe194f1
Reviewed-by: Tobias Hunger <tobias.hunger@qt.io>
This commit is contained in:
Ulf Hermann
2018-04-20 18:06:38 +02:00
parent de006655e3
commit 1770c2ffe2
17 changed files with 94 additions and 195 deletions

View File

@@ -40,8 +40,6 @@ class TimelineTraceManager::TimelineTraceManagerPrivate
public:
TimelineNotesModel *notesModel = nullptr;
TimelineTraceManager::State state = Empty;
int numEvents = 0;
int numEventTypes = 0;
quint64 availableFeatures = 0;
@@ -61,7 +59,6 @@ public:
void dispatch(const TraceEvent &event, const TraceEventType &type);
void reset();
void setState(TimelineTraceManager *q, TimelineTraceManager::State state);
void updateTraceTime(qint64 time);
void restrictTraceTimeToRange(qint64 start, qint64 end);
};
@@ -184,20 +181,15 @@ void TimelineTraceManager::initialize()
{
for (const Initializer &initializer : qAsConst(d->initializers))
initializer();
d->setState(this, AcquiringData);
}
void TimelineTraceManager::finalize()
{
QTC_CHECK(state() == AcquiringData);
// Load notes after the timeline models have been initialized ...
// which happens on stateChanged(Done).
for (const Finalizer &finalizer : qAsConst(d->finalizers))
finalizer();
d->setState(this, Done);
}
QFuture<void> TimelineTraceManager::save(const QString &filename)
@@ -335,35 +327,6 @@ void TimelineTraceManager::increaseTraceEnd(qint64 end)
}
}
void TimelineTraceManager::TimelineTraceManagerPrivate::setState(
TimelineTraceManager *q, TimelineTraceManager::State newState)
{
// It's not an error, we are continuously calling "AcquiringData" for example
if (newState == state)
return;
switch (newState) {
case ClearingData:
QTC_CHECK(state == Done || state == Empty || state == AcquiringData);
break;
case Empty:
// if it's not empty, complain but go on
QTC_CHECK(q->isEmpty());
break;
case AcquiringData:
break;
case Done:
QTC_ASSERT(state == AcquiringData || state == Empty, return);
break;
default:
QTC_ASSERT(false, return);
break;
}
state = newState;
emit q->stateChanged(state);
}
void TimelineTraceManager::TimelineTraceManagerPrivate::updateTraceTime(qint64 time)
{
QTC_ASSERT(time >= 0, return);
@@ -382,12 +345,6 @@ void TimelineTraceManager::TimelineTraceManagerPrivate::restrictTraceTimeToRange
restrictedTraceEnd = end;
}
TimelineTraceManager::State TimelineTraceManager::state() const
{
return d->state;
}
void TimelineTraceManager::setNotesModel(TimelineNotesModel *notesModel)
{
d->notesModel = notesModel;
@@ -410,17 +367,13 @@ void TimelineTraceManager::clearTypeStorage()
void TimelineTraceManager::clear()
{
d->setState(this, ClearingData);
clearEventStorage();
d->setState(this, Empty);
}
void TimelineTraceManager::clearAll()
{
d->setState(this, ClearingData);
clearEventStorage();
clearTypeStorage();
d->setState(this, Empty);
}
void TimelineTraceManager::restrictToRange(qint64 startTime, qint64 endTime)
@@ -428,7 +381,6 @@ void TimelineTraceManager::restrictToRange(qint64 startTime, qint64 endTime)
if (d->notesModel)
d->notesModel->stash();
d->setState(this, ClearingData);
d->reset();
setVisibleFeatures(0);

View File

@@ -42,13 +42,6 @@ class TIMELINE_EXPORT TimelineTraceManager : public QObject
{
Q_OBJECT
public:
enum State {
Empty,
AcquiringData,
ClearingData,
Done
};
typedef std::function<void(const TraceEvent &, const TraceEventType &)> TraceEventLoader;
typedef std::function<void()> Initializer;
typedef std::function<void()> Finalizer;
@@ -58,8 +51,6 @@ public:
explicit TimelineTraceManager(QObject *parent = nullptr);
~TimelineTraceManager();
State state() const;
qint64 traceStart() const;
qint64 traceEnd() const;
qint64 traceDuration() const;
@@ -99,7 +90,6 @@ public:
signals:
void error(const QString &error);
void stateChanged(State state);
void loadFinished();
void saveFinished();

View File

@@ -159,8 +159,6 @@ void FlameGraphModel::restrictToFeatures(quint64 visibleFeatures)
return;
m_acceptedFeatures = visibleFeatures;
if (m_modelManager->state() != QmlProfilerModelManager::Done)
return;
clear();

View File

@@ -341,7 +341,6 @@ const char *QmlProfilerModelManager::featureName(ProfileFeature feature)
void QmlProfilerModelManager::finalize()
{
QTC_ASSERT(state() == AcquiringData, /**/);
if (!d->file.flush())
emit error(tr("Failed to flush temporary trace file"));
d->detailsRewriter->reloadDocuments();

View File

@@ -37,6 +37,8 @@
#include <QTimer>
#include <QPointer>
#include <functional>
namespace QmlProfiler {
namespace Internal {
@@ -72,17 +74,16 @@ QmlProfilerStateWidget::QmlProfilerStateWidget(QmlProfilerStateManager *stateMan
// profiler state
d->m_modelManager = modelManager;
connect(d->m_modelManager, &QmlProfilerModelManager::stateChanged,
this, &QmlProfilerStateWidget::update);
modelManager->registerFeatures(0, QmlProfilerModelManager::QmlEventLoader(),
std::bind(&QmlProfilerStateWidget::initialize, this),
std::bind(&QmlProfilerStateWidget::clear, this),
std::bind(&QmlProfilerStateWidget::clear, this));
d->m_profilerState = stateManager;
connect(d->m_profilerState, &QmlProfilerStateManager::stateChanged,
this, &QmlProfilerStateWidget::update);
connect(d->m_profilerState, &QmlProfilerStateManager::serverRecordingChanged,
this, &QmlProfilerStateWidget::update);
connect(&d->timer, &QTimer::timeout, this, &QmlProfilerStateWidget::updateDisplay);
d->timer.setInterval(1000);
update();
setVisible(false);
}
QmlProfilerStateWidget::~QmlProfilerStateWidget()
@@ -97,6 +98,16 @@ void QmlProfilerStateWidget::reposition()
move(parentWidget->width()/2 - width()/2, parentWidget->height()/3 - height()/2);
}
void QmlProfilerStateWidget::initialize()
{
connect(d->m_profilerState, &QmlProfilerStateManager::stateChanged,
this, &QmlProfilerStateWidget::updateDisplay);
connect(d->m_profilerState, &QmlProfilerStateManager::serverRecordingChanged,
this, &QmlProfilerStateWidget::updateDisplay);
d->timer.start();
updateDisplay();
}
void QmlProfilerStateWidget::showText(const QString &text)
{
setVisible(true);
@@ -105,69 +116,45 @@ void QmlProfilerStateWidget::showText(const QString &text)
reposition();
}
void QmlProfilerStateWidget::updateDisplay()
void QmlProfilerStateWidget::clear()
{
if (!d->m_modelManager || !d->m_profilerState) {
disconnect(d->m_profilerState, &QmlProfilerStateManager::stateChanged,
this, &QmlProfilerStateWidget::updateDisplay);
disconnect(d->m_profilerState, &QmlProfilerStateManager::serverRecordingChanged,
this, &QmlProfilerStateWidget::updateDisplay);
d->timer.stop();
setVisible(false);
return;
}
void QmlProfilerStateWidget::updateDisplay()
{
QTC_ASSERT(d->m_modelManager, return);
QTC_ASSERT(d->m_profilerState, return);
// When application is being profiled
if (d->m_profilerState->serverRecording()) {
// Heuristic to not show the number if the application will only send the events when it
// stops. The number is still > 0 then because we get some StartTrace etc.
uint numEvents = d->m_modelManager->numEvents();
const int numEvents = d->m_modelManager->numEvents();
showText(numEvents > 256 ? tr("Profiling application: %n events", nullptr, numEvents) :
tr("Profiling application"));
return;
}
QmlProfilerModelManager::State state = d->m_modelManager->state();
if (state == QmlProfilerModelManager::Done || state == QmlProfilerModelManager::Empty) {
} else if (d->m_modelManager->traceDuration() > 0 && d->m_modelManager->isEmpty()) {
// After profiling, there is an empty trace
if (d->m_modelManager->traceDuration() > 0 && d->m_modelManager->isEmpty()) {
showText(tr("No QML events recorded"));
return;
}
} else if (!d->m_modelManager->isEmpty()) {
// When datamodel is acquiring or processing data
// When datamodel is acquiring data
if (d->m_profilerState->currentState() != QmlProfilerStateManager::Idle) {
if (state == QmlProfilerModelManager::AcquiringData) {
// we don't know how much more, so progress numbers are strange here
showText(tr("Loading buffered data: %n events", nullptr,
d->m_modelManager->numEvents()));
} else if (state == QmlProfilerModelManager::ClearingData) {
// when starting a second recording from the same process without aggregation
showText(tr("Clearing old trace"));
}
} else if (state == QmlProfilerModelManager::AcquiringData) {
} else {
// Application died before all data could be read
showText(tr("Loading offline data: %n events", nullptr,
d->m_modelManager->numEvents()));
} else if (state == QmlProfilerModelManager::ClearingData) {
showText(tr("Clearing old trace"));
}
return;
} else if (state == QmlProfilerModelManager::AcquiringData) {
} else {
showText(tr("Waiting for data"));
return;
}
// There is a trace on view, hide this dialog
setVisible(false);
}
void QmlProfilerStateWidget::update()
{
QmlProfilerModelManager::State state = d->m_modelManager ? d->m_modelManager->state()
: QmlProfilerModelManager::Empty;
if (state == QmlProfilerModelManager::AcquiringData)
d->timer.start();
else
d->timer.stop();
updateDisplay();
}
} // namespace Internal

View File

@@ -45,8 +45,9 @@ public:
private:
void showText(const QString &text);
void updateDisplay();
void update();
void reposition();
void initialize();
void clear();
class QmlProfilerStateWidgetPrivate;
QmlProfilerStateWidgetPrivate *d;

View File

@@ -96,7 +96,8 @@ void QmlProfilerStatisticsModel::restrictToFeatures(quint64 features)
}
}
}
if (!didChange || m_modelManager->state() != QmlProfilerModelManager::Done)
if (!didChange)
return;
clear();

View File

@@ -149,8 +149,11 @@ QmlProfilerTool::QmlProfilerTool()
this, &QmlProfilerTool::clientsDisconnected);
d->m_profilerModelManager = new QmlProfilerModelManager(this);
connect(d->m_profilerModelManager, &QmlProfilerModelManager::stateChanged,
this, &QmlProfilerTool::profilerDataModelStateChanged);
d->m_profilerModelManager->registerFeatures(0, QmlProfilerModelManager::QmlEventLoader(),
std::bind(&QmlProfilerTool::initialize, this),
std::bind(&QmlProfilerTool::finalize, this),
std::bind(&QmlProfilerTool::clear, this));
connect(d->m_profilerModelManager, &QmlProfilerModelManager::error,
this, &QmlProfilerTool::showErrorDialog);
connect(d->m_profilerModelManager, &QmlProfilerModelManager::availableFeaturesChanged,
@@ -305,21 +308,6 @@ QmlProfilerTool::QmlProfilerTool()
d->m_recordButton->setToolTip(recording ? tr("Disable Profiling") : tr("Enable Profiling"));
d->m_recordButton->setIcon(recording ? recordOn : recordOff);
d->m_recordButton->setChecked(recording);
switch (d->m_profilerModelManager->state()) {
case QmlProfilerModelManager::Empty:
case QmlProfilerModelManager::AcquiringData:
case QmlProfilerModelManager::Done:
// Don't change the recording button if the application cannot react to it.
d->m_recordButton->setEnabled(d->m_profilerState->currentState()
!= QmlProfilerStateManager::AppStopRequested
&& d->m_profilerState->currentState()
!= QmlProfilerStateManager::AppDying);
break;
case QmlProfilerModelManager::ClearingData:
d->m_recordButton->setEnabled(false);
break;
}
};
connect(d->m_profilerState, &QmlProfilerStateManager::stateChanged,
@@ -328,8 +316,6 @@ QmlProfilerTool::QmlProfilerTool()
d->m_recordButton, updateRecordButton);
connect(d->m_profilerState, &QmlProfilerStateManager::clientRecordingChanged,
d->m_recordButton, updateRecordButton);
connect(d->m_profilerModelManager, &QmlProfilerModelManager::stateChanged,
d->m_recordButton, updateRecordButton);
updateRecordButton();
}
@@ -434,11 +420,9 @@ void QmlProfilerTool::recordingButtonChanged(bool recording)
{
// clientRecording is our intention for new sessions. That may differ from the state of the
// current session, as indicated by the button. To synchronize it, toggle once.
if (recording && d->m_profilerState->currentState() == QmlProfilerStateManager::AppRunning) {
if (checkForUnsavedNotes()) {
if (!d->m_profilerModelManager->aggregateTraces() ||
d->m_profilerModelManager->state() == QmlProfilerModelManager::Done)
if (!d->m_profilerModelManager->aggregateTraces())
clearEvents(); // clear before the recording starts, unless we aggregate recordings
if (d->m_profilerState->clientRecording())
d->m_profilerState->setClientRecording(false);
@@ -485,8 +469,7 @@ void QmlProfilerTool::updateTimeDisplay()
}
Q_FALLTHROUGH();
case QmlProfilerStateManager::Idle:
if (d->m_profilerModelManager->state() != QmlProfilerModelManager::Empty &&
d->m_profilerModelManager->state() != QmlProfilerModelManager::ClearingData)
if (d->m_profilerModelManager->traceDuration() > 0)
seconds = d->m_profilerModelManager->traceDuration() / 1.0e9;
break;
}
@@ -735,7 +718,7 @@ void QmlProfilerTool::restoreFeatureVisibility()
void QmlProfilerTool::clientsDisconnected()
{
if (d->m_profilerModelManager->state() == QmlProfilerModelManager::AcquiringData) {
if (d->m_toolBusy) {
if (d->m_profilerModelManager->aggregateTraces()) {
d->m_profilerModelManager->finalize();
} else {
@@ -802,28 +785,27 @@ void QmlProfilerTool::setRecordedFeatures(quint64 features)
action->setEnabled(features & (1ULL << action->data().toUInt()));
}
void QmlProfilerTool::profilerDataModelStateChanged()
void QmlProfilerTool::initialize()
{
switch (d->m_profilerModelManager->state()) {
case QmlProfilerModelManager::Empty :
setButtonsEnabled(true);
break;
case QmlProfilerModelManager::ClearingData :
clearTextMarks();
setButtonsEnabled(false);
clearDisplay();
break;
case QmlProfilerModelManager::AcquiringData :
restoreFeatureVisibility();
setButtonsEnabled(false); // Other buttons disabled
break;
case QmlProfilerModelManager::Done :
}
void QmlProfilerTool::finalize()
{
showSaveOption();
updateTimeDisplay();
setButtonsEnabled(true);
createTextMarks();
break;
setButtonsEnabled(true);
d->m_recordButton->setEnabled(true);
}
void QmlProfilerTool::clear()
{
clearTextMarks();
clearDisplay();
setButtonsEnabled(true);
d->m_recordButton->setEnabled(true);
}
QList <QAction *> QmlProfilerTool::profilerContextMenuActions()
@@ -913,8 +895,7 @@ void QmlProfilerTool::serverRecordingChanged()
d->m_recordingTimer.start();
d->m_recordingElapsedTime.start();
if (!d->m_profilerModelManager->aggregateTraces() ||
d->m_profilerModelManager->state() == QmlProfilerModelManager::Done)
if (!d->m_profilerModelManager->aggregateTraces())
clearEvents();
d->m_profilerModelManager->initialize();
} else {

View File

@@ -104,6 +104,10 @@ private:
void createTextMarks();
void clearTextMarks();
void initialize();
void finalize();
void clear();
class QmlProfilerToolPrivate;
QmlProfilerToolPrivate *d;
};

View File

@@ -96,24 +96,7 @@ QmlProfilerTraceView::QmlProfilerTraceView(QWidget *parent, QmlProfilerViewManag
setObjectName("QmlProfiler.Timeline.Dock");
d->m_zoomControl = new Timeline::TimelineZoomControl(this);
connect(modelManager, &QmlProfilerModelManager::stateChanged, this, [modelManager, this]() {
switch (modelManager->state()) {
case QmlProfilerModelManager::Done: {
const qint64 start = modelManager->traceStart();
const qint64 end = modelManager->traceEnd();
d->m_zoomControl->setTrace(start, end);
d->m_zoomControl->setRange(start, start + (end - start) / 10);
Q_FALLTHROUGH();
}
case QmlProfilerModelManager::Empty:
d->m_modelProxy->setModels(d->m_suspendedModels);
d->m_suspendedModels.clear();
d->m_modelManager->notesModel()->restore();
break;
case QmlProfilerModelManager::ClearingData:
d->m_zoomControl->clear();
Q_FALLTHROUGH();
case QmlProfilerModelManager::AcquiringData:
modelManager->registerFeatures(0, QmlProfilerModelManager::QmlEventLoader(), [this]() {
if (d->m_suspendedModels.isEmpty()) {
// Temporarily remove the models, while we're changing them
d->m_suspendedModels = d->m_modelProxy->models();
@@ -122,7 +105,18 @@ QmlProfilerTraceView::QmlProfilerTraceView(QWidget *parent, QmlProfilerViewManag
// Otherwise models are suspended already. This can happen if either acquiring was
// aborted or we're doing a "restrict to range" which consists of a partial clearing and
// then re-acquiring of data.
break;
}, [this, modelManager]() {
const qint64 start = modelManager->traceStart();
const qint64 end = modelManager->traceEnd();
d->m_zoomControl->setTrace(start, end);
d->m_zoomControl->setRange(start, start + (end - start) / 10);
d->m_modelProxy->setModels(d->m_suspendedModels);
d->m_suspendedModels.clear();
}, [this]() {
d->m_zoomControl->clear();
if (!d->m_suspendedModels.isEmpty()) {
d->m_modelProxy->setModels(d->m_suspendedModels);
d->m_suspendedModels.clear();
}
});

View File

@@ -53,7 +53,6 @@ void DebugMessagesModelTest::initTestCase()
manager.addEvent(event);
}
manager.finalize();
QCOMPARE(manager.state(), QmlProfilerModelManager::Done);
}
void DebugMessagesModelTest::testTypeId()

View File

@@ -98,7 +98,6 @@ void FlameGraphModelTest::initTestCase()
{
QCOMPARE(model.modelManager(), &manager);
rangeModelId = generateData(&manager, &aggregator);
QCOMPARE(manager.state(), QmlProfilerModelManager::Done);
}
void FlameGraphModelTest::testIndex()

View File

@@ -44,7 +44,6 @@ void FlameGraphViewTest::initTestCase()
connect(&view, &QmlProfilerEventsView::showFullRange,
this, [this](){ manager.restrictToRange(-1, -1); });
FlameGraphModelTest::generateData(&manager, &aggregator);
QCOMPARE(manager.state(), QmlProfilerModelManager::Done);
view.resize(500, 500);
view.show();
QVERIFY(QTest::qWaitForWindowExposed(&view));

View File

@@ -62,7 +62,6 @@ void InputEventsModelTest::initTestCase()
}
manager.finalize();
QCOMPARE(manager.state(), QmlProfilerModelManager::Done);
}
void InputEventsModelTest::testAccepted()

View File

@@ -97,7 +97,6 @@ void MemoryUsageModelTest::initTestCase()
manager.addEvent(event);
manager.finalize();
QCOMPARE(manager.state(), QmlProfilerModelManager::Done);
QCOMPARE(model.count(), 11);
}

View File

@@ -188,8 +188,6 @@ void PixmapCacheModelTest::initTestCase()
manager.finalize();
QCOMPARE(manager.state(), QmlProfilerModelManager::Done);
}
void PixmapCacheModelTest::testConsistency()

View File

@@ -55,7 +55,6 @@ void QmlProfilerAnimationsModelTest::initTestCase()
manager.addEvent(event);
}
manager.finalize();
QCOMPARE(manager.state(), QmlProfilerModelManager::Done);
}
void QmlProfilerAnimationsModelTest::testAccepted()