QmlProfiler: Refactor complete() methods

The complete() methods do something more specific. We should call them
by what they do. Also, we don't need to signal the finishing of data
acquisition via a signal and most of the postprocessing can happen in
the worker thread.

Change-Id: Iae986aefb8e7e7d4327c481d7a85325bbff7fa48
Reviewed-by: Joerg Bornemann <joerg.bornemann@theqtcompany.com>
This commit is contained in:
Ulf Hermann
2015-09-10 17:11:21 +02:00
parent 44750d047e
commit fdbed834fa
6 changed files with 31 additions and 44 deletions

View File

@@ -96,11 +96,7 @@ QmlProfilerClientManager::~QmlProfilerClientManager()
void QmlProfilerClientManager::setModelManager(QmlProfilerModelManager *m) void QmlProfilerClientManager::setModelManager(QmlProfilerModelManager *m)
{ {
if (d->modelManager)
disconnect(this,SIGNAL(dataReadyForProcessing()), d->modelManager, SLOT(complete()));
d->modelManager = m; d->modelManager = m;
if (d->modelManager)
connect(this,SIGNAL(dataReadyForProcessing()), d->modelManager, SLOT(complete()));
} }
void QmlProfilerClientManager::setFlushInterval(quint32 flushInterval) void QmlProfilerClientManager::setFlushInterval(quint32 flushInterval)
@@ -315,7 +311,8 @@ void QmlProfilerClientManager::qmlComplete(qint64 maximumTime)
{ {
d->modelManager->traceTime()->increaseEndTime(maximumTime); d->modelManager->traceTime()->increaseEndTime(maximumTime);
d->qmlDataReady = true; d->qmlDataReady = true;
emit dataReadyForProcessing(); if (d->modelManager)
d->modelManager->acquiringDone();
// once complete is sent, reset the flags // once complete is sent, reset the flags
d->qmlDataReady = false; d->qmlDataReady = false;
} }

View File

@@ -62,7 +62,6 @@ public:
signals: signals:
void connectionFailed(); void connectionFailed();
void connectionClosed(); void connectionClosed();
void dataReadyForProcessing();
public slots: public slots:
void connectClient(quint16 port); void connectClient(quint16 port);

View File

@@ -111,10 +111,12 @@ QmlProfilerDataModel::QmlProfilerDataModel(Utils::FileInProjectFinder *fileFinde
d->modelManager = parent; d->modelManager = parent;
d->detailsRewriter = new QmlProfilerDetailsRewriter(this, fileFinder); d->detailsRewriter = new QmlProfilerDetailsRewriter(this, fileFinder);
d->modelId = d->modelManager->registerModelProxy(); d->modelId = d->modelManager->registerModelProxy();
connect(d->detailsRewriter, SIGNAL(rewriteDetailsString(int,QString)), connect(d->detailsRewriter, &QmlProfilerDetailsRewriter::rewriteDetailsString,
this, SLOT(detailsChanged(int,QString))); this, &QmlProfilerDataModel::detailsChanged);
connect(d->detailsRewriter, SIGNAL(eventDetailsChanged()), connect(d->detailsRewriter, &QmlProfilerDetailsRewriter::eventDetailsChanged,
this, SLOT(detailsDone())); this, &QmlProfilerDataModel::detailsDone);
connect(this, &QmlProfilerDataModel::requestReload,
d->detailsRewriter, &QmlProfilerDetailsRewriter::reloadDocuments);
// The document loading is very expensive. // The document loading is very expensive.
d->modelManager->setProxyCountWeight(d->modelId, 4); d->modelManager->setProxyCountWeight(d->modelId, 4);
@@ -155,7 +157,7 @@ void QmlProfilerDataModel::setData(qint64 traceStart, qint64 traceEnd,
d->eventTypes = types; d->eventTypes = types;
for (int id = 0; id < types.count(); ++id) for (int id = 0; id < types.count(); ++id)
d->eventTypeIds[types[id]] = id; d->eventTypeIds[types[id]] = id;
// Half the work is done. complete() will do the rest. // Half the work is done. processData() will do the rest.
d->modelManager->modelProxyCountUpdated(d->modelId, 1, 2); d->modelManager->modelProxyCountUpdated(d->modelId, 1, 2);
} }
@@ -215,7 +217,7 @@ inline static bool operator==(const QmlProfilerDataModel::QmlEventTypeData &type
type1.location.filename == type2.location.filename; type1.location.filename == type2.location.filename;
} }
void QmlProfilerDataModel::complete() void QmlProfilerDataModel::processData()
{ {
Q_D(QmlProfilerDataModel); Q_D(QmlProfilerDataModel);
// post-processing // post-processing
@@ -251,7 +253,7 @@ void QmlProfilerDataModel::complete()
// Allow changed() event only after documents have been reloaded to avoid // Allow changed() event only after documents have been reloaded to avoid
// unnecessary updates of child models. // unnecessary updates of child models.
d->detailsRewriter->reloadDocuments(); emit requestReload();
} }
void QmlProfilerDataModel::addQmlEvent(QmlDebug::Message message, QmlDebug::RangeType rangeType, void QmlProfilerDataModel::addQmlEvent(QmlDebug::Message message, QmlDebug::RangeType rangeType,
@@ -313,7 +315,7 @@ void QmlProfilerDataModel::detailsDone()
Q_D(QmlProfilerDataModel); Q_D(QmlProfilerDataModel);
emit changed(); emit changed();
d->modelManager->modelProxyCountUpdated(d->modelId, isEmpty() ? 0 : 1, 1); d->modelManager->modelProxyCountUpdated(d->modelId, isEmpty() ? 0 : 1, 1);
d->modelManager->complete(); d->modelManager->processingDone();
} }
} }

