QmlProfiler: Retain event types between sessions on same connection

The server won't re-send the event types. We need to keep them until the
connection goes away. Otherwise we get invalid event types and soft
asserts when trying to look up event types for new events. Also, when
clearing the event types, also clear the server type IDs. Not clearing
those constitutes a memory leak.

Change-Id: I564b0c4cf0ed754549d2b8ede63c97fa01affcec
Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
This commit is contained in:
Ulf Hermann
2018-01-03 13:40:48 +01:00
parent ffe120a43f
commit 4a5bd323a9
8 changed files with 43 additions and 8 deletions

View File

@@ -88,6 +88,12 @@ void QmlProfilerClientManager::clearConnection()
stopConnectionTimer();
}
void QmlProfilerClientManager::clearEvents()
{
if (m_qmlclientplugin)
m_qmlclientplugin->clearEvents();
}
void QmlProfilerClientManager::clearBufferedData()
{
if (m_qmlclientplugin)

View File

@@ -50,6 +50,7 @@ public:
void connectToServer(const QUrl &server);
void clearConnection();
void clearEvents();
void clearBufferedData();
bool isConnected() const;

View File

@@ -691,9 +691,8 @@ QmlProfilerModelManager::State QmlProfilerModelManager::state() const
return d->state;
}
void QmlProfilerModelManager::clear()
void QmlProfilerModelManager::doClearEvents()
{
setState(ClearingData);
d->numLoadedEvents = 0;
d->numFinishedFinalizers = 0;
d->file.remove();
@@ -702,13 +701,25 @@ void QmlProfilerModelManager::clear()
d->eventStream.setDevice(&d->file);
else
emit error(tr("Cannot open temporary trace file to store events."));
d->eventTypes.clear();
d->detailsRewriter->clear();
d->traceTime->clear();
d->notesModel->clear();
setVisibleFeatures(0);
setRecordedFeatures(0);
}
void QmlProfilerModelManager::clearEvents()
{
setState(ClearingData);
doClearEvents();
setState(Empty);
}
void QmlProfilerModelManager::clear()
{
setState(ClearingData);
doClearEvents();
d->eventTypes.clear();
d->detailsRewriter->clear();
setState(Empty);
}

View File

@@ -134,6 +134,7 @@ public:
static const char *featureName(ProfileFeature feature);
void clearEvents();
void clear();
void restrictToRange(qint64 startTime, qint64 endTime);
bool isRestrictedToRange() const;
@@ -156,6 +157,7 @@ signals:
private:
void setState(State state);
void detailsChanged(int typeId, const QString &newString);
void doClearEvents();
class QmlProfilerModelManagerPrivate;
QmlProfilerModelManagerPrivate *d;

View File

@@ -405,7 +405,7 @@ void QmlProfilerTool::recordingButtonChanged(bool recording)
if (checkForUnsavedNotes()) {
if (!d->m_profilerModelManager->aggregateTraces() ||
d->m_profilerModelManager->state() == QmlProfilerModelManager::Done)
clearData(); // clear before the recording starts, unless we aggregate recordings
clearEvents(); // clear before the recording starts, unless we aggregate recordings
if (d->m_profilerState->clientRecording())
d->m_profilerState->setClientRecording(false);
d->m_profilerState->setClientRecording(true);
@@ -469,6 +469,13 @@ void QmlProfilerTool::showTimeLineSearch()
Core::Find::openFindToolBar(Core::Find::FindForwardDirection);
}
void QmlProfilerTool::clearEvents()
{
d->m_profilerModelManager->clearEvents();
d->m_profilerConnections->clearEvents();
setRecordedFeatures(0);
}
void QmlProfilerTool::clearData()
{
d->m_profilerModelManager->clear();
@@ -859,7 +866,7 @@ void QmlProfilerTool::serverRecordingChanged()
d->m_recordingElapsedTime.start();
if (!d->m_profilerModelManager->aggregateTraces() ||
d->m_profilerModelManager->state() == QmlProfilerModelManager::Done)
clearData();
clearEvents();
d->m_profilerModelManager->startAcquiring();
} else {
d->m_recordingTimer.stop();

View File

@@ -74,6 +74,7 @@ public:
void gotoSourceLocation(const QString &fileUrl, int lineNumber, int columnNumber);
private:
void clearEvents();
void clearData();
void showErrorDialog(const QString &error);
void profilerDataModelStateChanged();

View File

@@ -213,9 +213,8 @@ QmlProfilerTraceClient::~QmlProfilerTraceClient()
delete d;
}
void QmlProfilerTraceClient::clearData()
void QmlProfilerTraceClient::clearEvents()
{
d->eventTypeIds.clear();
d->rangesInProgress.clear();
d->pendingDebugMessages.clear();
if (d->recordedFeatures != 0) {
@@ -225,6 +224,13 @@ void QmlProfilerTraceClient::clearData()
emit cleared();
}
void QmlProfilerTraceClient::clearData()
{
d->eventTypeIds.clear();
d->serverTypeIds.clear();
clearEvents();
}
void QmlProfilerTraceClient::sendRecordingStatus(int engineId)
{
d->sendRecordingStatus(engineId);

View File

@@ -55,6 +55,7 @@ public:
virtual void messageReceived(const QByteArray &) override;
virtual void stateChanged(State status) override;
void clearEvents();
void clearData();
void sendRecordingStatus(int engineId = -1);
void setRequestedFeatures(quint64 features);