View File

@@ -81,11 +81,11 @@ public:
void setData(qint64 traceStart, qint64 traceEnd, const QVector<QmlEventTypeData> &types, void setData(qint64 traceStart, qint64 traceEnd, const QVector<QmlEventTypeData> &types,
const QVector<QmlEventData> &events); const QVector<QmlEventData> &events);
void setNoteData(const QVector<QmlEventNoteData> &notes); void setNoteData(const QVector<QmlEventNoteData> &notes);
void processData();
int count() const; int count() const;
void clear(); void clear();
bool isEmpty() const; bool isEmpty() const;
void complete();
void addQmlEvent(QmlDebug::Message message, QmlDebug::RangeType rangeType, int bindingType, void addQmlEvent(QmlDebug::Message message, QmlDebug::RangeType rangeType, int bindingType,
qint64 startTime, qint64 duration, const QString &data, qint64 startTime, qint64 duration, const QString &data,
const QmlDebug::QmlEventLocation &location, qint64 ndata1, qint64 ndata2, const QmlDebug::QmlEventLocation &location, qint64 ndata1, qint64 ndata2,
@@ -94,6 +94,7 @@ public:
signals: signals:
void changed(); void changed();
void requestReload();
protected slots: protected slots:
void detailsChanged(int requestId, const QString &newString); void detailsChanged(int requestId, const QString &newString);

View File

@@ -293,30 +293,19 @@ void QmlProfilerModelManager::addQmlEvent(QmlDebug::Message message,
ndata1, ndata2, ndata3, ndata4, ndata5); ndata1, ndata2, ndata3, ndata4, ndata5);
} }
void QmlProfilerModelManager::complete() void QmlProfilerModelManager::acquiringDone()
{ {
switch (state()) { QTC_ASSERT(state() == AcquiringData, /**/);
case ProcessingData: setState(ProcessingData);
// Load notes after the timeline models have been initialized. d->model->processData();
}
void QmlProfilerModelManager::processingDone()
{
QTC_ASSERT(state() == ProcessingData, /**/);
d->notesModel->loadData(); d->notesModel->loadData();
setState(Done); setState(Done);
emit loadFinished(); emit loadFinished();
break;
case AcquiringData:
// Make sure the trace fits into the time span.
d->traceTime->increaseEndTime(d->model->lastTimeMark());
setState(ProcessingData);
d->model->complete();
break;
case Empty:
setState(Done);
break;
case Done:
break;
default:
emit error(tr("Unexpected complete signal in data model."));
break;
}
} }
void QmlProfilerModelManager::save(const QString &filename) void QmlProfilerModelManager::save(const QString &filename)
@@ -369,10 +358,8 @@ void QmlProfilerModelManager::load(const QString &filename)
setRecordedFeatures(reader.loadedFeatures()); setRecordedFeatures(reader.loadedFeatures());
file->close(); file->close();
file->deleteLater(); file->deleteLater();
d->traceTime->increaseEndTime(d->model->lastTimeMark());
// The completion step uses the old progress display widget for now. We need to do this in acquiringDone();
// the main thread as it creates widgets.
QMetaObject::invokeMethod(this, "complete", Qt::QueuedConnection);
}); });
Core::ProgressManager::addTask(result, tr("Loading Trace Data"), Constants::TASK_LOAD); Core::ProgressManager::addTask(result, tr("Loading Trace Data"), Constants::TASK_LOAD);

View File

@@ -110,6 +110,9 @@ public:
quint64 recordedFeatures() const; quint64 recordedFeatures() const;
void setRecordedFeatures(quint64 features); void setRecordedFeatures(quint64 features);
void acquiringDone();
void processingDone();
static const char *featureName(QmlDebug::ProfileFeature feature); static const char *featureName(QmlDebug::ProfileFeature feature);
signals: signals:
@@ -133,8 +136,6 @@ public slots:
const QmlDebug::QmlEventLocation &location, const QmlDebug::QmlEventLocation &location,
qint64 ndata1, qint64 ndata2, qint64 ndata3, qint64 ndata4, qint64 ndata5); qint64 ndata1, qint64 ndata2, qint64 ndata3, qint64 ndata4, qint64 ndata5);
void complete();
void save(const QString &filename); void save(const QString &filename);
void load(const QString &filename); void load(const QString &filename);